Access restrictions

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

Access restrictions

VasilisBouzas
Hello,

I would like to ask how you access properties of different restrictions for a specific class. If class "parent" has a property "has Children" you can access it like so:
parent.hasChildren
but only if the restriction is "some". What about an "only" restriction?

Kind regards,
Vasilis
Reply | Threaded
Open this post in threaded view
|

Re: Access restrictions

Jiba
Administrator
Hello,

You can access to all restriction in the is_a attribute, as Restriction object. Then you have to filter to retain only Restriction, and only those of the ONLY type.

Alternatively, if you are only interested in ONLY restrictions but not in SOME restrictions, you can change the behavior of Owlready so as Class.property returns ONLY restrictions instead of SOME.

This can be done by setting the special "class_property_type" annotation on the property, as follows:

my_prop.class_property_type = ["only"]

Jiba