简体   繁体   English

具有Protege OWL API的HermiT Resoner

[英]HermiT Resoner with Protege OWL API

I'm using the Protege OWL API 4.3 (OWL API 3.4.2). 我正在使用Protege OWL API 4.3(OWL API 3.4.2)。 It has the HermiT Reasoner Plugin installed wth it. 它安装了HermiT Reasoner插件。

My problem is that whatever query I have for the reasoner, there is no output, it does not provide any instances. 我的问题是我对推理机的任何查询都没有输出,它不提供任何实例。

This is how my ontology looks like: 这是我的本体的样子:

    <Ontology xmlns="http://www.w3.org/2002/07/owl#"
 xml:base="http://www.semanticweb.org/sabse/ontologies/2013/11/untitled-ontology-17"
 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:xml="http://www.w3.org/XML/1998/namespace"
 ontologyIRI="http://www.semanticweb.org/sabse/ontologies/2013/11/untitled-ontology-17">
<Prefix name="" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
<Declaration>
    <Class IRI="#Person"/>
</Declaration>
<Declaration>
    <Class IRI="#PersonWithPosition1"/>
</Declaration>
<Declaration>
    <DataProperty IRI="#position"/>
</Declaration>
<Declaration>
    <NamedIndividual IRI="#mary"/>
</Declaration>
<Declaration>
    <NamedIndividual IRI="#peter"/>
</Declaration>
<EquivalentClasses>
    <Class IRI="#PersonWithPosition1"/>
    <ObjectIntersectionOf>
        <Class IRI="#Person"/>
        <DataHasValue>
            <DataProperty IRI="#position"/>
            <Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#integer">1</Literal>
        </DataHasValue>
    </ObjectIntersectionOf>
</EquivalentClasses>
<SubClassOf>
    <Class IRI="#PersonWithPosition1"/>
    <Class IRI="#Person"/>
</SubClassOf>
<ClassAssertion>
    <Class IRI="#Person"/>
    <NamedIndividual IRI="#mary"/>
</ClassAssertion>
<ClassAssertion>
    <Class IRI="#Person"/>
    <NamedIndividual IRI="#peter"/>
</ClassAssertion>
<DataPropertyAssertion>
    <DataProperty IRI="#position"/>
    <NamedIndividual IRI="#mary"/>
    <Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#int">1</Literal>
</DataPropertyAssertion>
<DataPropertyAssertion>
    <DataProperty IRI="#position"/>
    <NamedIndividual IRI="#peter"/>
    <Literal datatypeIRI="http://www.w3.org/2001/XMLSchema#int">2</Literal>
</DataPropertyAssertion>
<DataPropertyDomain>
    <DataProperty IRI="#position"/>
    <Class IRI="#Person"/>
</DataPropertyDomain>
<DataPropertyRange>
    <DataProperty IRI="#position"/>
    <Datatype abbreviatedIRI="xsd:int"/>
</DataPropertyRange>

and this is my code: 这是我的代码:

    public class OWLAPIDemoApplication {

public static void main(String[] args) {

    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

    try {
        OWLOntology ontology;
        File file = new File("ontology.owl");
        ontology = manager.loadOntologyFromOntologyDocument(file);
        System.out.println("Loaded ontology: " + ontology);

        // Create an HermiT reasoner.

        Reasoner reasoner = new Reasoner(ontology);

        OWLDataFactory factory = manager.getOWLDataFactory();

        PrefixManager pm = new DefaultPrefixManager("#");

        // Get reference to the class PersonWithinPosition1
        OWLClass person = factory.getOWLClass(":Person", pm);

        OWLDataProperty position = factory.getOWLDataProperty(":position",
                pm);

        OWLClassExpression query = factory.getOWLObjectIntersectionOf(
                person,
                factory.getOWLDataHasValue(position,
                        factory.getOWLLiteral(1)));

        // Create a fresh name for the query.
        OWLClass newName = factory.getOWLClass(IRI.create("temp001"));

        // Make the query equivalent to the fresh class
        OWLAxiom definition = factory.getOWLEquivalentClassesAxiom(newName,
                query);
        manager.addAxiom(ontology, definition);

        manager.saveOntology(ontology, new SystemOutDocumentTarget());

        reasoner.flush();

        NodeSet<OWLNamedIndividual> w = reasoner
                .getInstances(newName, true);

        Set<OWLNamedIndividual> e;

        for (Node<OWLNamedIndividual> n : w) {

            for (OWLNamedIndividual i : n.getEntities()) {
                System.out.println(i.getIRI().toString());
            }

        }

        // After you are done with the query, you should remove the
        // definition
        manager.removeAxiom(ontology, definition);

        reasoner.dispose();

    } catch (OWLOntologyCreationException | OWLOntologyStorageException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

} 2 The query looks for persons that have the position "1". } 2查询查找位置为“ 1”的人员。 The System.out.println should show the individual "Mary", but there are no results. System.out.println应该显示单个的“ Mary”,但没有结果。 Can someone please tell what I am missing? 有人可以告诉我我想念什么吗? I think I did everything accoring to http://code.google.com/p/elk-reasoner/wiki/QueryingComplexClasses . 我认为我已经按照http://code.google.com/p/elk-reasoner/wiki/QueryingComplexClasses进行了所有操作。 The code is almost 1:1. 该代码几乎是1:1。

Cheers, S. 干杯,S。

You are creating the reasoner manually rather than through its factory. 您是在手动而不是通过工厂创建推理机。 This might leave it not listening for updates on the ontology, so the call to reasoner.flush() might not work. 这可能会导致它无法监听本体的更新,因此对reasoner.flush()的调用可能无法正常工作。 Try using Reasoner.ReasonerFactory to create instances and see if this fixes your issue. 尝试使用Reasoner.ReasonerFactory创建实例,看看是否可以解决您的问题。

Another possibility is that the IRIs in your code do not match those in the ontology. 另一种可能性是您代码中的IRI与本体中的IRI不匹配。 Make sure they do by printing out your IRIs and those in ontology.getSignature() . 通过打印出您的IRI和onology.getSignature ontology.getSignature() IRI来确保它们能够正常工作。

Edit: the second possibility is confirmed. 编辑:确认第二种可能性。 I copied your ontology fragment and your code in a test. 我在测试中复制了您的本体片段和您的代码。 The class IRIs in your ontology are: 本体中的IRI类为:

<http://www.semanticweb.org/sabse/ontologies/2013/11/untitled-ontology-17#Person>
<http://www.semanticweb.org/sabse/ontologies/2013/11/untitled-ontology-17#PersonWithPosition1>

The Person class in your code has IRI: 您代码中的Person类具有IRI:

<#Person>

The mismatch is caused by the prefix manager having "#" as default namespace. 不匹配是由前缀管理器将"#"作为默认名称空间引起的。 That is not the default namespace of your ontology. 那不是您的本体的默认名称空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM