2015-09-06 20 views
0

請使用OWLAPI通過java程序解析以下本體。如何使用OWLAPI獲取個人對象屬性集

<ObjectPropertyAssertion> 
     <ObjectProperty IRI="http://onto1#creator"/> 
     <NamedIndividual IRI="Mark1"/> 
     <NamedIndividual IRI="Car1"/> 
    </ObjectPropertyAssertion> 
    <ObjectPropertyAssertion> 
     <ObjectProperty IRI="http://onto1#creator"/> 
     <NamedIndividual IRI="Mark2"/> 
     <NamedIndividual IRI="Car2"/> 
    </ObjectPropertyAssertion> 

輸出:

  • 標誌1 - >分享幫助
  • 標記2 - > CAR2

預先感謝您的幫助

回答

2

您需要先提取本體中的個體,然後請求OWL API查找對象的值分配給這些個人屬性:

Set<OWLNamedIndividual> inds=localOntology.getIndividualsInSignature(); 
    for (OWLNamedIndividual ind: inds){ 
     System.out.println(ind.getObjectPropertyValues(localOntology)); 
    } 
+0

非常感謝。 – khiat

+0

對於OWLAPI版本4,請檢查EntitySearcher - OWLEntity中聲明的許多方法已移至此處。 – Ignazio

+0

嗨!根據OWL API中的DataProperty有沒有簡短的方法來保留個人?例如,如果我想保留對我而言未知的個人,但我知道它應該具有DataProperty(假設orderNumber = 1)。 我認爲迭代Set inds需要更多時間。 – Fabi

0

或者你可以使用一個OWLDataFactory作爲

OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); 
OWLDataFactory factory = manager.getDataFactory(); 
Set<OWLNamedIndividual> inds = localOntology.getIndividualsInSignature(); 
    for (OWLNamedIndividual ind: inds){ 
     System.out.println(ind.getObjectPropertyValues(factory.getOWLObjectProperty(IRI.create("Put the iri of the property here")), localOntology)); 
    } 

雖然牢記System.out.println(ind.getObjectPropertyValues(factory.getOWLObjectProperty(IRI.create("Put the iri of the property here")), localOntology));返回Set<OWLIndividual>
這有您想尋找準確的財產利益使用而不是特定個人的所有特性。

+0

非常感謝,是的,我已經使用了這個解決方案,因爲它返回了一組特定對象屬性的個體。 – khiat