Hi Jiba,
Thanks for the reply. First of all I must say that I don't have much experience to these stuff. I tried your suggestion but encountered an error.
I have mentioned below the code I have used and the Error message.
myonto=get_ontology("file:///home/sharada/main/test_Template.owl").load()
def createDatProp(a):
myonto=get_ontology("file:///home/sharada/main/test_Template.owl").load()
with myonto:
datProp=types.new_class(a, (DataProperty,))
createDatProp("TestDataProp_1")
createDatProp("TestDataProp_2")
individ=getattr(myonto,"SPJ")
setattr(individ,"TestDataProp_2","Test")
Error Message
setattr(individ,"TestDataProp_2","Test")
File "/home/sharada/.local/lib/python3.6/site-packages/owlready2/individual.py", line 295, in __setattr__
raise ValueError("Property '%s' is not functional, cannot assign directly (use .append() or assign a list)." % attr)
ValueError: Property 'TestDataProp_2' is not functional, cannot assign directly (use .append() or assign a list).
Really appreciate if you could help to counter this error.
Thank you.
On Thu, Aug 8, 2019 at 6:14 PM Jiba [via Owlready] <
[hidden email]> wrote:
Hi,
I think you need the getattr() / setattr() Python functions. These functions can get or set a property from a string containing the property name, e.g.
individual_name = "your_name"
individual = getattr(onto, individual_name)
prop_name = prop.python_name # If you have the property as object and not as a name
setattr(individual, prop_name, new_value)
Jiba
To unsubscribe from How to dynamically create a relation,
click here.
NAML