首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重置sync_reasoner推论

重置sync_reasoner推论
EN

Stack Overflow用户
提问于 2018-09-23 02:54:11
回答 1查看 402关注 0票数 0

我在本地本体上使用owlready2 python模块。

我已经连接了一个API端点,以提交关于此本体的查询。

我需要提交一些关于原始本体的查询,以及一些关于更新的本体(带有推论)的查询。

当我使用sync_reasoner()函数时,本体将使用HermiT进行的推理(即默认推理器)进行更新。

我的问题是,推理器做出的推论在对附加函数的不同调用中持续存在。

是否存在强制重置推断属性的解决方法?

代码语言:javascript
复制
def function():
    onto = get_ontology("file:///path/file.owl").load()
    namespace = onto.get_namespace("http://namespace")
    do_operations_with_original_ontology()
    with namespace:
       sync_reasoner()
       do_operations_with_UPDATED_ontology()
       return None

感谢你考虑我的问题,

阿盖里斯

EN

回答 1

Stack Overflow用户

发布于 2018-10-01 21:16:52

虽然我没有广泛地使用owlready2的推理功能,但我相信这与使用owlready2进行任何本体更新是一样的。

基本上,在owlready2中,要分离不同的本体或同一本体的不同版本(可能使用不同的命名空间),您需要将它们放在不同的“世界”中。语法描述为here

下面是一些基于文档示例的代码,让您对语法有一个大致的了解

代码语言:javascript
复制
from owlready2 import *

world = World()
onto = world.get_ontology("http://test.org/onto.owl")

with onto:
    class Drug(Thing):
        pass
    class ActivePrinciple(Thing):
        pass
    class has_for_active_principle(Drug >> ActivePrinciple):
        pass
    class someActivePrinciple(ActivePrinciple):
        pass
    class MyDrug(Drug):
        has_for_active_principle = [someActivePrinciple] #this one has some property restriction

# let's separate the worlds
world2 = World()
onto2 = world2.get_ontology("http://test.org/onto.owl")

with onto2:
    class Drug(Thing):
        pass
    class ActivePrinciple(Thing):
        pass
    class has_for_active_principle(Drug >> ActivePrinciple):
        pass
    class someActivePrinciple(ActivePrinciple):
        pass
    class MyDrug(Thing): # not a subClass of Drug
        pass  # missing the has_for_active_principle restriction


# now we can save without mixing the ontologies
onto.save(file=r"c:\temp\owlready.rdf", format="rdfxml")
onto2.save(file=r"c:\temp\owlready2.rdf", format="rdfxml") 

请注意,目前存在一个bug,它阻止直接保存“world”,只能保存本体,但该bug已经在开发版本中得到纠正。请参阅owlready forum relevant discussion

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52459855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档