简体   繁体   English

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

[英]How to get Individuals set of Object Property with OWLAPI

Please, I want to parse the following ontology with java program using OWLAPI. 请,我想使用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>

The output: 输出:

  • Mark1 --> Car1 标记1->汽车1
  • Mark2 --> Car2 标记2->汽车2

Thank you in advance for your help 预先感谢您的帮助

You need to first extract the individuals in your ontology, and then ask OWL API to find the values of the object properties assigned to these individuals: 您需要首先提取本体中的个体,然后要求OWL API查找分配给这些个体的对象属性的值:

    Set<OWLNamedIndividual> inds=localOntology.getIndividualsInSignature();
    for (OWLNamedIndividual ind: inds){
        System.out.println(ind.getObjectPropertyValues(localOntology));
    }

Alternatively you can use an OWLDataFactory as 或者,您可以使用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));
    }

Although keep in mind 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)); returns a Set<OWLIndividual> 返回一个Set<OWLIndividual>
This has the benefit of looking for exactly the property you want to use as opposed to all the properties on a particular individual. 这样做的好处是,可以精确地查找要使用的属性,而不是特定个体上的所有属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM