我正在尝试使用 Hermit Reasoner 来检查一致性。Hermit reasoner 默认不提供任何不一致的理由/解释。
编辑版本:: 我目前正在尝试使用 OWLReasoner,但它仍然会引发错误。
import java.util.Set;
import org.semanticweb.HermiT.Reasoner;
import org.semanticweb.owl.explanation.api.Explanation;
import org.semanticweb.owl.explanation.api.ExplanationGeneratorFactory;
import org.semanticweb.owl.explanation.api.ExplanationManager;
import org.semanticweb.owl.explanation.impl.blackbox.checker.InconsistentOntologyExplanationGeneratorFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.reasoner.Node;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owl.explanation.api.ExplanationGenerator;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
public class ConsistencyChecker {
public static void main(String[] args) throws Exception {
OWLOntologyManager m=OWLManager.createOWLOntologyManager();
OWLOntology o=m.loadOntologyFromOntologyDocument(IRI.create("http://www.cs.ox.ac.uk/isg/ontologies/UID/00793.owl"));
// Reasoner hermit=new Reasoner(o);
OWLReasoner owlreasoner=new Reasoner.ReasonerFactory().createReasoner(o);
System.out.println(owlreasoner.isConsistent());
//System.out.println(hermit.isConsistent());
//---------------------------- Copied from example---------
OWLDataFactory df = m.getOWLDataFactory();
OWLClass testClass = df.getOWLClass(IRI.create("urn:test#testclass"));
m.addAxiom(o, df.getOWLSubClassOfAxiom(testClass, df.getOWLNothing()));
OWLNamedIndividual individual = df.getOWLNamedIndividual(IRI
.create("urn:test#testindividual"));
m.addAxiom(o, df.getOWLClassAssertionAxiom(testClass, individual));
//----------------------------------------------------------
Node<OWLClass> unsatisfiableClasses = owlreasoner.getUnsatisfiableClasses();
//Node<OWLClass> unsatisfiableClasses = hermit.getUnsatisfiableClasses();
for (OWLClass owlClass : unsatisfiableClasses) {
System.out.println(owlClass.getIRI());
}
//-----------------------------
ExplanationGeneratorFactory<OWLAxiom> genFac = ExplanationManager.createExplanationGeneratorFactory((OWLReasonerFactory) owlreasoner);
ExplanationGenerator<OWLAxiom> gen = genFac.createExplanationGenerator(o);
//-------------------------
InconsistentOntologyExplanationGeneratorFactory igf = new InconsistentOntologyExplanationGeneratorFactory((OWLReasonerFactory) owlreasoner, 10000);
//InconsistentOntologyExplanationGeneratorFactory igf = new InconsistentOntologyExplanationGeneratorFactory((OWLReasonerFactory) hermit, 10000);
ExplanationGenerator<OWLAxiom> generator = igf.createExplanationGenerator(o);
OWLAxiom entailment = df.getOWLClassAssertionAxiom(df.getOWLNothing(),
individual);
//-------------
Set<Explanation<OWLAxiom>> expl = gen.getExplanations(entailment, 5);
//------------
System.out.println("Explanation "
+ generator.getExplanations(entailment, 5));
}
}
输出是
true
http://www.w3.org/2002/07/owl#Nothing
http://www.co-ode.org/ontologies/pizza/pizza.owl#CheeseyVegetableTopping
http://www.co-ode.org/ontologies/pizza/pizza.owl#IceCream
Exception in thread "main" java.lang.ClassCastException: org.semanticweb.HermiT.Reasoner cannot be cast to org.semanticweb.owlapi.reasoner.OWLReasonerFactory
at ConsistencyChecker.main(ConsistencyChecker.java:82)
将 owlexplanation api [1]与 Hermit Reasoner/OWLReasoner 集成的任何帮助将不胜感激。