Re: How to create Object and Data Properties dynamically ?

Posted by rahul_raj on
URL: http://owlready.306.s1.nabble.com/How-to-create-Object-and-Data-Properties-dynamically-tp244p371.html

Hello Jiba,
I needed to create data properties dynamically for my project. So, following this thread, I tried to implement it in the way Driss has done it. I have a list of strings where each string is a data property name.
s = ["has_PropertA", "has_PropertyB", "has_PropertyC"]

Now, I wish to create these data properties dynamically.

for i in range(len(s)):
    with onto:
        ontology_data_property = types.new_class(s[i],  (DataProperty))

But this throws an error - AttributeError: 'int' object has no attribute 'DataProperty'
I thought changing 'ontology' in the last line to the name of ontology might help. i.e.,
for i in range(len(s)):
    with onto:
        onto_data_property = types.new_class(s[i],  (DataProperty))

But this also gives the same error as above case.

Kindly put forward your views on this error and suggest a way out of this problem so as to fulfill my intended objective. I would be glad!