OWLAPI:HermiT推理器显示错误的结果,没有解释

时间:2016-07-22 10:44:17

标签: java owl ontology protege owl-api

我有通过Protege创建的本体论。

本体

<?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 -->

我想运行 HermiT 推理器来获取推断的类层次结构及其解释

以下是我的 JAVA代码

//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();

上述代码的输出是:

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。 HermiT推理器生成无解释。 (需要什么才能得到解释?)

Q2。在以下情况下,推理者还将一些事实/断言作为 Entailed -

1)SubClassOf(<http://www.semanticweb.org/ontologies/reasoner#A> <http://www.semanticweb.org/ontologies/reasoner#B>) [在本体论中提供]

2)SubClassOf(<http://www.semanticweb.org/ontologies/reasoner#B> <http://www.semanticweb.org/ontologies/reasoner#C>) [在本体论中提供]

我想获得像protege一样的数据。 Protege分别显示推断的公理及其解释。那么如何获得它们? (我添加了一些protege的屏幕截图供参考)

我的本​​体论:

enter image description here

蕴涵说明:

enter image description here

1 个答案:

答案 0 :(得分:4)

你在解释生成器上使用了错误的方法:我的意思是,你打电话

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

但是,如果你只提供一个类resp,为什么你认为这会给出一个公理的解释。班级表达?看看Javadoc,它说你调用的方法

“返回给定不可满足类的所有解释。”

这只是公理SubClassOf(CE, owl:Nothing)的便捷方法,即类CE不可满足。 在OWL中,您可以通过公理进行陈述,而这些是唯一可以真实的。坚持,从而被引入。简而言之,您必须使用子类公理并将其转换为类表达式,然后对其进行不可满足性测试:

A SubClassOf B => A and not B

有一个转换器类为你做任何OWL公理:

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