Define the class of an individual dynamically

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

Define the class of an individual dynamically

William
This post was updated on .
If I have defined two classes A and B (also dynamically), and assert A(i) [in DLs] with i=A() [in Owlready], then if I assert B(i), I have to execute i=B() which will cover i=A(). That is not what I want, I want to assert A(i) and B(i). I tried to use i.is_instance_of.append(B), but got error. It is not convenient to use `A and B` explicitly, since A(i) is also asserted dynamically.

Similarly, I met the same issue when I defined a subclass of two existed classes.

My purpose is to build a man-machine conversation system with owlready . https://github.com/Freakwill/gimbiseo
Reply | Threaded
Open this post in threaded view
|

Re: Define the class of an individual dynamically

Jiba
Administrator
Hi,

To add a second class B to i, you can use the two following syntax:

    i.is_a.append(B)

or:

    B(i)

You may get an error if the resulting instance is not valid in Python (e.g. metaclass conflict), but normally Owlready prevents these problems.

Best regards,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Define the class of an individual dynamically

William
This post was updated on .
Thank you. There was a bug in my program.

I read the article, that said `is_a` is used to define subclasses instead of individuals, while `is_instance_of` dose that.