2010-10-03 5 views
4

J'ai des déclarations Prolog comme celui-ciécrit la déclaration de Prolog avec pas opérateur

verb('part_of-8'). 
noun('doctor_investigation_system-2'). 
noun('dis-4'). 
berelation('be-6'). 
verb('be-6'). 
noun('hospital_information_system-11'). 
noun('his-13'). 
rel('part_of-8', 'doctor_investigation_system-2'). 
rel('doctor_investigation_system-2', 'dis-4'). 
rel('part_of-8', 'be-6'). 
rel('part_of-8', 'hospital_information_system-11'). 
rel('hospital_information_system-11', 'his-13'). 

associatedWith(X,Y,Z) :- 
    verb(Y), 
    noun(X), 
    noun(Z), 
    X\=Y, Y\=Z, Z\=X, 
    rel(X,Y), rel(Y,Z), 
    not(beralation(X)), not(beralation(Z)), not(beralation(Y)). 

mon but est d'obtenir associationWith (X, Y, Z) où X, Y, Z n'est pas un terme "être" (berelation), mais la règle ci-dessus que je l'ai écrit ne fonctionne pas, ce qu'il faut faire pour le faire fonctionner

Répondre

9

Je crois que vous cherchez \+ "is not provable" operator

Ainsi:

associatedWith(X,Y,Z) :- 
    verb(Y), 
    noun(X), 
    noun(Z), 
    X\=Y, 
    Y\=Z, 
    Z\=X, 
    rel(X,Y), 
    rel(Y,Z), 
    \+ beralation(X), 
    \+ beralation(Z), 
    \+ beralation(Y). 

Il y a une autre façon (sans \+, avec ! opérateur "cut"):

associatedWith(X,_,_) :- 
    berelation(X), !, fail. 
associatedWith(_,Y,_) :- 
    berelation(Y), !, fail. 
associatedWith(_,_,Z) :- 
    berelation(Z), !, fail. 
associatedWith(X,Y,Z) :- 
    verb(Y), 
    noun(X), 
    noun(Z), 
    X\=Y, 
    Y\=Z, 
    Z\=X, 
    rel(X,Y), 
    rel(Y,Z). 
Questions connexes