Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Prolog中的家谱_Prolog_Family Tree - Fatal编程技术网

Prolog中的家谱

Prolog中的家谱,prolog,family-tree,Prolog,Family Tree,当我试着看谁是谁的兄弟,谁是谁的姐妹,它给了我儿子和女儿,我找不到错误 father(pedro-i,fernando-i). father(pedro-i,beatriz(1347)). father(pedro-i,joão(1349)). father(pedro-i,dinis(1354)). father(pedro-i,joão_grão_mestre_da_ordem_de_avis). mother(constança(1320),

当我试着看谁是谁的兄弟,谁是谁的姐妹,它给了我儿子和女儿,我找不到错误

    father(pedro-i,fernando-i).
    father(pedro-i,beatriz(1347)).
    father(pedro-i,joão(1349)).
    father(pedro-i,dinis(1354)).
    father(pedro-i,joão_grão_mestre_da_ordem_de_avis).
    mother(constança(1320),luis).
    mother(constança(1320),maria(1342)).
    mother(constança(1320),fernando-i).
    mother(inês_de_castro,beatriz(1347)).
还有其他意见吗?我很感激

    ancestor(X,Y) :- mother(X,Y).
    ancestor(X,Y) :- father(X,Y).

    if_then_else(X,Y,male) :- father(X,Y).
    if_then_else(X,Y,female) :- mother(X,Y).

    son(X,Y) :- father(X,Y).
    sister(X,Y) :- ancestor(Z,Y),X\==Y,if_then_else(X,Y,female).
    brother(X,Y) :- ancestor(Z,Y),X\==Y,if_then_else(X,Y,male).
    descendent (X,Y) :- filho(X,Y). 
    descendent (X,Y) :- filho(X,Z),descendent (Z,Y).
    grandfather(X,Y) :- ancestor(X,Z),ancestor(Z,Y).
    grandmother(X,Y) :- ancestor(X,Z),ancestor(Z,Y).
    grandchildren(X,Y) :- ancestor(Z,X),ancestor(Y,Z).

    uncle(X,Y) :- brother(X,Z),ancestor(Z,Y).
你的子句
兄弟(X,Y):-祖先(Z,Y),X\==Y,if_then_else(X,Y,male)。
要求Y有一个祖先,但X也需要有一个祖先——相同的祖先:

brother(X,Y) :- ancestor(Z,Y),ancestor(Z,X), X\==Y,if_then_else(X,Y,male).
您还需要在末尾消除X是Y之父的要求

brother(X,Y) :- ancestor(Z,Y),ancestor(Z,X), X\==Y,male(X).

男性
只需要依赖于个人(你不需要成为男性的父亲)。
男性(费尔南多-i)。
等等。

你输入什么查询?你得到了什么结果?你期望得到什么结果?例如,如果我输入这个查询:“兄弟(X,费尔南多-I)”,我得到:“X=pedro-I”,我想得到:“X=joão(1349)。X=迪尼斯(1354)。X=joãoãu grãu mestre_da_ordem_de_avis)“只有男性,如果我问修女,只有女性@Lourger
s/pedro-I/pedro_I/g
@false不明白你想说什么。不要直接在
pedro-I
的名字中使用
-
,而是使用
。如果你真的坚持这样做,就把整个名字加上引号,比如
'pedro-i'