javaowlowl-apihermit

OWL api Java find Annotation


I have a .owl file with the syntax like this:

<AnnotationAssertion>
        <AnnotationProperty abbreviatedIRI="iri_of_annotation"/>
        <IRI>subject</IRI>
        <IRI>object</IRI>
</AnnotationAssertion>

So I can get the annotations of an individual:

OWLAnnotationProperty prop = factory.getAnnotationProperty(IRI.create("iri_of_annotation"));
individual.getAnnotations(ontology, prop);

This will return a list of annotations where the subject of each one will be the individual and the value is like in the example file object and works as expected.

But what I need is somehow get a list where the value of the annotation is the individual's IRI and the subject will be for example like in the file subject.

Thanks in advance!


Solution

  • There is no convenience method to find the annotations with a certain value, so you will have to go through all annotation assertion axioms and check if the annotation value matches the value you're after.

    (The code you show seems to use OWLAPI 3 methods, is that correct? If so I'd recommend upgrading to a more recent version, OWLAPI 3 is really ancient now.)

    One note: IRI.create("iri_of_annotation") creates a relative IRI; when reading ontologies from a file, relative IRIs will be made absolute, and so it's very likely that you won't be able to match data as you want if you don't use absolute IRIs in your code.