我试图读取存储在本体中的信息。 XML绑定(我工作的部分)是:
<!-- hasPrevious and hasNext are defined at the imported ontology -->
<owl:NamedIndividual rdf:about="http://www.myexampledomain.com/myExample.owl#one_relationship">
<rdf:type rdf:resource="http://www.myexampledomain.com/myExample.owl#typeA"/>
<intui_PO:hasPrevious rdf:resource="http://www.myexampledomain.com/myExample.owl#element01"/>
<intui_PO:hasNext rdf:resource="http://www.myexampledomain.com/myExample.owl#element02"/>
</owl:NamedIndividual>
我使用以下Java代码:
//Create factories that will produce the objects
OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
OWLDataFactory fac = man.getOWLDataFactory();
//Get a reasoner, to query the ontology
OWLReasonerConfiguration config = new SimpleConfiguration();
OWLReasoner reasoner = reasonerFactory.createReasoner(owlOnt, config);
//Get relations. Their properties are the related individuals
OWLClass myclass = fac.getOWLClass(IRI.create("http://www.myexampledomain.com/myExample.owl#RelationClass"));
NodeSet<OWLNamedIndividual> individualsRelationNodeSet = reasoner.getInstances(myclass,false);
Set<OWLNamedIndividual> relations = individualsRelationNodeSet.getFlattened();
有了这个,我找到了被发现的关系的名字个人。我想用以下内容阅读他们的属性:
Map<OWLObjectPropertyExpression,Set<OWLIndividual>> properties = oneRelation.getObjectPropertyValues(owlOnt);
但我得到一张空地图。我找不到解决方案,任何人都可以帮助我吗?
答案 0 :(得分:4)
我不确定你在做什么,但是有一种更简单的方法来阅读本体中的个体而不是你使用的个体。我建议你阅读OWL API文档,它有很多很好的例子。
Set<OWLLogicalAxiom> axiomSet=localOntology.getLogicalAxioms();
Iterator<OWLLogicalAxiom> iteratorAxiom= axiomSet.iterator();
while(iteratorAxiom.hasNext()) {
OWLAxiom tempAx= iteratorAxiom.next();
if(!tempAx.getIndividualsInSignature().isEmpty()){
System.out.println(tempAx.getIndividualsInSignature());
System.out.println(tempAx.getDataPropertiesInSignature());
System.out.println(tempAx.getObjectPropertiesInSignature());
}
}
基本上,你可以检查每个公理是否有一个嵌入其中的个体,然后提取属性。