pythonontologyreasonerowlready

Consistency checking using Hermit reasoner in Python for an Ontology


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:

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


Solution

  • 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