我有这样的Prolog声明
verb('part_of-8').
noun('doctor_investigation_system-2').
noun('dis-4').
berelation('be-6').
verb('be-6').
noun('hospital_information_system-11').
noun('his-13').
rel('part_of-8', 'doctor_investigation_system-2').
rel('doctor_investigation_system-2', 'dis-4').
rel('part_of-8', 'be-6').
rel('part_of-8', 'hospital_information_system-11').
rel('hospital_information_system-11', 'his-13').
associatedWith(X,Y,Z) :-
verb(Y),
noun(X),
noun(Z),
X\=Y, Y\=Z, Z\=X,
rel(X,Y), rel(Y,Z),
not(beralation(X)), not(beralation(Z)), not(beralation(Y)).
Run Code Online (Sandbox Code Playgroud)
我的目标是得到associationWith(X,Y,Z),其中X,Y,Z不是"be"项(berelation),但我写的上述规则不起作用,怎么做才能使它工作
我相信你正在寻找\+"不可证明"的运营商
从而:
associatedWith(X,Y,Z) :-
verb(Y),
noun(X),
noun(Z),
X\=Y,
Y\=Z,
Z\=X,
rel(X,Y),
rel(Y,Z),
\+ beralation(X),
\+ beralation(Z),
\+ beralation(Y).
Run Code Online (Sandbox Code Playgroud)
还有另一种方式(没有\+,使用!"cut"运算符):
associatedWith(X,_,_) :-
berelation(X), !, fail.
associatedWith(_,Y,_) :-
berelation(Y), !, fail.
associatedWith(_,_,Z) :-
berelation(Z), !, fail.
associatedWith(X,Y,Z) :-
verb(Y),
noun(X),
noun(Z),
X\=Y,
Y\=Z,
Z\=X,
rel(X,Y),
rel(Y,Z).
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12943 次 |
| 最近记录: |