Annotations not being saved

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

Annotations not being saved

gbaesso
Bonjour Mr. Lamy,

I was already able to create the full structure of my ontology from scratch entirely using owlready, and even import the converted data! It saved me hours of work... Incredible tool!

One thing I was not able to do was write the rdfs:comment (on the Data Properties).

I have tryied both:  

Drug.comment = ["A first comment on the Drug class", "A second comment"]
Drug.comment.append("A third comment")

(actually I had to use onto.Drug.comment, otherwise it returns that 'name is not defined'. This happens with most of the examples in the documentation)

And then "onto.save()". But the comment is never really saved to the OWL file...

I also noted that any attribute I try to assign a value works, and the value is kept in memory:

onto.Drug.comment = 'comment'
onto.Drug.anything = 'I can use any attribute'
print(onto.Drug.anything) actually returns the value

So I have a feeling that .comment is not going anywhere... What am I doing wrong this time?  :)

Salutations,
Guilherme




Reply | Threaded
Open this post in threaded view
|

Re: Annotations not being saved

gbaesso
I just found out myself one thing I was doing wrong: I forgot to add the main class on the dot notation: "onto.mainclass.mydataproperty" (my data property has the mainclass in the first segment of its name, and that caused me the mistake).

But that raised another problem:

When I try...

onto.mainclass.mydataproperty.comment = ['something']

it complaints that...

AttributeError: 'comment' is not a language code (must be 2-char string)!


I have faced it when I was creating my data loading module, and managed to handle it. I had to use...

getattr(obj, attrib).en = data


And it worked well! But the 'comment' property (on my data properties) did not. I can try....

onto.mainclass.mydataproperty.comment.en = ['something']

But it still says...

AttributeError: 'comment' is not a language code (must be 2-char string)!

Reply | Threaded
Open this post in threaded view
|

Re: Annotations not being saved

Jiba
Administrator
Hello,

I don't understand on what you are adding an annotation.

For annotating a class, the syntax is :

        onto.className.comment = "Your comment"

For annotating a property, the syntax is :

        onto.propertyName.comment = "Your comment"

For annotating a relation triple, for example on the triple (individual, property, value), you cannot use the 'dot' syntax. The syntax is :

        comment[onto.individual, onto.property, value] = "Your comment"


In OWL, a class cannot have property value. Owlready accept "class attributes" (e.g. onto.className.propertyName = ...) and actually transforms them automatically in OWL restrictions (this is an advanced feature that I still need to document). I think that the restriction cannot be annotated (Protégé does not allow that). However, you can annotate the subclass-of relation between the class and the restriction.

Subclass-of relations can be annotated using the same syntax than above for relations:

        comment[onto.className, rdfs_subclassof, superclass] = "Your comment"

The difficulty is to find the appropriate restriction superclass. Just after doing onto.className.propertyName = ..., the restriction is added at the end of onto.className.is_a, so you can do it as follows:

        comment[onto.className, rdfs_subclassof, onto.className.is_a[-1]] = "Your comment"

Best regards,
Jean-Baptiste Lamy
MCF, LIMICS, Université Paris 13

> I just found out myself what was wrong, I forgot to add the main class on the
> dot notation: "onto.mainclass.mydataproperty" (my data property has the
> mainclass in the first segment of its name, what caused me the confusion).
>
> But that raised another problem:
>
> When I try...
> onto.mainclass.mydataproperty.comment = ['something']
>
> it complaints that...
> AttributeError: 'comment' is not a language code (must be 2-char string)!
>
>
> I have faced it when I was creating my data loading module, and managed to
> handle it. I had to use...
> getattr(obj, attrib).en = data
>
>
> And it worked well! But the 'comment' property (on my data properties) did
> not. I can try....
> onto.mainclass.mydataproperty.comment.en = ['something']
>
> But it still says...
> AttributeError: 'comment' is not a language code (must be 2-char string)!
>
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://owlready.8326.n8.nabble.com/Annotations-not-being-saved-tp62p63.html
> To start a new topic under Owlready, email [hidden email]
> To unsubscribe from Owlready, visit
Reply | Threaded
Open this post in threaded view
|

Re: Annotations not being saved

gbaesso
Bonjour Mr. Lamy,

I am trying to annotate a property (Protégé calls it Data Property) using:

   onto.propertyName.comment = "Your comment"

But it says:

   AttributeError: 'comment' is not a language code (must be 2-char string)!
Reply | Threaded
Open this post in threaded view
|

Re: Annotations not being saved

gbaesso
This post was updated on .
Sorry, it worked with:

   onto.propertyName.comment.en = "Your comment"

(I was probably too sleepy last work night)

It also works dinamically with:

   getattr(onto, prop_name).comment.en = data


Merci!

Salutations,
Guilherme Baesso
Reply | Threaded
Open this post in threaded view
|

Re: Annotations not being saved

Jiba
Administrator
OK, it's more clear to me now.

You are right, onto.propertyName.comment does not work while onto.className.comment works... I'm going to investigate the problem.


Kind regards,
Jean-Baptiste Lamy
MCF, LIMICS, Université Paris 13

> Sorry, it worked with:
>
>    onto.propertyName.comment.en = "Your comment"
>
> Probably I was too sleepy last work night....
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://owlready.8326.n8.nabble.com/Annotations-not-being-saved-tp62p66.html
> To start a new topic under Owlready, email [hidden email]
> To unsubscribe from Owlready, visit