3

Protege 4 の単純なオントロジーを使用して、Eclipse 3.4 で OWL Api 4.0 を使用しています。「Ward」と「Gaurdian」の 2 つのクラスがあります。これらのクラスの個体は、オブジェクト プロパティ isWardOf によって関連付けられます。クラス ガーディアンの同じ個人に関連するクラス ワードの個人を取得するにはどうすればよいですか? 次の図を検討してください:-

ここに画像の説明を入力

ピーターとアリスはどちらもジャックとつながっているため、血縁関係または兄弟であるという事実を取得したいと思います。OWL API 4.0を使用してこれを達成する方法についての大まかな手がかり。

私の完全なフクロウファイルが添付されています:-

<?xml version="1.0"?>


<!DOCTYPE Ontology [
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY xml "http://www.w3.org/XML/1998/namespace" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>


<Ontology xmlns="http://www.w3.org/2002/07/owl#"
 xml:base="http://www.semanticweb.org/antonio/ontologies/2014/11/untitled-ontology-46"
 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/antonio/ontologies/2014/11/untitled-ontology- 
 46">
 <Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
 <Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
 <Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
 <Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
 <Declaration>
    <Class IRI="#Gaurdian"/>
 </Declaration>
 <Declaration>
    <Class IRI="#Ward"/>
 </Declaration>
 <Declaration>
    <ObjectProperty IRI="#isWardOf"/>
 </Declaration>
 <Declaration>
    <NamedIndividual IRI="#Allice"/>
 </Declaration>
 <Declaration>
    <NamedIndividual IRI="#Amber"/>
 </Declaration>
 <Declaration>
    <NamedIndividual IRI="#Jack"/>
 </Declaration>
 <Declaration>
    <NamedIndividual IRI="#Paul"/>
 </Declaration>
 <Declaration>
     <NamedIndividual IRI="#Peter"/>
 </Declaration>
 <ClassAssertion>
    <Class IRI="#Ward"/>
    <NamedIndividual IRI="#Allice"/>
 </ClassAssertion>
 <ClassAssertion>
    <Class IRI="#Gaurdian"/>
    <NamedIndividual IRI="#Amber"/>
 </ClassAssertion>
 <ClassAssertion>
    <Class IRI="#Gaurdian"/>
    <NamedIndividual IRI="#Jack"/>
 </ClassAssertion>
 <ClassAssertion>
    <Class IRI="#Ward"/>
    <NamedIndividual IRI="#Paul"/>
 </ClassAssertion>
 <ClassAssertion>
    <Class IRI="#Ward"/>
    <NamedIndividual IRI="#Peter"/>
 </ClassAssertion>
 <ObjectPropertyAssertion>
    <ObjectProperty IRI="#isWardOf"/>
    <NamedIndividual IRI="#Allice"/>
    <NamedIndividual IRI="#Jack"/>
 </ObjectPropertyAssertion>
 <ObjectPropertyAssertion>
    <ObjectProperty IRI="#isWardOf"/>
    <NamedIndividual IRI="#Amber"/>
    <NamedIndividual IRI="#Jack"/>
 </ObjectPropertyAssertion>
 <ObjectPropertyAssertion>
    <ObjectProperty IRI="#isWardOf"/>
    <NamedIndividual IRI="#Paul"/>
    <NamedIndividual IRI="#Amber"/>
 </ObjectPropertyAssertion>
 <ObjectPropertyDomain>
    <ObjectProperty IRI="#isWardOf"/>
    <Class IRI="#Ward"/>
  </ObjectPropertyDomain>
  <ObjectPropertyRange>
    <ObjectProperty IRI="#isWardOf"/>
    <Class IRI="#Gaurdian"/>
  </ObjectPropertyRange>
  </Ontology> >
4

2 に答える 2

2

これが私が考えることができる最も簡単な方法です。これには名目上の推論が含まれるため、計算コストが高くなる可能性があります。ただし、オントロジーが大きすぎない場合、このアプローチは実行可能です。

アイデアは、すべてのガーディアンのすべてのインスタンスを取得することです。次に、そのような個体ごとに、isWard プロパティによって関連付けられているすべての個体を取得します。サイズが 1 より大きい場合、これらのセットが探しているものになります (セットのサイズが 1 の場合、指定されたガーディアンのウォードが 1 つしかない場合)。このための OWL API コードは次のようになります。

// load an ontology
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(ONTOLOGY_IRI);
OWLDataFactory df = manager.getOWLDataFactory();

// We need a reasoner to ask for individuals
OWLReasoner reasoner = createReasoner(ontology);
reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS);

// get all the gaurdians in the ontology
OWLClass gaurdian = df.getOWLClass(IRI.create("#Gaurdian"));
Set<OWLNamedIndividual> gaurdians = reasoner.getInstances(gaurdian, false).getFlattened();


for (OWLNamedIndividual g : gaurdians) {
    // all wards of a given gaurdian g
    OWLObjectProperty isWardOf = df.getOWLObjectProperty(IRI.create("#isWardOf"));
    OWLClassExpression wardsOfG = df.getOWLObjectHasValue(isWardOf, g);
    // get all the wards related to a given gaurdian
    Set<OWLNamedIndividual> wards = reasoner.getInstances(wardsOfG, false).getFlattened();
    if ( wards.size() > 1 ) {
        // this set of wards is connected to the same gaurdian
    }
}
于 2015-01-14T17:47:22.100 に答える
0

OWL API ドキュメントには、ラフ ガイド チュートリアルのソース コードへの参照があります。

テストの 1 つは、オブジェクト プロパティのアサーションを取得し、必要に応じて適応できるようにする必要があります。

@Test
public void testIndividualAssertions() throws OWLException {
    OWLOntologyManager m = create();
    OWLOntology o = m.createOntology(EXAMPLE_IRI);
    // We want to state that matthew has a father who is peter.
    OWLIndividual matthew = df.getOWLNamedIndividual(IRI.create(EXAMPLE_IRI
            + "#matthew"));
    OWLIndividual peter = df.getOWLNamedIndividual(IRI.create(EXAMPLE_IRI
            + "#peter"));
    // We need the hasFather property
    OWLObjectProperty hasFather = df.getOWLObjectProperty(IRI
            .create(EXAMPLE_IRI + "#hasFather"));
    // matthew --> hasFather --> peter
    OWLObjectPropertyAssertionAxiom assertion = df
            .getOWLObjectPropertyAssertionAxiom(hasFather, matthew, peter);
    // Finally, add the axiom to our ontology and save
    AddAxiom addAxiomChange = new AddAxiom(o, assertion);
    m.applyChange(addAxiomChange);
    // matthew is an instance of Person
    OWLClass personClass = df.getOWLClass(IRI.create(EXAMPLE_IRI
            + "#Person"));
    OWLClassAssertionAxiom ax = df.getOWLClassAssertionAxiom(personClass,
            matthew);
    // Add this axiom to our ontology - with a convenience method
    m.addAxiom(o, ax);
}
于 2014-12-31T20:34:24.563 に答える