Getting Annotations of an Annotation (Sub-Annotations)

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

Getting Annotations of an Annotation (Sub-Annotations)

Clair Kronk
Hello!

I've been working on an application which uses Owlready2 (which has been amazing by the way!), but I have some annotations that have annotations themselves which I am not sure how to get programmatically?

For instance, if I have a "hasSynonym" annotation of an entry and the "hasSynonym" annotation has an annotation "comment" how would I get that comment?

Thanks so much!
Reply | Threaded
Open this post in threaded view
|

Re: Getting Annotations of an Annotation (Sub-Annotations)

Jiba
Administrator
Hi,

You can access annotations on property values (including other annotation) with the Annotation[subject, property, value] syntax.

Here is an example:


from owlready2 import *

onto = get_ontology("http://test.org/t.owl")

with onto:
  class Term(Thing): pass
  class synonym(AnnotationProperty): pass
 
  t = Term("headacke")
  t.synonym = ["cephalgia"]

  comment[t, synonym, "cephalgia"] = ["A comment about this synonym"]


Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Getting Annotations of an Annotation (Sub-Annotations)

Clair Kronk
Hi!

So I'm a bit confused about this.

For instance, I have an entity that I get as follows:

onto = load_ontology(local_ontology_file)
entity = onto.search_one(iri="http://semanticscience.org/resource/SIO_000015")

This entity has a related synonym called "information artifact", I can get this by running:

print(entity.hasRelatedSynonym)

Which returns:

['information artifact']

"information artifact" has an annotation called alternate name with the string "information artifacts". So I try to pattern off of what you indicated:

with onto:
  class hasRelatedSynonym(AnnotationProperty): pass
  class alternateName(AnnotationProperty): pass

  print(alternateName[entity, hasRelatedSynonym, "information artifact"])

But this gives me an empty array?

Thanks so much for your help so far!
Reply | Threaded
Open this post in threaded view
|

Re: Getting Annotations of an Annotation (Sub-Annotations)

Jiba
Administrator
Hi,

If the annotation classes already exist in your ontology file, do not recreate them (otherwise, Owlready will use the second annotation, which has no relation).

I think you can just use:

print(onto.alternateName[entity, hasRelatedSynonym, "information artifact"])

(you may need to find the exact name and namespace for onto.alternateName, depending on its IRI).

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Getting Annotations of an Annotation (Sub-Annotations)

Clair Kronk
I think this is closer but still not working:/

I'm getting the error that 'hasRelatedSynonym' is not defined when I run:

print(onto.alternateName[entity, hasRelatedSynonym, "information artifact"])

I tried this as well:

print(onto.alternateName[entity, onto.hasRelatedSynonym, 'information artifact'])

Which gives a 'NoneType' object is not subscriptable error.
Reply | Threaded
Open this post in threaded view
|

Re: Getting Annotations of an Annotation (Sub-Annotations)

Jiba
Administrator
I think onto.hasRelatedSynonym is Ok, but the problem is in onto.alternateName.

If you have difficulties to access it, maybe the easier way would be to use its full IRI, e.g. :

alternateName = IRIS["http://.../alternateName"] # put the full IRI here

and then :

print(alternateName[entity, onto.hasRelatedSynonym, "information artifact"])

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Getting Annotations of an Annotation (Sub-Annotations)

Clair Kronk
Unfortunately still no, but I got it by modifying what you sent!

I ran:

onto = load_ontology(local_gsso_file)
entity = onto.search_one(iri="http://semanticscience.org/resource/SIO_000015")
alternateName = IRIS['https://schema.org/alternateName']
print(alternateName[entity, hasRelatedSynonym, 'information artifact'])

And still get a "name 'hasRelatedSynonym' is not defined".

So then I ran:

onto = load_ontology(local_gsso_file)
alternateName = IRIS['https://schema.org/alternateName']
hasRelatedSynonym = IRIS['http://www.geneontology.org/formats/oboInOwl#hasRelatedSynonym']
print(alternateName[entity, hasRelatedSynonym, 'information artifact'])

And it correctly prints 'information artifact'!
Reply | Threaded
Open this post in threaded view
|

Re: Getting Annotations of an Annotation (Sub-Annotations)

Clair Kronk
So while this system works... It is fairly slow, especially if I'm trying to gather all the sub-annotations of all of the annotations (taking around ~5-10 minutes to run). Would you happen to know if there's any faster way of getting sub-annotations?

Thanks so much!
Reply | Threaded
Open this post in threaded view
|

Re: Getting Annotations of an Annotation (Sub-Annotations)

Jiba
Administrator
Hi,

Which version of Owlready are you using? The acces to annotations have been optimized in version 0.21, but previous versions were much slower.

For an even faster access, you may access the RDF triples directly, but it is also much more complex.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Getting Annotations of an Annotation (Sub-Annotations)

Clair Kronk
I'm using version 0.18 (I didn't specify a version when I pip installed a month or so ago).

If I update, should the same syntax function the same way or is there a different syntax that was switched to?

(Thank you so much and apologies for all of the questions!)
Reply | Threaded
Open this post in threaded view
|

Re: Getting Annotations of an Annotation (Sub-Annotations)

Jiba
Administrator
The syntax remains the same.

Jiba