繁体   English   中英

Java owlapi 提取物

[英]Java owlapi extract

我有一个本体

<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,例如

OWL 中的rdfs:label是一个注解 要获取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版本objectPropertiesInSignature java-9已经发布了几天,所以现在是学习stream功能的好时机。

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

暂无
暂无

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

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