owlready2: create FunctionalProperty to multiple classes

52 views Asked by At

I need a FunctionalProperty to classes like this in Python using owlready2:


    class student(Thing):
        pass

    class teacher(Thing):
        pass

and so on, I have six of them.

I found a similar question here and the solution was this:

class has_color(ObjectProperty):
       domain = [Or([Car,Bike,House])]
       range = [Color]

or

domain = [Car | Bike | House]

But I have five classes and I get this error message:

Exception has occurred: TypeError LogicalClassConstruct.init() takes from 2 to 4 positional arguments but 6 were given

To reproduce it, just create six class and run this:

    class has_value(FunctionalProperty):
        domain = [
            Or(myclass1, myclass2, myclass3, myclass4, myclass5, myclass6)
        ]
        range = [float]
1

There are 1 answers

0
CerebralFart On BEST ANSWER

I'm not too familiar with the owlready2 library, but it seems you've missed some brackets from the example. The example defines the domain as

Or([Car,Bike,House])

So your domain should be written as

Or([myclass1, myclass2, myclass3, myclass4, myclass5, myclass6])

Note the square brackets around the class list.