Adding a function to a class in an imported ontology

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

Adding a function to a class in an imported ontology

Micheal
If class X that exists within my imported ontology Z.

How can I modify X by adding a new function, e.g. how do I do the same like below if Drug is from an import ontology,

...     class Drug(Thing):
...         def get_per_tablet_cost(self):
...             return self.cost / self.number_of_tablets

thanks
Reply | Threaded
Open this post in threaded view
|

Re: Adding a function to a class in an imported ontology

Jiba
Administrator
Hi,

You can do it using the same way:

with Z:
    class X(Thing):
        def my_function(self): ...

If a class already exists, Owlready does not create a new one but extend the former definition. Here, it will add the function to it.

Notice that, since the previous class is extended, you do not need to mention its superclasses (hence I simply used Thing as parent above).

Jiba