0

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: enter image description here

My modified code:

from owlready2 import *

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

Output owl file I have got:

enter image description here

Bayzid
  • 105
  • 11

2 Answers2

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.

Henriette Harmse
  • 4,167
  • 1
  • 13
  • 22
  • Thank you. I was following your instructions but couldn't manage to get the desired output. It gives me an empty owl file. My python code: `from owlready2 import * onto = get_ontology("test.owl") with onto:sync_reasoner() onto.save()` – Bayzid Jul 04 '18 at 01:33
  • and I get an owl file like this: ` ` Anyway Thank you very much for your help. – Bayzid Jul 04 '18 at 01:36
  • 1
    Since OWLReady calls HermiT from the commandline, you could use HermiT directly from the commandline and debug it in that way and check the output and work out how you can parse the output from OWLReady. I did try to go through the OWLReady code, but my knowledge of Python is limited. – Henriette Harmse Jul 04 '18 at 02:09
  • 1
    Frankly, if it was my choice I would rather use the Java OWL API, which has a more elegant API in my opinion. – Henriette Harmse Jul 04 '18 at 02:10
1

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")

Output file

Bayzid
  • 105
  • 11