Check ontology consistency & satisifiability with OWL API 4

1.7k views Asked by At

I'm trying to check an ontology for its consistency. The ontology includes only descriptions of individuals, the class and semantic rules are described by an imported ontology.

I thougt using the isConsistenct method would be the right choice.

OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
OWLReasoner reasoner =     reasonerFactory.createNonBufferingReasoner(mergedOntology);
    if(reasoner.isConsistent()){
        return "Merged ontology PASSED the consistency test";
    }else{
        return "Ontology FAILED the consistency test";
    } 

What would be the correct approach to check the ontology's consistency, like Protege 5 applies when starting a reasoner?


Code update using Pellet

        OWLReasonerFactory reasonerFactory = new PelletReasonerFactory();
        OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner(mergedOntology);
        String answer = "";
        if(reasoner.isConsistent()){
            if(reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size()>0){
                answer = "Merged ontology FAILED satisfiability test. Unsatisfiable classes detected: " + reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size();
            }
            answer = "Merged ontology PASSED the consistency test";
        }else{
            answer = "Merged ontology FAILED the consistency test, please review the Axioms or debug using Protege";
            //FYI an example how to implement a working debugger can be found on sourceforge's OWL API page under Debugger 
        }
        reasoner.dispose();
        return answer;
2

There are 2 answers

4
Ignazio On BEST ANSWER

The approach is right but the use of the StructuralReasonerFactory is an issue. That reasoner does no real reasoning, it merely uses asserted axioms to answer some basic queries. It cannot check consistency.

You need to use a real reasoner to carry out the consistency check. There are a few reasoners already supporting OWLAPI 4, see https://github.com/owlcs/owlapi/wiki

3
Artemis On

Protege is also using some sort of isConsistent method. Depending on which version you are referring to, this method either is built in by the developers or used the one that is developed in OWL API. For example, look at this. However, when you run the reasoner in Protege, both the inConsistent and isSatisfiable methods are fired. So what you see is the result of two actions. Read the following blog post for understanding the difference if you need. The gist is:

So, while we can have unsatisfiable classes in a consistent ontology, all classes in an inconsistent ontology are unsatisfiable because an inconsistent ontology simply has no model, and thus it can’t have one with instances of any given class.

If you want to find the unsatisfiable classes, you just need to call the isSatisfiable method on all the classes:

reasoner.isSatisfiable(className);