问题
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.
来源:https://stackoverflow.com/questions/25622694/how-to-get-annotations-from-owl-individual-using-owlapi