Prolog 继承困惑

对于这个Prolog脚本有点困惑..

  /*框架表示 */   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])).   /* 继承 - 使用递归*/   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如何知道执行哪个规则?感谢任何帮助!


回答:

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

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

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注