【问题标题】:Prolog inheritance confusionProlog继承混淆
【发布时间】:2014-02-04 21:42:24
【问题描述】:

只是对这个序言脚本有点困惑..

  /*frame representation */

   frame(name(bird), isa(animal), hasproperty([fly, feathers, sing])).
   frame(name(canary),isa(bird), hasproperty([yellow, nervous, easily_frightened])).
   frame(name(tweety), isa(canary), hasproperty([baby, my_pet])).
   frame(name(barn_owl), isa(bird), hasproperty([nocturnal,large_eyes])).
   frame(name(barny), isa(barn_owl), hasproperty([sick,forward_facing])).

   /* inheritance -using recursion*/

   inherit(Concept, Prop):- frame(name(Concept), _, hasproperty(Prop)).

   inherit(Concept, Prop):-
       frame(name(Concept), isa(Parent), _),
       write(Parent), nl,
       frame(name(Parent), _, hasproperty(PP)),
       write(PP), nl, 
       inherit(Parent, NewProp).

我了解它检查概念是否具有特定属性的第一条规则,但是我不太了解第二条规则.. 我知道如果它继承的框架具有特定属性,它应该可以解决但我不确定它是如何检查的,特别是当属性名称从 PP 到 NewProp 不同时。如果有两个同名的规则,prolog 如何知道在这个脚本中执行哪个规则?为任何帮助干杯!

【问题讨论】:

  • 在回答您的第二个问题时,Prolog 按给定顺序查询规则。将同一谓词的附加子句视为“或”。
  • 对!知道了!谢谢!
  • 代码实际上应该做什么?您发现了一个差异,即单例 NewProp 变量。 Prop 变量也是单例的。所以逻辑可能有问题。

标签: inheritance recursion prolog artificial-intelligence frame


【解决方案1】:

我认为你想要做的是,在inherit 的第二个子句中,找到你的概念的父级,然后立即调用继承。现在,你又完成了一半的工作。

inherit(Concept, Prop):- frame(name(Concept), _, hasproperty(Prop)).

inherit(Concept, Prop):-
   frame(name(Concept), isa(Parent), _),
   write(Parent), nl,
   inherit(Parent, Prop).

【讨论】:

  • 啊!这看起来好多了!谢谢你:)
猜你喜欢
  • 1970-01-01
  • 2011-12-30
  • 1970-01-01
  • 2011-04-25
  • 2019-12-08
  • 2016-05-13
  • 1970-01-01
  • 2015-09-18
  • 2015-05-13
相关资源
最近更新 更多