Individuals data properties modifications not saving when individuals have different namespace than class

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

Individuals data properties modifications not saving when individuals have different namespace than class

anthonyhombiat
Hi everyone,

I'm using owlready2 for manipulating foaf:Person individuals in my application.
These individuals have a namespace which is specific to my application and hence different from the foaf namespace.
When I try to retrieve a foaf:Person 
person = onto.search_one(type=Person, iri=my_person_iri_with_a_non_foaf_namespace)
I get a None type object. Therefore, I remove the type filter:
person = onto.search_one(iri=my_person_iri_with_a_non_foaf_namespace)
which gives me the individual I'm looking for. Then I change some of its attributes:
person.firstName = "John" [and] person.lastName = "Doe"
Finally, I try to save the ontology
onto.save()
But the changes in attributes values are not persisted.
I noticed that removing the type filter in the search_one() function I end up with an owl:Thing individual.
Therefore, I tried to cast the owl:Thing individual to a foaf:Person with
contributor.__class__ = Person
But here again I can't persist the edited attributes values.

Any idea?

Thanks for your help!

Anthony
Reply | Threaded
Open this post in threaded view
|

Re: Individuals data properties modifications not saving when individuals have different namespace than class

Jiba
Administrator
Hi,

I tried the following example with the latest version of Owlready (NB foaf_example.rdf is the RDF file example found on Wikipedia here : https://fr.wikipedia.org/wiki/FOAF ) :

from owlready2 import *

foaf    = get_ontology("/tmp/foaf.rdf").load()
foaf_ex = get_ontology("/tmp/foaf_example.rdf").load()

person  = onto.search_one(type = foaf.Person, iri = "http://jimmywhales.com/me")
print(person)
print(person.givenName)

person.givenName = ["Newname"]

foaf_ex.save("/tmp/foaf_example2.rdf")


This code runs as expected. Could you verify if it works also for you ?


If you want to use the FOAF "name" property, you will suffer from problem because Owlready use the "name" attribute for the identifier of the individual. You can use FOAF name after renaming it in Python, as follows:

foaf["name"].python_name = "foaf_name"

Jiba