Java owlapi extract

185 Views Asked by At

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,

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

this will print the name of ObjectProperty, e.g. http://purl.obolibrary.org/obo/BFO_0000050.

I wonder how to get the rdfs:label, e.g. part of

1

There are 1 best solutions below

4
On

The rdfs:label in OWL is an annotation. To get the label you must query for the annotation of the objectProperty you want.

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). So please considere using the stream version objectPropertiesInSignature of java-8 . java-9 have been release few days ago, so it is a good time to learn the stream functionnality.

NB: the annotations are almost free, but OWL2 have put some more standardisation on it, so there is annotations with 'predefined semantics'.