1
votes

I'm new in Prolog SWI can you help me to solve this. Suppose have a database with predicates likes (person1, person2) and hobbies (person1, hobby). Now, how can I design a rule such that the system answers that two people have the same kind of liking or not depending on their hobbies.

likes (john, jake).  
true 
1
Write the rule in normal language first, without regard to Prolog. What would it be? What does it mean to have the "same kind of liking depending on their hobbies"? Do you mean a rule that determines if two people simply have the same hobby? Or are you looking for a rule that defines two people who both like each other and have the same hobby? Is your "like" fact one directional? (if a likes b, is it also implicitly true that b likes a?)lurker
its mean that two people simply have the same hobby that's it.Aihtsham Ali
So write a rule, A likes B iff A has a hobby H and B has a hobby H.Eugene Sh.
i tried something like this checkhobby(A,B) :- likes(A,H), likes(B,H), dif(A,B).Aihtsham Ali
You said that you want to check if two people have the same hobby. But your example for checkhobby doesn't even use the hobbies data. It's a little confusing what you're really after here. This is sounding like you just need to go read the beginning chapters of a beginning Prolog book, or try a Prolog tutorial.lurker

1 Answers

1
votes

finally, I did it

hobby(harry,music).
hobby(harry,running).
hobby(jocker,swimming).
hobby(jocker,movies).
hobby(jocker,art).
hobby(curl,running).
hobby(curl,art).
hobby(curl,movies).

same_hobby(P1,P2) :-
        dif(P1,P2),
        hobby(P1,H),
        hobby(P2,H).