Dynamic ConstrainedDatatype FunctionalProperty

Posted by DE3000 on
URL: http://owlready.306.s1.nabble.com/Dynamic-ConstrainedDatatype-FunctionalProperty-tp2344.html

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?