我想制定一个利用继承的规则。例如,这里有一个在许多序言书中使用的著名示例,用于描述继承。
(来源:unak.is)
以下是这些关系的事实:
%Bird
%animal's childs
isa(bird, animal).
isa(fish, animal).
%bird's childs
isa(ostrich, bird).
isa(penguin, bird).
isa(canary, bird).
isa(robin, bird).
%penguin's childs
isa(opus, penguin).
%canary's childs
isa(tweety, canary).
%animal's property
hasprop(animal, covering, skin).
%bird's property
hasprop(bird, travel, fly).
hasprop(bird, covering, feathers).
%fish's property
hasprop(fish, travel, swim).
%ostrich's property
hasprop(ostrich, travel, walk).
%penguin's property
hasprop(penguin, travel, walk).
hasprop(penguin, color, brown).
%canary's property
hasprop(canary, color, yellow).
hasprop(canary, sound, sing).
%robin's property
hasprop(robin, color, red).
hasprop(robin, sound, sing).
%tweety's property
hasprop(tweety, color, white).
%rules
hasproperty(Object, Property, Value) :- hasprop(Object, Property, Value),!.
hasproperty(Object, Property, Value) :- isa(Object, Parent),
hasproperty(Parent, Property, Value).
在这个网络中,当我查询像 hasproperty(penguin, X, Y) 这样的语句时,我只能得到一个结果(我知道这是因为 cut 运算符。)。我想要的是这样的结果:
?- hasproperty(penguin, X, Y).
X = travel,
Y = walk.
X = color,
Y = brown.
X = covering,
Y = feathers.
在此结果中,较低级别的属性、旅行和覆盖覆盖了较高级别的属性。但我不知道处理这些覆盖。如果您对此有任何解决方案,请告诉我。