I am trying to find out whether an ontology is inconsistent or not, and if it is inconsistent then to print which are the classes/ axioms which cause the inconsistency. I am getting the correct result regarding the inconsistency check, however I am stuck while printing the list of axioms behind the inconsistency. I tried an approach mentioned in a question of stackoverflow, but it is not working.
I checked and the problem is that no list of explanations are being stored in explanations variable. Can you point out where I am going wrong.
package com.tcs.HermiT;
import java.io.File;
import java.util.Set;
import org.semanticweb.HermiT.Configuration;
import org.semanticweb.HermiT.Reasoner;
import org.semanticweb.HermiT.Reasoner.ReasonerFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import com.clarkparsia.owlapi.explanation.BlackBoxExplanation;
import com.clarkparsia.owlapi.explanation.ExplanationGenerator;
import com.clarkparsia.owlapi.explanation.HSTExplanationGenerator;
public class Demo {
public void reason() throws OWLOntologyCreationException {
// First, we create an OWLOntologyManager object. The manager will load and save ontologies.
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory=m.getOWLDataFactory();
File inputOntologyFile = new File("C:\\Users\\1047785\\Desktop\\HermiT\\Input10.owl");
OWLOntology o=m.loadOntologyFromOntologyDocument(inputOntologyFile);// Now, we instantiate HermiT by creating an instance of the Reasoner class in the package org.semanticweb.HermiT.
ReasonerFactory factory = new ReasonerFactory();
Configuration configuration=new Configuration();
configuration.throwInconsistentOntologyException = false;
OWLReasoner reasoner=factory.createReasoner(o, configuration);
System.out.println("Consistency : "+reasoner.isConsistent());
System.out.println("Computing explanations for the inconsistency...");
factory=new Reasoner.ReasonerFactory() {
protected OWLReasoner createHermiTOWLReasoner(org.semanticweb.HermiT.Configuration configuration,OWLOntology o) {
// don't throw an exception since otherwise we cannot compte explanations
configuration.throwInconsistentOntologyException=false;
return new Reasoner(configuration,o);
}
};
BlackBoxExplanation exp=new BlackBoxExplanation(o, factory, reasoner);
HSTExplanationGenerator multExplanator=new HSTExplanationGenerator(exp);
// Now we can get explanations for the inconsistency
Set<Set<OWLAxiom>> explanations=multExplanator.getExplanations(dataFactory.getOWLThing());
// Let us print them. Each explanation is one possible set of axioms that cause the
// unsatisfiability.
for (Set<OWLAxiom> explanation : explanations) {
System.out.println("------------------");
System.out.println("Axioms causing the inconsistency: ");
for (OWLAxiom causingAxiom : explanation) {
System.out.println(causingAxiom);
}
System.out.println("------------------");
}
}
}
The output is coming as
consistency : true/false(correct result)
Computing explanations for inconsistency