我正在尝试使用隐士推理程序来检查一致性。默认情况下,隐士推理机不为不一致之处提供任何理由/解释。

编辑版本::我目前正在尝试使用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]与隐士Reasoner / OWLReasoner集成方面的任何帮助将不胜感激。

[1] https://github.com/matthewhorridge/owlexplanation

最佳答案

该错误是因为您将OWLReasoner强制转换为OWLReasonerFactory

您在上面的几行中使用的是HermiT的OWLReasonerFactory

new Reasoner.ReasonerFactory()

10-08 01:10