从文本 Prolog 创建规则
Create rules from text Prolog
我有这样一句话:
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.
我如何为最后两个句子创建 Prolog 规则?
这是我现在拥有的:
footballer(john).
actor(Mary).
color(blond) # not sure if its ok
footballer(john).
footballer(joe).
actor(mary).
actor(kevinbacon).
singer(elvis).
cosmonaut(yuri).
friend(john, X) :- footballer(X).
friend(john, X) :- actor(X).
看到询问 ?- friend(john, F).
找到 joe、mary 和 kevinbacon,但没有找到 elvis 或 yuri。
您可以对 friend(mary, X)
和 blonde_hair(marilyn)
执行类似的操作。
您可能需要弄清楚如何说 John 不是他自己的朋友,或许可以使用 dif/2。
这个方法很简单,你可以问“谁是足球运动员?”但是你不能轻易地问“约翰是做什么的?”。为此,您可能会考虑:
person_job(john, footballer).
person_job(ronaldo, footballer).
person_job(mary, actress).
person_job(elvis, singer).
person_haircolour(elvis, black).
person_haircolour(sia, blonde).
在这些关系的基础上(将一个人与他们的工作联系起来,将一个人与他们的头发颜色联系起来)会让你问“谁是足球运动员?”以及“约翰做什么?”或“谁有金发?”。
(约翰的朋友都是足球运动员,但是成千上万的足球运动员都是约翰的朋友吗?)
(是骗子提示吗,Mary是女演员,John是演员的朋友?)
我有这样一句话:
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.
我如何为最后两个句子创建 Prolog 规则? 这是我现在拥有的:
footballer(john).
actor(Mary).
color(blond) # not sure if its ok
footballer(john).
footballer(joe).
actor(mary).
actor(kevinbacon).
singer(elvis).
cosmonaut(yuri).
friend(john, X) :- footballer(X).
friend(john, X) :- actor(X).
看到询问 ?- friend(john, F).
找到 joe、mary 和 kevinbacon,但没有找到 elvis 或 yuri。
您可以对 friend(mary, X)
和 blonde_hair(marilyn)
执行类似的操作。
您可能需要弄清楚如何说 John 不是他自己的朋友,或许可以使用 dif/2。
这个方法很简单,你可以问“谁是足球运动员?”但是你不能轻易地问“约翰是做什么的?”。为此,您可能会考虑:
person_job(john, footballer).
person_job(ronaldo, footballer).
person_job(mary, actress).
person_job(elvis, singer).
person_haircolour(elvis, black).
person_haircolour(sia, blonde).
在这些关系的基础上(将一个人与他们的工作联系起来,将一个人与他们的头发颜色联系起来)会让你问“谁是足球运动员?”以及“约翰做什么?”或“谁有金发?”。
(约翰的朋友都是足球运动员,但是成千上万的足球运动员都是约翰的朋友吗?)
(是骗子提示吗,Mary是女演员,John是演员的朋友?)