如何使用OWLAPI获取个人对象属性集

时间:2015-09-06 14:15:19

标签: java owl-api

请,我想使用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>

输出:

  • Mark1 - &gt; CAR1
  • Mark2 - &gt; CAR2

提前感谢您的帮助

2 个答案:

答案 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>
这有利于寻找您想要使用的财产,而不是特定个人的所有财产。