Create rules from text Prolog
I have this written sentence:
John is a footballer. Mary is an actress. All of Mary's friends are footballers and are blond (their hair). All of John's friends are footballers or actors.
How could i create Prolog rules for last two sentences? This is what i have for now:
footballer(john).
actor(Mary).
color(blond) # not sure if its ok
Solution 1:
footballer(john).
footballer(joe).
actor(mary).
actor(kevinbacon).
singer(elvis).
cosmonaut(yuri).
friend(john, X) :- footballer(X).
friend(john, X) :- actor(X).
See that asking ?- friend(john, F).
finds joe, mary and kevinbacon, and does not find elvis or yuri.
You can do a similar thing for friend(mary, X)
and blonde_hair(marilyn)
.
You may need to work out how to say that John is not friends with himself, perhaps using dif/2.
This approach is quite simple and you can ask "who is a footballer?" but you cannot easily ask "what does John do?". For that you might consider:
person_job(john, footballer).
person_job(ronaldo, footballer).
person_job(mary, actress).
person_job(elvis, singer).
person_haircolour(elvis, black).
person_haircolour(sia, blonde).
and building on those relations (relating a person to their job, a person to their hair colour) will let you ask "who is a footballer?" as well as "what does John do?" or "who has blonde hair?".
(All John's friends are footballers, but are all thousands and thousands of footballers friends with John?)
(Is it a trick prompt, Mary is an actress, John is friends with actors?)