Assigning data and object properties to newly created individuals

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

Assigning data and object properties to newly created individuals

evgenia
Hi Jiba!

I have an already existing ontology to which I would like to add new individuals, however, they also come with both data and object properties. How can I assign them to the new instances?
For a better understanding, I will give you an example: as in input I have a dictionary which contains all the information about the new individual, something like
newlicense = {'id': 'BlaBla', 'url': 'www.google.com', 'type': 'Public Domain'}, where url is a data property and type is an object property. I create an individual the following way: SoftwareLicense(newlicense['id']). However, the assgniment of properties fails with setattr (GIVES NO ERROR MESSAGE, BUT WHILE CALLING THE PROPERTY DOESN'T RETURN ANYTHING), which I assume is the proper way of doing it. Are there any options to do it?

Best
Evgenia
Reply | Threaded
Open this post in threaded view
|

Re: Assigning data and object properties to newly created individuals

Jiba
Administrator
Hi,

To set the property values, you can do:

sl = SoftwareLicense(newlicense['id'])
sl.url = newlicense["url"] # if the url property is functional
sl.url.append(newlicense["url"]) # if the url property is NOT functional

or :

setattr(sl, "url", newlicense["url"]) # if the url property is functional
getattr(sl, "url").append(newlicense["url"]) # if the url property is NOT functional

or :

onto.url[sl].append(newlicense["url"]) # same syntax whether if the url property is functional or not

You should also ensure that the url property exists.

Jiba