Skip to content

Instantly share code, notes, and snippets.

@redraiment
Created April 9, 2020 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redraiment/c1908ebbc383bf850ed6b43ce2bb3394 to your computer and use it in GitHub Desktop.
Save redraiment/c1908ebbc383bf850ed6b43ce2bb3394 to your computer and use it in GitHub Desktop.
通过人物实体、性别事实、父母关系来推算女儿关系。
% 知识库
%% 性别的实体
female(ann).
female(eve).
%% 父母的实体
parent(ann, mary).
parent(tom, eve).
parent(tom, mary).
% 规则
%% 有相同孩子的两个人是配偶关系
spouse(This, That) :- parent(This, Child), parent(That, Child), \+ (This = That).
%% 女性的配偶通常是男性
male(Who) :- spouse(Who, Spouse), female(Spouse).
%% 女性小孩是女儿,配偶的女性小孩也是女儿
daughter(Parent, Child) :- spouse(Parent, Spouse), (parent(Spouse, Child); parent(Parent, Child)), female(Child).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment