简体   繁体   English

Java owlapi 提取物

[英]Java owlapi extract

I have an ontology我有一个本体

<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>

I'm trying to extract all the ObjectProperties,我正在尝试提取所有 ObjectProperties,

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

this will print the name of ObjectProperty, eg http://purl.obolibrary.org/obo/BFO_0000050 .这将打印 ObjectProperty 的名称,例如http://purl.obolibrary.org/obo/BFO_0000050

I wonder how to get the rdfs:label, eg part of我想知道如何获得 rdfs:label,例如

The rdfs:label in OWL is an annotation . OWL 中的rdfs:label是一个注解 To get the label you must query for the annotation of the objectProperty you want.要获取label您必须查询所需的 objectProperty 的注释。

To display all annotations of an ontology you can do something like that :要显示本体的所有注释,您可以执行以下操作:

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() is deprecated in the modern (more than one year) version of owlapi (5). getObjectPropertiesInSignature()在 owlapi (5) 的现代(一年多)版本中已弃用。 So please considere using the stream version objectPropertiesInSignature of java-8 .所以请考虑使用java-8stream版本objectPropertiesInSignature java-9 have been release few days ago, so it is a good time to learn the stream functionnality. java-9已经发布了几天,所以现在是学习stream功能的好时机。

NB: the annotations are almost free, but OWL2 have put some more standardisation on it, so there is annotations with 'predefined semantics'.注意:注释几乎是免费的,但是OWL2 对其进行了更多的标准化,因此有带有“预定义语义”的注释。

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

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