owlcs / owlapi

OWL API main repository
821 stars 315 forks source link

Unable to fetch annotations from OWLClass #1075

Closed pradeepharbour closed 1 year ago

pradeepharbour commented 1 year ago

Hi, I have few annotations defined for a class in RDF, I am not able to fetch them from the api. Here is what I tried,

ontology.getAnnotations(new OWLAnnotationPropertyImpl(owlClass.getIRI()));

This is returning empty list. Can someone help me how to extract them?

ignazio1977 commented 1 year ago

ontology::getAnnotations is looking for annotation axioms where the input annotation matches the annotation property; using the owlClass IRI is unlikely to work because owl classes and annotation properties should not have the same IRI (forbidden punning in OWL). Unless in your ontology the annotation property IRI actually matches the class IRI, no results are expected.

Use EntitySearcher.getAnnotationObjects(owlClass, ontology) instead.

Note: do not instantiate manually Impl classes, use an instance of OWLDataFactory instead. OWLManager can be used to get data factory instances.