How to get annotations from owl individual using O

2019-09-04 23:25发布

问题:

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());
}

回答1:

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());
}


回答2:

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

It works with entities and anonymous individuals.



标签: java owl owl-api