0

我有一个本体

<owl:ObjectProperty rdf:about="http://purl.obolibrary.org/obo/BFO_0000050">
    <owl:inverseOf rdf:resource="http://purl.obolibrary.org/obo/BFO_0000051"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#TransitiveProperty"/>
    <oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">BFO:0000050</oboInOwl:hasDbXref>
    <oboInOwl:hasOBONamespace rdf:datatype="http://www.w3.org/2001/XMLSchema#string">external</oboInOwl:hasOBONamespace>
    <oboInOwl:id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">part_of</oboInOwl:id>
    <oboInOwl:shorthand rdf:datatype="http://www.w3.org/2001/XMLSchema#string">part_of</oboInOwl:shorthand>
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">part of</rdfs:label>
</owl:ObjectProperty>

我正在尝试提取所有 ObjectProperties,

for (OWLObjectProperty obp : ont.getObjectPropertiesInSignature()){
    System.out.println(obp.toString());
}

这将打印 ObjectProperty 的名称,例如http://purl.obolibrary.org/obo/BFO_0000050

我想知道如何获得 rdfs:label,例如

4

1 回答 1

1

rdfs:labelOWL 中的 是一个注解。要获得label你必须查询你想要的 objectProperty 的注解。

要显示本体的所有注释,您可以执行以下操作:

final OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File(my_file));

final List<OWLAnnotation> annotations = ontology.objectPropertiesInSignature()//
    .filter(objectProperty -> objectProperty.equals(the_object_property_I_want))//
    .flatMap(objectProperty -> ontology.annotationAssertionAxioms(objectProperty.getIRI()))//
    .map(OWLAnnotationAssertionAxiom::getAnnotation)//
    .collect(Collectors.toList());

for (final OWLAnnotation annotation : annotations)
    System.out.println(annotation.getProperty() + "\t" + annotation.getValue());

getObjectPropertiesInSignature()在 owlapi (5) 的现代(超过一年)版本中已弃用。所以请考虑使用java-8stream版本objectPropertiesInSignaturejava-9前几天发布了,现在是学习功能的好时机。stream

注意:注解几乎是免费的,但OWL2 对其进行了更多标准化,因此有带有“预定义语义”的注解。

于 2017-10-04T21:22:27.323 回答