How to access ontology annotations

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to access ontology annotations

Jade
I want to be able to programmatically access ontology annotations, so NOT those ascribed to terms/classes or annotation/object/data properties, but those applied to the ontology itself.

I code in python and have become familiar with using owlready2 to access ontology content (e.g. using .classes(), .annotation_properties(), etc, but I can't find how to access ontology annotations.

E.g. I have annotations such as dc:accessRights, dc:isReferencedBy, etc whichare used to annotate/describe the ontology itself. I need to be able to access these (so that I can extract them, translate them and add them back into the ontology file).

Is there a way to do this? I have tried using onto.annotations() and e.g. onto.abstract, but just get "None".

Many thanks!
Jade Hotchkiss
Reply | Threaded
Open this post in threaded view
|

Re: How to access ontology annotations

Jiba
Administrator
Hi,

You can access or modify ontology annotation via the "ontology.metadata" pseudo-object, for example to add a comment:

onto.metadata.comment.append("xxx")

(NB onto.abstract searches for an entity named "abstract" in the ontology, thus it cannot be used for accessing annotations).

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: How to access ontology annotations

Jade
Thank you for this information, Jiba.

Unfortunately I am not able to iterate through an onto.metadata() or onto.metadata object.

E.g. when I try this:

"for  data in onto.metadata:"  (I first used "onto = get_ontology(owl_file_path).load()")

I get the error:

"builtins.TypeError: 'Metadata' object is not iterable"

I need to be able to access the ontology's metadata without knowing what it includes and then be able to write extra information back to each metadata object.

Is there an iterable object for accessing ontology metadata using owlready2?

Many thanks!
Jade Hotchkiss
Reply | Threaded
Open this post in threaded view
|

Re: How to access ontology annotations

Jiba
Administrator
Hi,

Currently, it is not possible to obtain the list of annotations... I've added that support in the development version of Owlready. In that version, you can now use onto.metadata as you did to obtain a list of annotation property, e.g.:

for annot in onto.metadata:
    print(annot[onto])


As a workaround, in the current stable version, you can use instead:

for annot in [onto._to_python(p) for p in onto.world._get_triples_s_p(onto.storid) if p != rdf_type]:


Jiba
Reply | Threaded
Open this post in threaded view
|

Re: How to access ontology annotations

Jiba
Administrator
Sorry, it should be:

for annot in onto.metadata:
    print(annot[onto.metadata])

Jiba