how to add object property values dynamically to a generated class

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

how to add object property values dynamically to a generated class

eyseman
Hi,

I am currently trying to add several object properties to a class, I have generated:

     myclass = onto.SomeClass('some id')

The ontology includes an object property called "includesConcept"
I can add a specific class to "myclass" via the following:

     myclass.includesConcept = [onto.SomeOtherClass()]

This works perfectly fine. However, I would like to add the "onto.SomeOtherClass()" dynamically.
For example:

     conceptToBeIncluded = onto.SomeOtherClass()

     myclass.includesConcept = [conceptToBeIncluded]

or even something like this:

     conceptList= [onto.SomeOtherClassA(), onto.SomeOtherClassB()]

     myclass.includesConcept = [conceptList]

Is there a way to do this?

Thanks!

Best
eyseman


Reply | Threaded
Open this post in threaded view
|

Re: how to add object property values dynamically to a generated class

eyseman
Hi,

I just found the solution. You can directly access classes via
   
    onto["name_of_the_class"]

so I loop through all my classes i would like to add via:

    list_of_classes = ["classA", "classB", "classC"]
    concepts = []

    for item in list_of_classes:
        concepts.append(onto[item]())

and then pass this list to the actual object property

     myclass.includesConcept = concepts


I hope someone can use this :)

Best
eyseman