Prolog 序言列表显示结果

Prolog 序言列表显示结果,prolog,Prolog,大家好,我是prolog的新手,我正在尝试完成我的第一个项目。我有一个带有3个参数的家谱(family/3)(person(dad),person(mom),。列出所有的孩子).目前我的知识库中有3个家庭。我正在努力完成的是显示有3个以上孩子的母亲的姓名。任何帮助都会很好。 这是到目前为止的代码 family(person(tom,right,date(17,May,1950),works(mathematician)),person(ann,right,date(29,May,1951),un

大家好,我是prolog的新手,我正在尝试完成我的第一个项目。我有一个带有3个参数的家谱(family/3)(person(dad),person(mom),。列出所有的孩子).目前我的知识库中有3个家庭。我正在努力完成的是显示有3个以上孩子的母亲的姓名。任何帮助都会很好。 这是到目前为止的代码

family(person(tom,right,date(17,May,1950),works(mathematician)),person(ann,right,date(29,May,1951),unemployed),
[person(pat,right,date(5,May,1983),unemployed),person(max,right,date(15,May,1973),unemployed),[]]).

family(person(nick,wellbard,date(15,September,1954),works(electrician)),person(cathrine,wellbard,date(11,March,1957),unemployed),
[person(john,wellbard,date(15,May,1985),works(musician)),person(mike,wellbard,date(25,May,1989),unemployed),
person(chloe,wellbard,date(13,October,1991),unemployed),[]]).

family(person(john,brock,date(17,January,1951),works(programmer)),person(mary,brock,date(19,March,1952),works(teacher)),
[person(tony,brock,date(20,May,1975),unemployed),person(sasha,brock,date(1,April,1979),unemployed),
person(josh,brock,date(29,April,1982),unemployed),[]]).
我在想类似于
家庭(,X,):-[X,Y,Z |]
这样我就可以显示至少有3个孩子的母亲的名字。
请原谅我犯的任何错误,我是ProLog的新手,任何帮助或指导都会很好,谢谢:)

你已经走上正轨,或多或少。。。 试一试

编辑如果您无法更改子列表,删除最后无用的[],则规则应实际读取

mother_with_at_least_3_sons(M) :-
   family(_,M,[_,_,_,_|_]).

这是我对你问题的回答

%如果你找到一个有爸爸、妈妈、孩子的家庭,我们会对序言“说”

%其中Kids是一个包含3个以上元素的列表(通过长度获得)

%然后告诉我妈妈的姓名

more_than_three_children(MotherName,MotherSurname) :- family(Dad,Mom,Kids),
                                                      length(Kids,NumberOfKids),
                                                      NumberOfKids > 3,
                                                      Mom=person(MotherName,MotherSurname,_,_).
%为了找到所有母亲,我们可以使用findall谓词

%第一个参数是OBJECT,我们使用目标创建对象的实例

%第二个参数是目标。如果prolog“找到”满足该目标的某种结构

%它将把它放在列表中(这是第三个参数)

mother_list(List) :- findall((MotherName,MotherSurname),more_than_three_children(MotherName,MotherSurname),List).

为什么您所有的孩子列表都以[]结尾?这也匹配只有两个儿子的家庭(儿子列表末尾有一个空列表)。
mother_list(List) :- findall((MotherName,MotherSurname),more_than_three_children(MotherName,MotherSurname),List).