- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在发现 Owlready 库的所有可能性。
现在我正在尝试处理一些 SWRL 规则,到目前为止一切顺利,但我有一点被卡住了。
我已经在我的本体中定义了一些规则,现在我想查看所有结果(因此,一切都是从规则中推断出来的)。
例如,如果我有一个规则has_brother(David, ?b) ^ has_child(?b, ?s) -> has_uncle(?s, David)
大卫有两个兄弟,约翰和皮特,约翰的 child 是安娜,皮特的 child 是西蒙,我也想看到类似的东西:has_brother(David, John) ^ has_child(John, Anna) -> has_uncle(Anna, David)
has_brother(David, Pete) ^ has_child(Pete, Simon) -> has_uncle(Simon, David)
这有可能吗?
我想也许如果我运行推理器,我可以在它的输出中看到它,但我在任何地方都找不到它。
我感谢任何可能的帮助!
最佳答案
这是我的解决方案:
import owlready2 as owl
onto = owl.get_ontology("http://test.org/onto.owl")
with onto:
class Person(owl.Thing):
pass
class has_brother(owl.ObjectProperty, owl.SymmetricProperty, owl.IrreflexiveProperty):
domain = [Person]
range = [Person]
class has_child(Person >> Person):
pass
class has_uncle(Person >> Person):
pass
rule1 = owl.Imp()
rule1.set_as_rule(
"has_brother(?p, ?b), has_child(?p, ?c) -> has_uncle(?c, ?b)"
)
# This rule gives "irreflexive transitivity",
# i.e. transitivity, as long it does not lead to has_brother(?a, ?a)"
rule2 = owl.Imp()
rule2.set_as_rule(
"has_brother(?a, ?b), has_brother(?b, ?c), differentFrom(?a, ?c) -> has_brother(?a, ?c)"
)
david = Person("David")
john = Person("John")
pete = Person("Pete")
anna = Person("Anna")
simon = Person("Simon")
owl.AllDifferent([david, john, pete, anna, simon])
david.has_brother.extend([john, pete])
john.has_child.append(anna)
pete.has_child.append(simon)
print("Uncles of Anna:", anna.has_uncle) # -> []
print("Uncles of Simon:", simon.has_uncle) # -> []
owl.sync_reasoner(infer_property_values=True)
print("Uncles of Anna:", anna.has_uncle) # -> [onto.Pete, onto.David]
print("Uncles of Simon:", simon.has_uncle) # -> [onto.John, onto.David]
备注:
has_brother
是
has_brother(A, B)
⇒ has_brother(B, A)
has_brother(A, B) + has_brother(B, C) ⇒ has_brother(A, C)
A
可能与
C
是同一个人这与非自反性相冲突。因此,我为这种“弱传递性”使用了一个规则。
has_brother
像预期的那样工作,叔叔规则也一样。当然,reasoner 必须先运行。
关于python - OWL 2 中的 SWRL 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69224096/
我知道 owl:Class 是 rdfs:class 的子类,所有 OWL 类都是 owl:Class 的成员。我还知道 owl:Thing 位于类层次结构的顶部。那么 owl:Class 和 owl
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 5 年前。
我认为我对 OWL 公理仍然存在根本性的误解:(。 这是我创建的一个小型测试本体: @prefix xsd: . @prefix rdf: . @prefix rdfs:
我是耶拿的新手。我想创建一个新的 OntModel 并需要将一些其他本体导入到该模型中。如果我将其写入文件,我希望该文件可以显示如下内容: 现在,我不知道如何通过jena将其他本
我认为我对 OWL 公理仍然存在根本性的误解:(。 这是我创建的一个小型测试本体: @prefix xsd: . @prefix rdf: . @prefix rdfs:
我是耶拿的新手。我想创建一个新的 OntModel 并需要将一些其他本体导入到该模型中。如果我将其写入文件,我希望该文件可以显示如下内容: 现在,我不知道如何通过jena将其他本
导航和点周围的容器 .owl 控件不再存在,但我需要它们。有人知道如何恢复导航和点的环绕吗? 最佳答案 如果有人正在寻找...这是我的解决方案,用于取回 owl-nav 和 owl-dots 周围的包
对于我认为非常简单的场景,如果能提供一些帮助,我将不胜感激;但作为 OWL 和 GraphDB 的新手,我可能犯了一些基本错误。 我有一个非常简单的 Turtle 指定的 OWL 示例,如下所示: @
我使用 Protege 创建了一个本体。 类- Person Man Woman 属性(域/范围) Knows(Person / Person) hasRelationShip(Per
我正在使用 Protege v4.3 制作本体。 我有一个关于 OWL 本体和 DL 查询的问题。 例如,在 Pizza 本体中, http://owl.cs.manchester.ac.uk/co-
例如,此问题主要发生在用户使用速度较慢的互联网或移动设备时。但是,当轮播中的页面内容/图像没有被缓存时,有时也会在更高的速度上看到闪烁。 如果页面加载并呈现第一个元素,所有轮播“幻灯片”就像一个列表一
我需要在Protégé中实现一个OWL-ontology,它包含两个类:s1和s2,都是System的实例> 类。这两个类是通过连接类s1_s2 连接起来的,其中包含属性omega。该属性必须根据以下
我一直在四处寻找为什么 OWL Full 是不可判定的,但我还没有找到一个易于理解的例子来让我理解它。 我发现一些陈述解释了这是由于“Entailment Closure”,并且这也与 OWL Ful
我试图理解 OWL 2 的以下公理,但不知道它们是哪种公理。这里 R 是角色,C 是类 ∃R⊑C ∃R⊑∃R.C C ⊑ ¬∃R ∃R ⊑ ¬C 到目前为止,我认为 1 提供了有关 R 范围的信息,但
当 Owl Carousel 在隐藏元素中启动,然后通过触发器显示该元素时,轮播项目的宽度完全错误(直到窗口调整大小): Fiddle (点击红色链接,看到损坏的布局出现,然后调整窗口大小) 这个问题
在构建轮播时,我意识到猫头鹰添加了克隆的重复项。我的猫头鹰配置看起来像这样。我如何阻止这种情况发生。 owlDfe.owlCarousel({ loop: false,
我有两张幻灯片。我用的是 OWL 1,效果很好。我想要无限循环,所以搬到了 OWL 2。 下面的代码效果很好。幻灯片保持同步,但自动播放永远不会开始。我必须拖动幻灯片或显示导航并单击下一个/上一个。
我们根据分别与 B 或 C 的实例具有关系 a_to_b 和 a_to_c 的实例的交集 (AND),将类 A 定义为 owl:equivalentClass 并将类 A2 定义为 rdfs:subC
我正在使用 rdflib 创建一个图形。我想使用我拥有的“.owl”文件中的一些术语。我如何使用 rdflib 将这个 owl 文件作为 MyImportedTerminology 导入,并访问它的术
通常,当我们说“我所有的 child 都是女性”时,我们的意思是“并且至少有一个”。名门pizza tutorial (V1.3)在第 100 页解决了这个问题,说拥有普遍限制 (owl:allVal
我是一名优秀的程序员,十分优秀!