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:
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.
Basically I was missing two important things.
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.
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")