![](/img/trans.png)
[英]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.