4
votes

I have following ontology created through Protege.

Ontology :

<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
    <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<rdf:RDF xmlns="http://www.semanticweb.org/ontologies/reasoner#"
     xml:base="http://www.semanticweb.org/ontologies/reasoner"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
    <owl:Ontology rdf:about="http://www.semanticweb.org/ontologies/reasoner"/>
    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Object Properties
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->
    <!-- http://www.semanticweb.org/ontologies/reasoner#myProp -->
    <owl:ObjectProperty rdf:about="http://www.semanticweb.org/ontologies/reasoner#myProp"/>
    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Classes
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->
    <!-- http://www.semanticweb.org/ontologies/reasoner#A -->

    <owl:Class rdf:about="http://www.semanticweb.org/ontologies/reasoner#A">
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/reasoner#B"/>
    </owl:Class>
    <!-- http://www.semanticweb.org/ontologies/reasoner#B -->
    <owl:Class rdf:about="http://www.semanticweb.org/ontologies/reasoner#B">
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/reasoner#C"/>
        <rdfs:subClassOf>
            <owl:Class>
                <owl:intersectionOf rdf:parseType="Collection">
                    <rdf:Description rdf:about="http://www.semanticweb.org/ontologies/reasoner#D"/>
                    <owl:Restriction>
                        <owl:onProperty rdf:resource="http://www.semanticweb.org/ontologies/reasoner#myProp"/>
                        <owl:someValuesFrom rdf:resource="http://www.semanticweb.org/ontologies/reasoner#A"/>
                    </owl:Restriction>
                </owl:intersectionOf>
            </owl:Class>
        </rdfs:subClassOf>
    </owl:Class>
    <!-- http://www.semanticweb.org/ontologies/reasoner#C -->
    <owl:Class rdf:about="http://www.semanticweb.org/ontologies/reasoner#C">
        <owl:equivalentClass rdf:resource="http://www.semanticweb.org/ontologies/reasoner#D"/>
    </owl:Class>
    <!-- http://www.semanticweb.org/ontologies/reasoner#D -->
    <owl:Class rdf:about="http://www.semanticweb.org/ontologies/reasoner#D"/>
</rdf:RDF>
<!-- Generated by the OWL API (version 3.5.1) http://owlapi.sourceforge.net -->

I want to run HermiT reasoner to get inferred class hierarchy along with its explanation.

Following is my JAVA code :

//Some work done before to load the ontology into OWLOntologyManager
Configuration reasonerConf = new Configuration();
reasonerConf.throwInconsistentOntologyException = false;
ReasonerFactory factory = new ReasonerFactory();
OWLReasoner reasoner = factory.createReasoner(owlOntology, reasonerConf); // owlOntology : Current working Ontology
BlackBoxExplanation exp = new BlackBoxExplanation(owlOntology, factory, reasoner);
HSTExplanationGenerator multExplanator = new HSTExplanationGenerator(exp);
InferredSubClassAxiomGenerator ge = new InferredSubClassAxiomGenerator();
Set<OWLSubClassOfAxiom> subss = ge.createAxioms(dataFactory, reasoner); // dataFactory : OWLDataFactory
System.out.println("\nSubClassAxiom in reasoner :- ");
for (OWLSubClassOfAxiom ax : subss) {
    System.out.println("\nAxiom :- " + ax);
    System.out.println(ax.getSuperClass());
    System.out.println(ax.getSubClass());
    System.out.println("Is Axiom Entailed ? :- " + reasoner.isEntailed(ax));
    Set<Set<OWLAxiom>> expl = multExplanator.getExplanations(ax.getSuperClass());
    System.out.println("Explanation Set size :- " + expl.size());
}
reasoner.dispose();

My output for above code is :

SubClassAxiom in reasoner :- 

Axiom :- SubClassOf(<http://www.semanticweb.org/ontologies/reasoner#C> owl:Thing)
owl:Thing
<http://www.semanticweb.org/ontologies/reasoner#C>
Is Axiom Entailed ? :- true
Explanation Set size :- 0

Axiom :- SubClassOf(<http://www.semanticweb.org/ontologies/reasoner#B> <http://www.semanticweb.org/ontologies/reasoner#C>)
<http://www.semanticweb.org/ontologies/reasoner#C>
<http://www.semanticweb.org/ontologies/reasoner#B>
Is Axiom Entailed ? :- true
Explanation Set size :- 0

Axiom :- SubClassOf(<http://www.semanticweb.org/ontologies/reasoner#B> <http://www.semanticweb.org/ontologies/reasoner#D>)
<http://www.semanticweb.org/ontologies/reasoner#D>
<http://www.semanticweb.org/ontologies/reasoner#B>
Is Axiom Entailed ? :- true
Explanation Set size :- 0

Axiom :- SubClassOf(<http://www.semanticweb.org/ontologies/reasoner#D> owl:Thing)
owl:Thing
<http://www.semanticweb.org/ontologies/reasoner#D>
Is Axiom Entailed ? :- true
Explanation Set size :- 0

Axiom :- SubClassOf(<http://www.semanticweb.org/ontologies/reasoner#A> <http://www.semanticweb.org/ontologies/reasoner#B>)
<http://www.semanticweb.org/ontologies/reasoner#B>
<http://www.semanticweb.org/ontologies/reasoner#A>
Is Axiom Entailed ? :- true
Explanation Set size :- 0

Q1 . There are no explanations generated by HermiT reasoner. (Anything needed to get the explanations ?)

Q2 . Also the reasoner gives some facts/assertions as Entailed in following cases -

1) SubClassOf(<http://www.semanticweb.org/ontologies/reasoner#A> <http://www.semanticweb.org/ontologies/reasoner#B>) [Provided in Ontology]

2) SubClassOf(<http://www.semanticweb.org/ontologies/reasoner#B> <http://www.semanticweb.org/ontologies/reasoner#C>) [Provided in Ontology]

I want to get data just like protege. Protege shows inferred axioms separately along with their explanations. So how to get them ? (I have added some screen shots of protege for reference)

My Ontology:

enter image description here

Explanation for entailment:

enter image description here

1

1 Answers

4
votes

You are using the wrong method on the explanation generator: I mean, you call

Set<Set<OWLAxiom>> expl = multExplanator.getExplanations(ax.getSuperClass());

But why do you think this gives back explanations for an axiom if you provide only a class resp. class expression? Having a look at the Javadoc, it says that the method you called

"Returns all the explanations for the given unsatisfiable class."

This is just a convenience method for the axiom SubClassOf(CE, owl:Nothing), i.e. that the class CE is unsatisfiable. In OWL you can make statements via axioms, and those are the only thing that can be true resp. hold, and thus being entailed. Shortly said, you have to use the subclass axiom and convert it into a class expression which will then be tested for unsatisfiability:

A SubClassOf B => A and not B

There is a converter class that does it for you for any OWL axiom:

com.clarkparsia.owlapi.explanation.SatisfiabilityConverter::convert(OWLAxiom axiom)