Python functions for Thing class

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

Python functions for Thing class

Jordon
Hi Jiba!

I love that I can define python functions on the classes in my ontology. I have a few functions I want all my ontology classes to have access to. Can I define python functions on the Thing class like I can for any other class? And will all the child classes have access to those functions?

Thanks!
Jordon
Reply | Threaded
Open this post in threaded view
|

Re: Python functions for Thing class

Jiba
Administrator
Hi,

That's a good question... I've just tried, and it appears to work.

You can do it as follows (NB the Thing class is defined in the owl pseudo ontology):


from owlready2 import *

onto = get_ontology("http://test.org/test.owl")

with onto:
    class MyClass(Thing): pass

with owl:
    class Thing(Thing):
        def test_func(self, x): print(x)


m = MyClass()
m.test_func("eee")


Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Python functions for Thing class

Jordon
This post was updated on .
Thank you for your reply! This will make things so much nicer. When trying to declare a function on the Thing class I was doing 'with onto' instead of 'with owl', a crucial detail I overlooked.

Much thanks!
Jordon