请,我想使用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>
输出:
提前感谢您的帮助
答案 0 :(得分:2)
您需要首先提取本体中的个体,然后让OWL API
找到分配给这些个体的对象属性的值:
Set<OWLNamedIndividual> inds=localOntology.getIndividualsInSignature();
for (OWLNamedIndividual ind: inds){
System.out.println(ind.getObjectPropertyValues(localOntology));
}
答案 1 :(得分: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>
这有利于寻找您想要使用的财产,而不是特定个人的所有财产。