[英]Getting individual properties with owl api
I'm trying to read the information stored in an ontology. 我正在尝试读取存储在本体中的信息。 The XML binding (of the part I'm working in) is:
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>
I use the following Java code: 我使用以下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();
With this, I have NamedIndividuals that are the relations found. 有了这个,我找到了名为NamedIndividuals的关系。 I want to read their properties with:
我想阅读它们的属性:
Map<OWLObjectPropertyExpression,Set<OWLIndividual>> properties = oneRelation.getObjectPropertyValues(owlOnt);
But I get an empty Map. 但是我得到一个空的地图。 I cannot find the solution, can anyone help me?
我找不到解决方案,有人可以帮助我吗?
I am not really sure what you are doing, but there is an easier way to read the individuals from the ontology than the one you used. 我不确定自己在做什么,但是从本体中读取个体的方法比您使用的个体更简单。 I would suggest you read the OWL API documentation, it has so many good examples.
我建议您阅读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());
}
}
Basically, you can just check if each axiom has an individual embedded in it, and then extract the property. 基本上,您可以仅检查每个公理是否嵌入了单独的公理,然后提取属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.