(Thanks of the comments, I am updating my code and question. Maybe it will be useful for others.)
Update
I am doing several edit processes in one ontology, at the end, I realized my ontology is inconsistent. Now I should get rid of all the unsatisfiable classes.
I searched a lot, but there is no code to solve the inconsistencies.
Follow the approach of this paper and the library of Matthew Horridge and this, still I am struggling with this issue.
I update my code and question, this is my solution. Is there any more suggestion for it?
What I am doing to solve the inconsistencies:
- Run a reasoner to find unsatisfiable classes
- From the all unsatisfiable classes, only find the root-unsatisfiable-classes
- Find explanation axioms for them
- Rank them and select the axioms which should be deleted (or rewrite) by the user
In my below code (using other existing solutions), I only need to implement rank function (the left open issue in inconsistency resolver).
For example, for my ontology, it has 25 unsatisfiable classes, which only 2 of them are the root of inconsistencies. These 2 root-classes, has 11 axioms (which I get them by getExplanations
)
import java.io.File;
import java.util.Iterator;
import java.util.Set;
import org.semanticweb.owl.explanation.impl.rootderived.CompleteRootDerivedReasoner;
import org.semanticweb.owl.explanation.impl.rootderived.StructuralRootDerivedReasoner;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import com.clarkparsia.owlapi.explanation.BlackBoxExplanation;
import com.clarkparsia.owlapi.explanation.HSTExplanationGenerator;
import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;
public class InconsistencyTest {
public static void main(String areg[]) throws Exception {
File fileM = new File("address\\to\\my\\ontology\\myOnt.owl");
OWLOntologyManager tempManager = OWLManager.createOWLOntologyManager();
OWLOntology ont = tempManager.loadOntologyFromOntologyDocument(fileM);
// run an reasoner
OWLReasonerFactory reasonerFactory = new PelletReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createNonBufferingReasoner(ont);
if (reasoner.isConsistent()) {
// an ontology can be consistent, but have unsatisfiable classes.
if (reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size() > 0) {
// means: an ontology is consistent but unsatisfiable!
System.out.println("The ontology FAILED satisfiability test with Pellet reasoner. \n Unsatisfiable classes detected: "
+ reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().size());
// This line return all unsatisfibaleClasses, but I do not need it
// Iterator<OWLClass> aList=reasoner.getUnsatisfiableClasses().getEntitiesMinusBottom().iterator();
// get root of unstaisfiableClasses, and get their explanations
BlackBoxExplanation bb = new BlackBoxExplanation(ont, reasonerFactory, reasoner);
HSTExplanationGenerator multExplanator = new HSTExplanationGenerator(bb);
CompleteRootDerivedReasoner rdr = new CompleteRootDerivedReasoner(tempManager, reasoner, reasonerFactory);
for (OWLClass cls : rdr.getRootUnsatisfiableClasses()) {
System.out.println("**** ROOT! " + cls);
int maxEntailment = 5;
Set<Set<OWLAxiom>> exSet = multExplanator.getExplanations(cls, maxEntailment);
OWLAxiom deletedAxiom = rankAxiom(exSet);
//return these axioms to user to delete or rewrite them
}
} else {
System.out.println("The ontology PASSED the consistency test.");
}
} else {
System.out.println("The ontology FAILED the consistency test, please review the Axioms or debug using Protege");
}
reasoner.dispose();
}
Do I follow everything correct? Is there any suggestion for rank the axioms?
Very Thanks