I want to get inferred axioms from reasoner [HermiT] along with its proper explanation. I have following ontology created in protege.
A.owl
<?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/A#"
xml:base="http://www.semanticweb.org/ontologies/A"
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/A"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/ontologies/A#A -->
<owl:Class rdf:about="http://www.semanticweb.org/ontologies/A#A">
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/A#B"/>
</owl:Class>
<!-- http://www.semanticweb.org/ontologies/A#B -->
<owl:Class rdf:about="http://www.semanticweb.org/ontologies/A#B">
<owl:equivalentClass rdf:resource="http://www.semanticweb.org/ontologies/A#C"/>
</owl:Class>
<!-- http://www.semanticweb.org/ontologies/A#C -->
<owl:Class rdf:about="http://www.semanticweb.org/ontologies/A#C"/>
</rdf:RDF>
<!-- Generated by the OWL API (version 3.5.1) http://owlapi.sourceforge.net -->
Following is my Java code :-
//Some work done to load ontology
ReasonerFactory factory = new ReasonerFactory();
Reasoner reasoner = new Reasoner(reasonerConf, owlOntology);
BlackBoxExplanation explain = new BlackBoxExplanation(owlOntology, factory, reasoner);
HSTExplanationGenerator multiEx = new HSTExplanationGenerator(explain);
InferredSubClassAxiomGenerator gen = new InferredSubClassAxiomGenerator();
Set<OWLSubClassOfAxiom> subClass = gen.createAxioms(dataFactory, reasoner);
SatisfiabilityConverter converter = new SatisfiabilityConverter(dataFactory);
for (OWLSubClassOfAxiom ax : subClass) {
System.out.println("\nAxiom :- " + ax);
System.out.println("Is axiom entailed by reasoner ? :- " + reasoner.isEntailed(ax));
System.out.println("Is axiom contained in ontology ? :- " + owlOntology.containsAxiom(ax));
Set<Set<OWLAxiom>> expl = multiEx.getExplanations(converter.convert(ax));
System.out.println("No. of Explanations :- " + expl.size());
System.out.println("Explanation :- ");
for (Set<OWLAxiom> a : expl) {
System.out.println(a);
}
}
According to my code here is the output :-
Axiom :- SubClassOf(<http://www.semanticweb.org/ontologies/A#B> owl:Thing)
Is axiom entailed by reasoner ? :- true
Is axiom contained in ontology ? :- false
No. of Explanations :- 1
Explanation :-
[EquivalentClasses(<http://www.semanticweb.org/ontologies/A#B> <http://www.semanticweb.org/ontologies/A#C> )]
Axiom :- SubClassOf(<http://www.semanticweb.org/ontologies/A#C> owl:Thing)
Is axiom entailed by reasoner ? :- true
Is axiom contained in ontology ? :- false
No. of Explanations :- 1
Explanation :-
[EquivalentClasses(<http://www.semanticweb.org/ontologies/A#B> <http://www.semanticweb.org/ontologies/A#C> )]
Axiom :- SubClassOf(<http://www.semanticweb.org/ontologies/A#A> <http://www.semanticweb.org/ontologies/A#B>)
Is axiom entailed by reasoner ? :- true
Is axiom contained in ontology ? :- true
No. of Explanations :- 1
Explanation :-
[SubClassOf(<http://www.semanticweb.org/ontologies/A#A> <http://www.semanticweb.org/ontologies/A#B>)]
Axiom :- SubClassOf(<http://www.semanticweb.org/ontologies/A#A> <http://www.semanticweb.org/ontologies/A#C>)
Is axiom entailed by reasoner ? :- true
Is axiom contained in ontology ? :- false
No. of Explanations :- 1
Explanation :-
[EquivalentClasses(<http://www.semanticweb.org/ontologies/A#B> <http://www.semanticweb.org/ontologies/A#C> ), SubClassOf(<http://www.semanticweb.org/ontologies/A#A> <http://www.semanticweb.org/ontologies/A#B>)]
I have following questions :
1) Is this code sufficient to get inferred axioms ? (Like I can check whether new axiom is available inside original ontology, if no then its an inferred axiom - [Take care of axioms saying C SubClassOf owl:Thing
])
2) What is the use of reasoner's isEntailed()
method if its giving true
always ?
3) There is always 1 explanation for inferred axiom. Is it correct ? For inferred axiom A SubClassOf C
, has 1 explanation but its Set
is opposite (order-wise) of what has shown in protege. So I need to show it in reverse direction always ?
Protege image :-
1) yes it is sufficient - an axiom that's entailed and present in the ontology is usually called 'asserted'.
2) isEntailed() does not always return true. It does for the axioms you're using - try asking if owl:Thing is subclass if owl:Nothing.
3) there is at least one explanation for an entailed axiom. When the axiom is contained in the ontology, it is the trivial explanation - all contained axioms are entailed. For more complex cases, multiple explanations are possible.