1

目前正在做一些 PROLOG 练习——对这一切都很陌生,所以请多多包涵。我有以下知识库:

/* The structure of a subject teaching team takes the form:
team(Subject, Leader, Non_management_staff, Deputy).
Non_management_staff is a (possibly empty) list of teacher
structures and excludes the teacher structures for Leader and
Deputy.
teacher structures take the form:
teacher(Surname, Initial,
profile(Years_teaching,Second_subject,Club_supervision)).
Assume that each teacher has his or her team's Subject as their
main subject. */

team(computer_science,teacher(may,j,profile(20,ict,model_railways)),
[teacher(clarke,j,profile(32,ict,car_maintenance))],
teacher(hamm,p,profile(11,ict,science_club))).

team(maths,teacher(vorderly,c,profile(25,computer_science,chess)),
[teacher(o_connell,d,profile(10,music,orchestra)),
teacher(brankin,p,profile(20,home_economics,cookery_club))],
teacher(lynas,d,profile(10,pe,football))).

team(english,teacher(brewster,f,profile(30,french,french_society)),
[ ],
teacher(flaxman,j,profile(35,drama,debating_society))).

team(art,teacher(lawless,m,profile(20,english,film_club)),
[teacher(walker,k,profile(25,english,debating_society)),
teacher(brankin,i,profile(20,home_economics,writing)),
teacher(boyson,r,profile(30,english,writing))],
teacher(carthy,m,profile(20,music,orchestra))).

subject(X):- team(X,_,_,_).
leader(X) :- team(_,X,_,_).
deputy(X) :- team(_,_,_,X).

non_management(X) :-
    team(_,_,Non_management,_),
    member(X,Non_management).

exists(X) :-
    subject(X);  
    leader(X);
    deputy(X);
    non_management(X).

我现在要写一条规则,(q) 老师 A 和老师 B 的首字母,其中老师 A 和老师 B 在不同的学科组,每个人都以家政学作为第二个学科,每个人都姓 Brankin。

我被困在如何比较知识库中的所有实体上。在此之前,我只从单个实体(在本例中为单个教师)提取值。例如:

question1(Initial,Surname) :-
    exists(teacher(Surname,Initial,profile(_,english,_))).

非常感谢任何帮助。

4

1 回答 1

0

您不需要显式比较知识库中的所有实体 - 这在 Prolog 回答查询的方式中是隐含的,无论它们是简单的还是复杂的。对于前几个标准,你可以说

team(W,X,Y,Z), team(J,K,L,I), W \= J.

这将通过回溯为您提供不同团队的所有可能组合。您可以使用类似的东西扩展查询

member(A,Y), member(B,L), A=teacher(...), B=teacher(...)

处理其他标准。

于 2012-05-18T07:57:38.687 回答