[英]OWLAPI 5: how to iterate over the classes of my ontology to insert individuals?
[英]How to get Individuals set of Object Property with OWLAPI
請,我想使用OWLAPI用Java程序解析以下本體。
<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>
輸出:
預先感謝您的幫助
您需要首先提取本體中的個體,然后要求OWL API
查找分配給這些個體的對象屬性的值:
Set<OWLNamedIndividual> inds=localOntology.getIndividualsInSignature();
for (OWLNamedIndividual ind: inds){
System.out.println(ind.getObjectPropertyValues(localOntology));
}
或者,您可以使用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>
這樣做的好處是,可以精確地查找要使用的屬性,而不是特定個體上的所有屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.