【发布时间】:2020-04-30 20:28:49
【问题描述】:
美好的一天!我想问一下如何能够将列表元素用作谓词中的变量。
这是我目前能够制作的代码:
case(boeing, [f4, f6, f12, f14, f21, f1, f10]).
go(Case) :-
case(Case, [H|T]),
getf124(Case, H).
getf124(Case,factorsSoFar) :-
member(f3, factorsSoFar),
write(['the defendent is the owner of secret']),
nl, getf123(Case, [f124|factorsSoFar]).
getf124(Case,factorsSoFar):-
write(['Accepted that the defendent is not the owner of secret']),
nl, getf123(Case,factorsSoFar).
当我删除 getf124(Case, H) 时,我可以执行查询
?- go(boeing).
true
但这仅意味着我只是检查我的查询是否包含规则库中指定的单词。 (在这种情况下是波音)
我的目标是在谓词中使用列表的头部 [H|T]
getf124(Case, factorsSoFar)
所以如果检测到 f4,那么它应该输出
Accepted that the defendent is not the owner of secret
对列表中的每个元素以此类推。 (尾巴)
** 编辑:添加了整个代码以供参考**
case(boeing, [f4, f6, f12, f14, f21, f1, f10]).
go(Case) :-
case(Case, [H|T]),
getf124(Case, H).
% determine acceptibilty of
% F124, Defendent Ownership Rights
getf124(Case,F) :-
member(f3, F),
write(['the defendent is the owner of secret']), nl,
getf123(Case, [f124|F]).
getf124(Case,factorsSoFar):-
write(['Accepted that the defendent is not the owner of secret']),
nl, getf123(Case,factorsSoFar).
% determine acceptibilty of
% F123, Maintaining Secrecy via Outsiders
getf123(Case,factorsSoFar) :-
member(f12, factorsSoFar),
member(f10,factorsSoFar),!,
write(['Efforts made vis a vis Outsiders']),
nl, getf122(Case, [f123|factorsSoFar]).
getf123(Case,factorsSoFar):-
write(['Accepted that Efforts not made vis a vis Outsiders']),
nl, getf122(Case,factorsSoFar).
% determine acceptibilty of
% F122, Maintaining Secrecy via Defendent
getf122(Case,factorsSoFar) :-
member(f4, factorsSoFar),
member(f1,factorsSoFar),!,
write(['Efforts made a vis a vis Defendent']),
nl, getf121(Case, [f122|factorsSoFar]).
getf122(Case,factorsSoFar):-
write(['Accepted that Efforts not made vis a vis Defendent']),
nl, getf121(Case,factorsSoFar).
% determine acceptibilty of
% F121, Confidentiality Agreement
getf121(Case,factorsSoFar):-
member(f23,factorsSoFar),
member(f4,factorsSoFar),!,
write(['There was no Confidentiality Agreement']),
nl, getf115(Case,factorsSoFar).
getf121(Case,factorsSoFar):-
write(['Accepted that there was a Confidentiality Agreement']),
nl, getf115(Case,[f121|factorsSoFar]).
% determine acceptibilty of
% F115, Notice of Confidentiality
getf115(Case,factorsSoFar):-
member(f23,factorsSoFar),
write(['defendent was not on notice of Confidentiality']),
nl, getf114(Case,factorsSoFar).
getf115(Case,factorsSoFar):-
member(f21,factorsSoFar),
write(['defendent was on notice of Confidentiality']),
nl, getf114(Case,[f115|factorsSoFar]).
getf115(Case,factorsSoFar):-
member(f14,factorsSoFar),
write(['defendent was on notice of Confidentiality']),
nl, getf114(Case,[f115|factorsSoFar]).
getf115(Case,factorsSoFar):-
member(f5,factorsSoFar),
write(['defendent was not on notice of Confidentiality']),
nl, getf114(Case,factorsSoFar).
getf115(Case,factorsSoFar):-
member(f4,factorsSoFar),
write(['defendent was on notice of Confidentiality']),
nl, getf114(Case,[f115|factorsSoFar]).
getf115(Case,factorsSoFar):-
member(f13,factorsSoFar),
write(['defendent was on notice of Confidentiality']),
nl, getf114(Case,[f115|factorsSoFar]).
getf115(Case,factorsSoFar):-
write(['Accepted that defendent was not on notice of Confidentiality']),
nl, getf114(Case,factorsSoFar).
% determine acceptibilty of
% F114, Confidentiality relationship
getf114(Case,factorsSoFar):-
member(f115,factorsSoFar);
member(f121, factorsSoFar),
write(['There was a Confidential Relationship']),
nl, getf112(Case, [f114|factorsSoFar]).
getf114(Case,factorsSoFar):-
write(['Accepted that there was no Confidentiality Relationship']),
nl, getf112(Case,factorsSoFar).
% determine acceptability of
% F112, Information used
getf112(Case,factorsSoFar):-
member(f18,factorsSoFar),
write(['The information was used']),
nl, getf111(Case,[f112|factorsSoFar]).
getf112(Case,factorsSoFar):-
member(f8,factorsSoFar),
write(['the information was used']),
nl, getf111(Case,[f112|factorsSoFar]).
getf112(Case,factorsSoFar):-
member(f7,factorsSoFar),
write(['the information was used']),
nl, getf111(Case,[f112|factorsSoFar]).
getf112(Case,factorsSoFar):-
member(f17,factorsSoFar),
write(['the information was not used']),
nl, getf111(Case,factorsSoFar).
getf112(Case,factorsSoFar):-
write(['accepted that the information was used']),
nl, getf111(Case,[f112|factorsSoFar]).
% determine acceptibilty of
% F111, Questionable means
getf111(Case,factorsSoFar):-
member(f25,factorsSoFar);
write(['Questionable means not were used']),
nl, getf108(Case,factorsSoFar).
getf111(Case,factorsSoFar):-
member(f17,factorsSoFar);
write(['Questionable means not were used']),
nl, getf108(Case,factorsSoFar).
getf111(Case,factorsSoFar):-
member(f22,factorsSoFar);
write(['Questionable means were used']),
nl, getf108(Case,[f111|factorsSoFar]).
getf111(Case,factorsSoFar):-
member(f26,factorsSoFar);
write(['Questionable means were used']),
nl, getf108(Case,[f111|factorsSoFar]).
getf111(Case,factorsSoFar):-
member(f14,factorsSoFar);
write(['Questionable means were used']),
nl, getf108(Case,[f111|factorsSoFar]).
getf111(Case,factorsSoFar):-
member(f2,factorsSoFar);
write(['Questionable means were used']),
nl, getf108(Case,[f111|factorsSoFar]).
getf111(Case,factorsSoFar):-
member(f1,factorsSoFar);
write(['Questionable means not were used']),
nl, getf108(Case,factorsSoFar).
getf111(Case,factorsSoFar):-
write(['Accepted that questionable means not were used']),
nl, getf108(Case,factorsSoFar).
% determine acceptibilty of
% F108, Information available elsewhere
getf108(Case,factorsSoFar):-
member(f16,factorsSoFar);
member(f24,factorsSoFar),
write(['the Information was available elsewhere']),
nl, getf106(Case, [f108|factorsSoFar]).
getf108(Case,factorsSoFar):-
write(['Accepted that the Information was not available elsewhere']),
nl, getf106(Case,factorsSoFar).
% determine acceptibilty of
% F106, Information Known
getf106(Case,factorsSoFar):-
member(f20,factorsSoFar),
write(['The information is known']),
nl, getf105(Case, [f106|factorsSoFar]).
getf106(Case,factorsSoFar):-
member(f27,factorsSoFar),
member(f15,factorsSoFar), !,
write(['The information is known']),
nl, getf105(Case, [f106|factorsSoFar]).
getf106(Case,factorsSoFar):-
member(f27,factorsSoFar),
member(f123,factorsSoFar),!,
write(['The information is known']),
nl, getf105(Case, [f106|factorsSoFar]).
getf106(Case,factorsSoFar):-
write(['Accepted that the information is not known']),
nl, getf105(Case, [f106|factorsSoFar]).
% determine acceptibilty of
% F105, Information Known Or available
getf105(Case,factorsSoFar):-
member(f106, factorsSoFar);
member(f108, factorsSoFar),
write(['The information was known or available']),
nl, getf104(Case, [f105|factorsSoFar]).
getf105(Case,factorsSoFar):-
write(['Accepted that the information was neither known or available']),
nl, getf104(Case, factorsSoFar).
% determine acceptibilty of
% F104, Information Valuable
getf104(Case,factorsSoFar):-
member(f8,factorsSoFar),
write(['the information was Valuable']),
nl, getf120(Case, [f104|factorsSoFar]).
getf104(Case,factorsSoFar):-
member(f15,factorsSoFar),
write(['the information was Valuable']),
nl, getf120(Case, [f104|factorsSoFar]).
getf104(Case,factorsSoFar):-
member(f105,factorsSoFar),
write(['the information was not Valuable']),
nl, getf120(Case,factorsSoFar).
getf104(Case,factorsSoFar):-
write(['Accepted that the information was Valuable']),
nl, getf120(Case, [f104|factorsSoFar]).
% determine acceptibilty of
% F120, Information legitimately obtained
getf120(Case,factorsSoFar):-
member(f111,factorsSoFar),
member(f105,factorsSoFar),!,
write(['the information was not legitimately obtained']),
nl, getf110(Case,factorsSoFar).
getf120(Case,factorsSoFar):-
write(['Accepted that the information was legitimately obtained']),
nl, getf110(Case,[f120|factorsSoFar]).
% determine acceptibilty of
% F110, Improper Means
getf110(Case,factorsSoFar):-
member(f120, factorsSoFar),
member(f111,factorsSoFar),!,
write(['Improper means were not used']),
nl, getf102(Case,factorsSoFar).
getf110(Case,factorsSoFar):-
write(['Accepted that Improper means were used']),
nl, getf102(Case, [f110|factorsSoFar]).
% determine acceptibilty of
% F102, Efforts to maintain secrecy
getf102(Case,factorsSoFar):-
member(f19,factorsSoFar),
write(['Efforts were not taken to maintain secrecy']),
nl, getf203(Case,factorsSoFar).
getf102(Case,factorsSoFar):-
member(f23,factorsSoFar),
write(['Efforts were not taken to maintain secrecy']),
nl, getf203(Case,factorsSoFar).
getf102(Case,factorsSoFar):-
member(f27,factorsSoFar),
member(f123,factorsSoFar),!,
write(['Efforts were not taken to maintain secrecy']),
nl, getf203(Case,factorsSoFar).
getf102(Case,factorsSoFar):-
member(f6,factorsSoFar),
write(['Efforts were taken to maintain secrecy']),
nl, getf203(Case, [f102|factorsSoFar]).
getf102(Case,factorsSoFar):-
member(f122,factorsSoFar),
write(['Efforts were taken to maintain secrecy']),
nl, getf203(Case, [f102|factorsSoFar]).
getf102(Case,factorsSoFar):-
member(f123,factorsSoFar),
write(['Efforts were taken to maintain secrecy']),
nl, getf203(Case, [f102|factorsSoFar]).
getf102(Case,factorsSoFar):-
write(['Accepted that efforts were not taken to maintain secrecy']),
nl, getf203(Case,factorsSoFar).
% determine acceptibilty of
% F203, Information Trade secret
getf203(Case,factorsSoFar):-
member(f102,factorsSoFar),
member(f104,factorsSoFar),
write(['Information was a trade secret']),
nl, getf201(Case,[f203|factorsSoFar]).
getf203(Case,factorsSoFar):-
write(['Accepted that Information was not a trade secret']),
nl, getf201(Case,factorsSoFar).
% determine acceptibilty of
% F201, Information misappropriation
getf201(Case,factorsSoFar):-
member(f114,factorsSoFar),
member(f112,factorsSoFar),
write(['Information was misappropriated']),
nl, getf200(Case,[f201|factorsSoFar]).
getf201(Case,factorsSoFar):-
member(f110,factorsSoFar),
write(['Information was misappropriated']),
nl, getf200(Case,[f201|factorsSoFar]).
getf201(Case,factorsSoFar):-
write(['Accepted that Information was not misappropriated']),
nl, getf200(Case,factorsSoFar).
% determine acceptibilty of
% F200, Trade secret misappropriation
getf200(Case,factorsSoFar):-
member([f203,factorsSoFar]),
member(f201,factorsSoFar),
member(f124,factorsSoFar),!,
write(['the trade secret was misappropriated']),
nl, write(['find for plaintiff']).
getf200(Case,factorsSoFar):-
write(['the trade secret was not misappropriated']),
nl, write(['find for defendent']).
编辑#2:天哪,我应用了上述编辑(idk 为什么我没有使用适当的变量,变量应该以大写字母开头,真是太糟糕了facepalm)
?- go(spaceAero).
[Accepted that the defendent is not the owner of secret]
[Accepted that Efforts not made vis a vis Outsiders]
[Accepted that Efforts not made vis a vis Defendent]
[Accepted that there was a Confidentiality Agreement]
[Accepted that defendent was not on notice of Confidentiality]
[There was a Confidential Relationship]
[The information was used]
[Questionable means not were used]
[Accepted that the Information was not available elsewhere]
[Accepted that the information is not known]
true ;
[Accepted that the information was neither known or available]
[the information was Valuable]
[Accepted that the information was legitimately obtained]
[Accepted that Improper means were used]
[Efforts were not taken to maintain secrecy]
[Accepted that Information was not a trade secret]
[Information was misappropriated]
完美!一切都输出,除了我在最后一行遇到错误。寻找应该输出的原告。虽然在查看调试时,似乎所有列表元素都被正确收集了
boeing[f200, f201, f203, f102,f110,f104,f111,
f112,f114,f115,f121,f122,f123,
f4,f6,f12,f14,f21,f1,f10]
【问题讨论】:
标签: prolog