我有这些家庭的事实:基于知识的系统
male(jerry).
male(stuart).
male(warren).
male(peter).
female(kather).
female(maryalice).
female(ann).
brother(jerry,stuart).
brother(jerry,kather).
brother(peter, warren).
sister(ann, maryalice).
sister(kather,jerry).
parent_of(warren,jerry).
parent_of(maryalice,jerry).
而且使用基本谓词male
,female
和parent_of
我想定义father
,mother
,son
,daughter
,sibling
,spouse
和parent_of
。
这是我做了什么:
father(P,C) :- male(P), parent_of(P,C).
mother(P,C) :- female(P), parent_of(P,C).
son(C,P) :- male(C), parent_of(P,C).
daughter(C,P) :- female(C), parent_of(P,C).
sibling(C,OC) :- parent_of(P,C), parent_of(P,OC).
spouse(H,W) :- parent_of(H,C), parent_of(W,C).
parent_of(P,C) :-
((sister(C,OC) ; sister(OC,C))
; (brother(C,OC) ; brother(OC,C))).
通过查询parent_of(P,C)
它应该返回warren
是jerry,stuart and kather
父母和maryalice
是jerry, stuart and kather
是父母。但这是我得到的:
?- parent_of(X,Y).
X = warren,
Y = jerry ;
X = maryalice,
Y = jerry ;
Y = ann ;
Y = kather ;
Y = maryalice ;
Y = jerry ;
Y = jerry ;
Y = jerry ;
Y = peter ;
Y = stuart ;
Y = kather ;
Y = warren.
它没有任何意义!任何帮助深表感谢!
亲切的问候, 理查德
谢谢你回复@danielp和@CapelliC。 (S,X): - 女性(S),parent_of(C,S),parent_of(C,X),S \ = X.'和'brother(S,X): - 男性(S),父母(C,S),父母(C,X),S 1 = X.“,并删除了”parent_of“规则。我试图用兄弟姐妹的事实来查询'parent_of(X,Y)',但没有它们,但它仍然只返回我定义的事实(warren和jerry,maryalice和jerry)。 –
除了您定义的那些之外,您还会得到什么额外结果? – danielp
由于'杰里'有兄弟姐妹'stuart'和'kather'我除了看到'warren'是'stuart'和'kather'的父母。另外'maryalice'是'stuart'和'kather'的父亲。 –