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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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