Reputation: 1
I am trying to find the rules based on the facts and write some sample queries. But I can't understand other query logic.
% parent(X,Y) means that person X is a parent (father or mother) of person Y
parent(alex,julia).
parent(alex,rosa).
parent(lina,julia).
parent(lina,rosa).
parent(romeo,peter).
parent(julia,peter).
parent(rosa,silvia).
parent(oscar,ida).
parent(eva,ida).
parent(eva,bruno).
parent(peter,bruno).
parent(peter,georg).
parent(peter,irma).
parent(ruth,georg).
parent(ruth,irma).
parent(silvia,otto).
parent(silvia,pascal).
parent(irma,olga).
parent(irma,jean).
parent(otto,olga).
parent(otto,jean).
parent(jean,tina).
parent(marie,tina).
% male(X) means that X is a male person
male(alex).
male(romeo).
male(oscar).
male(peter).
male(bruno).
male(georg).
male(otto).
male(pascal).
male(jean).
% husband(X,Y) means that person X is the husband of person Y
husband(alex,lina).
husband(romeo,julia).
husband(oscar,eva).
husband(peter,ruth).
husband(otto,irma).
husband(jean,marie).
% female
female(X) :- \+ male(X).
% father
father(X,Y) :- parent(X,Y),male(X).
% mother
mother(X,Y) :- parent(X,Y),female(X).
% son
son(X,Y) :- male(X),parent(Y,X).
% daughter
daughter(X,Y) :- female(X),parent(Y,X).
% sibling
% brother
% sister
% wife
% grandchild
% grandparent
% grandfather
% grandmother
% uncle
% halfbrother
% halfsister
% stepbrother
% stepsister
% ancestor
% descendant
% father-in-law
% mother-in-law
% familycomn
Upvotes: 0
Views: 1080
Reputation: 1
% sibling sibling(X,Y) :- father(P,X), father(P,Y), mother(Q,X), mother(Q,Y).
% brother brother(X,Y) :- sibling(X,Y), male(X).
% sister sister(X,Y) :- sibling(X, Y), female(X).
% wife wife(X,Y) :- husband(Y,X).
% grandchild grandchild(X,Y) :- grandparent(Y,X).
% grandparent grandparent(X,Y) :- parent(Z,Y), parent(X,Z).
% grandfather grandfather(X,Y) :- grandparent(X,Y), male(X).
% grandmother grandmother(X,Y) :- grandparent(X,Y), female(X).
% uncle uncle(X,Y) :- parent(Z,Y), brother(X,Z).
% halfbrother halfbrother(X,Y) :- halfsibling(X,Y), male(X).
% halfsister halfsister(X,Y) :- halfsibling(X,Y), female(X).
% stepbrother stepbrother(X,Y) :- stepsibling(X,Y) , male(X).
% stepsister stepsister(X,Y) :- stepsibling(X,Y) , female(X).
% ancestor ancestor(X, Y) :- parent(X,Y); parent(X,Z), ancestor(Z,Y).
% descendant descendant(X, Y) :- ancestor(Y,X).
Upvotes: 0
Reputation: 2578
% female female(X) :- + male(X).
X is a female if X is not a male (Prolog predates gender fluidity).
% father father(X,Y) :- parent(X,Y),male(X).
X is the father of Y if X is a parent of Y and X is male
% Sibling
sibling(X,Y) :- dif(X,Y),parent(Z,X),parent(Z,Y).
Y and X are siblings if they have a parent in common, but are not one and the same person (cfr. @lurker)
Upvotes: 1