1

Protege OWL API 4.3 (OWL API 3.4.2) を使用しています。HermiT Reasoner Plugin がインストールされています。

私の問題は、推論用のクエリが何であれ、出力がなく、インスタンスが提供されないことです。

これは私のオントロジーがどのように見えるかです:

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

これは私のコードです:

    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 クエリは、位置が「1」の人物を探します。System.out.println には個々の「Mary」が表示されるはずですが、結果はありません。誰かが私が欠けているものを教えてもらえますか? http://code.google.com/p/elk-reasoner/wiki/QueryingComplexClassesに従ってすべてを行ったと思います。コードはほぼ 1:1 です。

乾杯、S.

4

1 に答える 1