Consistency checking using Hermit reasoner in Python for an Ontology

荒凉一梦 提交于 2019-12-08 10:44:29

问题


I am using owlready2 api for python to load an Ontology and check consistency for that ontology using the sync_reasoner() function. But it seems that it is not checking the consistency for the ontology. Although there is an error, it shows nothing! Any idea how can I check consistency of an ontology in python using owlready2 or any other api.

here is my small code:

from owlready2 import *
onto = get_ontology("test.owl")
sync_reasoner()

and here is the output I am getting:

  • Owlready2 * Running HermiT... java -Xmx2000M -cp C:\Users\44999038\AppData\Local\Programs\Python\Python36-32\lib\site-packages\owlready2\hermit;C:\Users\44999038\AppData\Local\Programs\Python\Python36-32\lib\site-packages\owlready2\hermit\HermiT.jar org.semanticweb.HermiT.cli.CommandLine -c -O -D -I file:///C:/Users/44999038/AppData/Local/Temp/tmptmcc_a79
  • Owlready2 * HermiT took 0.48622655868530273 seconds

Ontology:

My modified code:

from owlready2 import *

onto = get_ontology("test.owl")
with onto:sync_reasoner()
onto.save()

Output owl file I have got:


回答1:


The output you are showing is merely the output of OWLReady calling the HermiT reasoner from the commandline. Hence, the reason why the "output" is the same irrespective.

What you need is the inference results after classification. According to the documentation you can direct the inferences to a file, or get the results from your classes as shown in this example.

What is not obvious, is how to determine whether the ontology is inconsistent or not. The best I can find is that you need to search through the inference results and if you can find a class that is equivalent to owl:Nothing, your ontology is inconsistent.




回答2:


Basically I was missing two important things.

  1. I have put onto.save() instead of onto.save("test_t1.owl"). Although its okay to put only onto.save() but onto.save("test_t1.owl") saves the output in different file.

  2. I was missing the load() function while mentioning the source ontology onto = get_ontology("file path").load() This file path could be a URL such as "https://protege.stanford.edu/ontologies/pizza/pizza.owl" or a local directory path "C:\User\Desktop\test.owl"

My working code is given below:

from owlready2 import *
import owlready2

#owlready2.JAVE_EXE="C:\\Program Files\\Java\\jdk1.8.0_144\\bin\\java.exe"
onto_path.append("C:\\User\\Desktop")
onto = get_ontology("test.owl").load()
#inferred_onto = get_ontology("http://test.org/my_inferrences.owl";)
with onto: sync_reasoner()
onto.save("test_t1.owl")



来源:https://stackoverflow.com/questions/51147628/consistency-checking-using-hermit-reasoner-in-python-for-an-ontology

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!