How to create individuals dynamically

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

How to create individuals dynamically

IWilliams
I have a list of strings. e.g. myList=["tom", "pam", "sam", ]
I would like to load an ontology and dynamically create individuals for a particular class using the strings in myList. How can I achieve this? I am new to Owlready2.

Thanks
gp
Reply | Threaded
Open this post in threaded view
|

Re: How to create individuals dynamically

gp
You may want to check the nice documentation
http://owlready2.readthedocs.io/en/latest/class.html#creating-individuals

something like
classObj = myOnto.search(label="*classLabel")[0] # you may need to pick another element of the list
for ind in myList:
    myInd = classObj(ind)

You can also store myInd somewhere for direct access, like in a dictionary for instance.

Hope this helps!
Reply | Threaded
Open this post in threaded view
|

Re: How to create individuals dynamically

IWilliams
Thank you! I have not tried it yet, but from reading the doc, I strongly believe it will work. I will let you know.
Reply | Threaded
Open this post in threaded view
|

Re: How to create individuals dynamically

Zinat
Hi,

I have tried this procedure. It is not working. is dynamic Individual creation really possible in owlready2?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: How to create individuals dynamically

Jiba
Administrator
Hi,

Yes, it should work as indicated in the previous code.

Could you share at excerpt of our code?

Best regards,
Jiba