用非运算符编写序言语句 [英] writing prolog statement with not operator

查看:29
本文介绍了用非运算符编写序言语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的 Prolog 语句

I have Prolog statements like this

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)).

我的目标是得到 associationWith(X,Y,Z) 其中 X, Y, Z 不是be"术语(berelation),但是我写的上述规则不起作用,该怎么做它工作

my aim is to get associationWith(X,Y,Z) where X, Y, Z is not a "be" term(berelation), but the above rule that I have written is not working, what to do to make it work

推荐答案

我相信您正在寻找 \+不可证明"运算符

I believe you're looking for \+ "is not provable" operator

因此:

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).

还有一种方法(不用\+,用!剪切"操作符):

There is another way (without \+, with ! "cut" operator):

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).

这篇关于用非运算符编写序言语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆