2014-12-29 8 views
3

Protege 4에서 간단한 온톨로지를 사용하여 Eclipse 3.4에서 OWL API 4.0을 사용하고 있습니다. "와드"와 "가우디안"의 두 클래스가 있습니다. 이러한 클래스의 개인은 객체 속성 isWardOf와 관련이 있습니다. Class Gaurdian의 같은 개인과 관련된 Ward 클래스의 개인을 검색하려면 어떻게해야합니까? 다음 그림을 고려하십시오 - 나는 그들이 모두 잭에 연결되어있는 베드로와 Allice가 관련 또는 형제 자매라는 사실을 검색 할OWL API 4.0을 사용하여 동일한 개체 속성을 가진 OWL 개체 검색

enter image description here

. 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> > 
올빼미 API 문서에

답변

1

여기에 있습니다. 내가 생각할 수있는 가장 간단한 방법입니다. 명목상의 추론을 포함하기 때문에 계산 비용이 많이 든다. 그러나 온톨로지가 너무 크지 않은 경우이 접근법이 가능합니다.

아이디어는 모든 가디언의 모든 인스턴스를 얻는 것입니다. 그런 다음 모든 개인은 isWard 속성에 의해 연결된 모든 개인을 얻습니다. 이 세트는 크기가 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 
    } 
} 
+0

이미 제안한 내용의 추적되지 않은 버전을 구현했습니다. 온톨로지가 크다. 그것은 실제로 비싸지 만 다른 제안은 없기 때문입니다. 나는 이것으로 지금 갈 것이다. – jaykio77

0

는 시험의 here

하나가 주장을 검색하는 거친 가이드 튜토리얼의 소스 코드에 대한 참조있다 당신의 필요에 맞게 조정할 수있는 객체 속성 :

@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); 
}