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.
dp = types.new_class("hasSomething", (DataProperty,))
# 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
You can use "dp.EditorAnnotation" to get or set the annotation values.
Here is an example:
onto = get_ontology("http://test.org/t.owl")
class Clazz(Thing): pass
class hasSomething(Clazz >> str): pass
class EditorAnnotation(AnnotationProperty): pass
class EditorPrivateComment(EditorAnnotation): pass
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
In my current program I have managed the following:
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?