Search code examples
javasemantic-webowllinked-data

How to parse OWL2 file with OWLAPI - AnnotationProperties


I have an OWL file (OWL2) that I need to parse and ultimately write the data into some file. The file contains AnnotationProperties, DataProperties, ObjectProperties and Classes.

My first aim is to try to list out the property information as much as possible. i.e. for AnnotationProperties to see if I can print out the name of the property and the "value".

Similarly, to be able to display the class details i.e. for each class, the name of the class, the properties i.e. data or object properties of the class. I'm not sure how to do this and any reading I've done so far is confusing because it seems to talk about instances, which I don't believe are present in the file. Also, the OWLAPI javadoc and documentation and such are not very helpful with the kind of methods I might have to be calling.

E.g. if I had the following AnnotationProperty:

<owl:AnnotationProperty rdf:about="&xxx;SOME_ID">
    <ABC rdf:datatype="xsd;string">1235412</ABC>
</owl:AnnotationProperty>

ontology.getAnnotationPropertiesInSignature() would get me a set of AnnotationProperties and I can iterate and say property.getIRI().getFragment() to see the SOME_ID, but now how would I obtain and display the inner contents i.e. the ABC-1235412 ? Similarly, any help on how to obtain the information of a class i.e. display or show its properties and restrictions is appreciated.


Solution

  • The fragment you're showing does not create an annotation assertion axiom with property SOME_ID, it is instead an annotation on the property SOME_ID itself. The triple looks like this:

    SOME_ID ABC "1235412"^^xsd:int

    From your description of what you're trying to do, you /need/ instances - values for any property (annotation, object or data property) are expressed through assertions, i.e., axioms which refer to an individual (or instance - the two names refer to the same concept).

    E.g.,

    Ignazio hasAge "38"^^xsd:int

    would be a data or annotation property assertion on the individual Ignazio with value 38.

    To access these assertions, you can use

    OWLIndividual ignazio = ...
    ontology.getAnnotationAssertionAxioms(ignazio);
    

    To access annotations like the one you show, i.e., on the annotatio property itself:

    OWLAnnotationProperty some_id = ...
    ontology.getAnnotationAssertionAxioms(some_id.getIRI());