Java 使用OWLAPI获取单个属性

Java 使用OWLAPI获取单个属性,java,owl,ontology,Java,Owl,Ontology,我试图读取存储在本体中的信息。XML绑定(我正在处理的部分)是: 我使用以下Java代码: //Create factories that will produce the objects OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory(); OWLDataFactory fac = man.getOWLDataFactory(); //Get a reasoner, to query the ontol

我试图读取存储在本体中的信息。XML绑定(我正在处理的部分)是:


我使用以下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();
//创建将生成对象的工厂
OWLReasonerFactory reasonerFactory=新的StructuralReasonerFactory();
OWLDataFactory=man.getOWLDataFactory();
//获取推理器,以查询本体
OWLReasonerConfiguration配置=新的SimpleConfiguration();
OWLReasoner=reasonerFactory.createReasoner(owlOnt,config);
//获得关系。它们的属性是相关的个体
OWLClass myclass=fac.getOWLClass(IRI.create(“http://www.myexampledomain.com/myExample.owl#RelationClass"));
NodeSet individualsRelationNodeSet=reasoner.getInstances(myclass,false);
Set relations=individualsRelationNodeSet.GetFlatten();
有了这个,我就有了与之相关的个人的名字。我想通过以下方式阅读它们的属性:

Map<OWLObjectPropertyExpression,Set<OWLIndividual>> properties = oneRelation.getObjectPropertyValues(owlOnt);
Map properties=oneRelation.getObjectPropertyValue(owlOnt);

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

我不太确定你在做什么,但从本体中读取个体的方法比你使用的更简单。我建议您阅读OWLAPI文档,它有很多很好的例子

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());
        }
    }
Set axiomSet=localOntology.getLogicalAxioms();
Iterator iteratorAxiom=axiomSet.Iterator();
while(iteratorAxiom.hasNext()){
OWLAxiom tempAx=iteratorAxiom.next();
如果(!tempAx.getIndividualsInSignature().isEmpty()){
System.out.println(tempAx.getIndividualsInSignature());
System.out.println(tempAx.getDataPropertiesInSignature());
System.out.println(tempAx.getObjectPropertiesInSignature());
}
}

基本上,您只需检查每个公理中是否嵌入了个体,然后提取属性。

我不确定您在做什么,但从本体中读取个体的方法比您使用的方法更简单。我建议您阅读OWLAPI文档,它有很多很好的例子

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());
        }
    }
Set axiomSet=localOntology.getLogicalAxioms();
Iterator iteratorAxiom=axiomSet.Iterator();
while(iteratorAxiom.hasNext()){
OWLAxiom tempAx=iteratorAxiom.next();
如果(!tempAx.getIndividualsInSignature().isEmpty()){
System.out.println(tempAx.getIndividualsInSignature());
System.out.println(tempAx.getDataPropertiesInSignature());
System.out.println(tempAx.getObjectPropertiesInSignature());
}
}

基本上,您只需检查每个axiom中是否嵌入了一个单独的属性,然后提取属性。

谢谢,Axioms解决方案似乎比我的更好:)谢谢,Axioms解决方案似乎比我的更好:)空映射可能意味着值要么在导入的本体中声明,要么在iri中存在键入错误,例如,属性iNote表示structural Reasurer不进行推理Sempty map可能意味着在导入的本体中声明了值,或者在iri中存在键入错误,例如属性iNote表示structural Reasurer不进行推理