我在本地本体上使用owlready2 python模块。
我已经连接了一个API端点,以提交关于此本体的查询。
我需要提交一些关于原始本体的查询,以及一些关于更新的本体(带有推论)的查询。
当我使用sync_reasoner()函数时,本体将使用HermiT进行的推理(即默认推理器)进行更新。
我的问题是,推理器做出的推论在对附加函数的不同调用中持续存在。
是否存在强制重置推断属性的解决方法?
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感谢你考虑我的问题,
阿盖里斯
发布于 2018-10-01 21:16:52
虽然我没有广泛地使用owlready2的推理功能,但我相信这与使用owlready2进行任何本体更新是一样的。
基本上,在owlready2中,要分离不同的本体或同一本体的不同版本(可能使用不同的命名空间),您需要将它们放在不同的“世界”中。语法描述为here。
下面是一些基于文档示例的代码,让您对语法有一个大致的了解
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
https://stackoverflow.com/questions/52459855
复制相似问题