2012-05-17 142 views
1

目前正在進行一些PROLOG練習 - 對此很新,所有這些都與我相關。我有以下的知識基礎: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)老師和教師B的縮寫,其中教師A和教師B是不同學科小組,每個小組有家政作爲他們的第二個 科目,並且每個都有姓布蘭金。

我被困在如何比較知識庫中的所有實體。在此之前,我只提取單個實體的值(在這個例子中是單個教師)。例如:

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

任何幫助非常感謝。

回答

0

您不需要明確比較知識庫中的所有實體 - 這是Prolog回答查詢的方式隱含的,無論它們是簡單的還是複雜的。對於前幾條標準,你可以說

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

這將通過回溯得到所有不同團隊的所有可能的組合。您可以使用類似

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

來處理其他條件。