defining equivalency class using data properties

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

defining equivalency class using data properties

jritch33
Love owlready2 with python! I am building a classifier that requires me to incorporate DataProperties into my equivalency classes. I can make it happen in protege but I want to define my equivalency classes in python. I will use your example from the docs to highlight exactly what I am trying to accomplish.  

#  example from the docs
class NonVegetarianPizza(onto.Pizza):
... equivalent_to = [
... onto.Pizza
... & ( onto.has_topping.some(onto.MeatTopping)
... | onto.has_topping.some(onto.FishTopping)
... ) ]

Let's say I want to include count of 'calories' for a new classification HighCalorieNonVegetarianPizza.

# modified example from the docs
class HighCalorieNonVegetarianPizza(onto.Pizza):
... equivalent_to = [
... onto.Pizza
... & ( onto.has_topping.some(onto.MeatTopping)
... | onto.has_topping.some(onto.FishTopping)
... )
... & (onto.has_calorie_count.some(int > 400)]

I can't seem to figure out the syntax for the bold line in the modified example (onto.has_calorie_count.some(int > 400)). I assume this is possible but that might be a mistake. If so, would you please suggest the best way to accomplish this in python?

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

Re: defining equivalency class using data properties

Jiba
Administrator
Hi,

Thank you for your compliments :)

To use dataproperties in constraints, you must use a ConstrainedDatatype, as follows:

   onto.has_calorie_count.some(ConstrainedDatatype(int, min_exclusive = 400))

Owlready also has a simplified syntax (equivalent to the above):

   onto.has_calorie_count > 400

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

Re: defining equivalency class using data properties

jritch33
Thanks for responding so quickly! I was able to get the first way to work:

onto.has_calorie_count.some(ConstrainedDatatype(int, min_exclusive = 400))

but the simplified syntax:

onto.has_calorie_count > 400

Raises TypeError: '<=' not supported between instances of 'And' and 'int'

Not a huge issue and it's quite possible I just misunderstood something but thought it was worth sharing.

Thanks again for your help!
Reply | Threaded
Open this post in threaded view
|

Re: defining equivalency class using data properties

Jiba
Administrator
Hi,

I think you need parentheses, because & has priority over > in Python.

For example :

    onto.Pizza & has_calorie_count.some > 400

should be written :

    onto.Pizza & (has_calorie_count.some > 400)

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

Re: defining equivalency class using data properties

jritch33
Yup! That was it! Thanks so much!