Data property work around

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

Data property work around

azihsan
Hi,

I encounter the problem of assignning the data property of an individual.

this seems work to me

from owlready2 import * 
import types

onto = get_ontology('https://text.org/test/')

with onto: 
    cls = types.new_class('NewClass', (Thing, ))
    data_prop = types.new_class('NewDataProp', (DataProperty, ))
    data_prop.range = [int]
    individual = cls('new-individual')

    individual.NewDataProp.append(20)

But actually i need to something like this
from owlready2 import * 
import types

onto = get_ontology('https://text.org/test/')

with onto: 
    cls = types.new_class('NewClass', (Thing, ))
    data_prop = types.new_class('NewDataProp', (DataProperty, ))
    data_prop.range = [int]
    individual = cls('new-individual')

    individual.data_prop.append(20)

i need to dynamically assign the data property of individual according to object of types.new_class(), is there any way to do that?
Reply | Threaded
Open this post in threaded view
|

Re: Data property work around

Jiba
Administrator
Hi,

You can the following alternate syntax:

data_prop[individual].append(20)


You may also use the Python getattr() function (but it is quite more complex):

getattr(individual, data_prop.name).append(20)

Jiba