dynamic annotation hierarchy example please

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

dynamic annotation hierarchy example please

synsem950
Hello,
I am trying to create an annotation hierarchy dynamically and assign the annotationproperties to
classes and properties.Ex
I have an EditorAnnotation with a subannotation EditorPrivateComment with a value "I think this requires more thought"
I would now like to assign this and other annotations to for example a dataproperty and of course
retrieve the annotation for the data property and I cannot figure out how to program this.
Ex.
with onto:
     dp = types.new_class("hasSomething", (DataProperty,))
     dp.domain=Clazz
     dp.range="xsd:string"
     # Now annotation
     EA = types.new_class("EditorAnnotation", (AnnotationProperty,))
     ?? How do I set the value dynamically of the annotation
     ?? and attach it to dp
     ?? How do I retrieve the annotation from dp?
     ?? There will be many EditorAnnotations with different values
     ?? so like dp[EditorAnnotation]=value
     ?? How do I do that?
     ?? Example of creating a subannotation dynamically


Thanks in advance
Reply | Threaded
Open this post in threaded view
|

Re: dynamic annotation hierarchy example please

Jiba
Administrator
Hello,

You can use "dp.EditorAnnotation" to get or set the annotation values.

Here is an example:


onto = get_ontology("http://test.org/t.owl")
with onto:
  class Clazz(Thing): pass
  class hasSomething(Clazz >> str): pass
  class EditorAnnotation(AnnotationProperty): pass
  class EditorPrivateComment(EditorAnnotation): pass

  hasSomething.EditorAnnotation = ["annotation value"]

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: dynamic annotation hierarchy example please

synsem950
Hi Jiba and thanks for the quick reply.

From what I see in the forum I think I am not the only one having this problem
that the examples given are hardcoded.
Many of us work with generic problems and code generation and cannot afford
to program like the examples and it becomes very frustrating to know things can
be done but struggling to find out how.
It would greatly improve the documentation and usability of the excellent software
if for every "hardcoded" example in parallel there was an "dynamic" equivalent.

So for the given example with the names of the classes,properties and annotations
being strings.

In my current program I have managed the following:

clazz="mySubClass"
superClazz=Thing
subClazz=types.new_class(clazz,(superClazz))
setattr(subClazz,"editor_comment","I think...")

Using setattr I get the annotation as xsd:string to show up in protege as
editor_comment with a value of " I think...."
as desired. However, I don't understand why. How can Owlready know it is an annotation?
It is not quite what I want. I want the annotations to have a structure so that I can retrieve
only annotations of a certain class.

So once I have created the editor_annotation property with types.new
how can I associate it with a class or property and set the annotation
value for the class or property?

Kind regards,





Reply | Threaded
Open this post in threaded view
|

Re: dynamic annotation hierarchy example please

Jiba
Administrator
Hi,

> How can Owlready know it is an annotation?

Owlready use the name of the attribute to find the corresponding property. As it is an AnnotationProperty, Owlready creates an annotation.

> So once I have created the editor_annotation property with types.new how can I associate it with a class or property and set the annotation value for the class or property?

Just as previously :

setattr(subClazz,"editor_annotation","I think...")

Jiba