Dynamic ConstrainedDatatype FunctionalProperty

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

Dynamic ConstrainedDatatype FunctionalProperty

DE3000
I'm trying to create a dynamic ConstrainedDatatype FunctionalProperty. I have a Class that will store a minimum and a maximum value:
class MyValue(Thing): pass
class has_min(DataProperty, FunctionalProperty):
  domain =[MyValue]
  range = [float]
  python_name = "min"
class has_max(DataProperty, FunctionalProperty):
  domain =[MyValue]
  range = [float]
  python_name = "max"
Now I want to create a FunctionalProperty with a ConstrainedDatatype but I am unsure how to go about this.

My attempt so far is to create a SubClass of MyValue:
class CValue(MyValue):
  defined_class = True
  has_max = 100.0
  has_min = 10
class has_value(DataProperty, FunctionalProperty):
  domain =[CValue]
  range = [ConstrainedDatatype(float, min_inclusive = CValue.has_min, max_inclusive = CValue.has_max)]
  python_name = "value"
which does allow me to create individuals with the range 10 <= value <= 100 but I need other individuals with different ranges. Changing indv.min and indv.max after the indv is created obvisouly does not update the ConstrainedDatatype (verified with reasoner). The MyValue class does have other properties but are not relevant for the example.

I know new classes can be created dynamically:
import types
with my_ontology:
  NewClass = types.new_class("NewClassName", (SuperClass,))
but how do you link that with updating the ConstrainedDatatype range in CValue? Do I need to create dynamic properties with dynamic classes or is there an easier way?
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic ConstrainedDatatype FunctionalProperty

Jiba
Administrator
Hi,

When you do:

class has_value(DataProperty, FunctionalProperty):
  domain =[CValue]
  range = [ConstrainedDatatype(float, min_inclusive = CValue.has_min, max_inclusive = CValue.has_max)]

The DataProperty is created with the min_inclusive given at that time; if CValue.has_min change later, it will not be updated.

I'm not sure that what you want to achieve can be done in OWL, because OWL definition corresponds to a single free variable, while you need two here (one for the dataproperty and one for the CValue). Possibly, you should look at SWRL rules, which support several free variables. You may create a rule limiting the range of the float value, by classifying any individual having a non satisfying value as Nothing.

Jiba