Individuals data properties modifications not saving when individuals have different namespace than class
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:
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.
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: