使用 owl api 获取单个属性

0 java owl ontology

我正在尝试读取存储在本体中的信息。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>
Run Code Online (Sandbox Code Playgroud)

我使用以下 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();
Run Code Online (Sandbox Code Playgroud)

有了这个,我就找到了命名的关系。我想通过以下方式读取它们的属性:

Map<OWLObjectPropertyExpression,Set<OWLIndividual>> properties = oneRelation.getObjectPropertyValues(owlOnt);
Run Code Online (Sandbox Code Playgroud)

但我得到一张空地图。我找不到解决方案,有人可以帮助我吗?

Art*_*mis 5

我不太确定你在做什么,但是有一种比你使用的方法更容易从本体中读取个体的方法。我建议你阅读 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());
        }
    }
Run Code Online (Sandbox Code Playgroud)

基本上,您可以检查每个公理是否嵌入了一个单独的公理,然后提取该属性。