简体   繁体   中英

How to get annotations from owl individual using OWLAPI

I already know how to get annotations from OWL classes (see the java code below). But I'm not able to get annotations from OWL individuals. Could anybody please tell me how to code the same functionality for an OWLIndividual instead of an OWLClass? Thankyou!

IRI iri = IRI.create("http://www.example.com/ontology/108024893-n"); //class IRI
OWLClass clazz = manager.getOWLDataFactory().getOWLClass(iri);

for (OWLAnnotation annotation : clazz.getAnnotations(ontology)) 
{
  System.out.println("\nannotation value: "+annotation.getValue());
}

I got the solution: I had to convert individual into an OWLEntity:

OWLEntity entity = (OWLEntity)individual;
for (OWLAnnotation annotation : entity.getAnnotations(ontology)) 
{
    System.out.println("\nannotation property->value: "+annotation.getProperty()+" -> "+annotation.getValue());
}

A general solution is to use OWLOntology.getAnnotationAssertionAxioms(OWLAnnotationSubject)

It works with entities and anonymous individuals.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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