簡體   English   中英

從句子 prolog 創建規則

[英]create rules from sentence prolog

我有下一句話:

約翰是一名足球運動員。 瑪麗是一名演員。 瑪麗的所有朋友都是足球運動員,而且都是金發(他們的頭發)。 約翰的所有朋友都是足球運動員或演員。

如果我做了前兩句話,我怎么能進入 prolog最后兩句話。

footballer(john).
actor(Mary).

嘗試類似:

person( john , red      , footballer ).
person( mary , brunette , actor      ).

friend( john, mary ).

等等

然后就像這樣簡單:

all_johns_friends_are_footballers :-
  ( friend(john, A ) ; friend( A , john ) ), % Find each friend of john
  \+ person( A , _ , footballer ) ,          % Are they not a footballer?
  !,                                         % if so, eliminate the choice point
  fail.                                      %   and fail hard.
all_johns_friends_are_footballers .          % otherwise, succeed. John either has no friend or they are all footballers.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM