Is there anyone who could help figure out what the double greater-than symbol (i.e. Drug >> float
in line 10 and Drug >> int
in line 13) means in the following python scripts?
1 from owlready2 import *
2
3 onto = get_ontology("http://test.org/onto.owl")
4
5 with onto:
6 class Drug(Thing):
7 def get_per_tablet_cost(self):
8 return self.cost / self.number_of_tablets
9
10 class has_for_cost(Drug >> float, FunctionalProperty):
11 python_name = "cost"
12
13 class has_for_number_of_tablets(Drug >> int, FunctionalProperty):
14 python_name = "number_of_tablets"
15
16 my_drug = Drug(cost = 10.0, number_of_tablets = 5)
17 print(my_drug.get_per_tablet_cost())
--- Below is the printing outcome. ---
2.0
The code is copied from here and runs in python 3.
The >>
symbol here is not bitwise operator. Python's bitwise operation, say x >> y
, requires y
to be an integer. It is clear that the code here (Drug >> float
) is not shifting Drug
right by float
bits.
Although similar questions were asked before (see here and here), their answers mostly pointed to the so-called "print chevron" in python 2, where the >>
redirects the to-be-printed messages to the file-like object specified right after the >>
. They do not apply to my question because here is not a case of print statement.
To trace the >>
in the code above, I revised the script in line 10 as class has_for_cost(Drug >> list, FunctionalProperty)
(namely replace >> float
with >> list
) and ran the code again. It raised an AttributeError as follows:
AttributeError Traceback (most recent call last)
<ipython-input-1-1be374b27b04> in <module>()
8 return self.cost / self.number_of_tablets
9
---> 10 class has_for_cost(Drug >> list, FunctionalProperty):
11 python_name = "cost"
12
~/anaconda3/lib/python3.6/site-packages/owlready2/prop.py in __init__(Prop, name, bases, obj_dict)
254 class ReasoningPropertyClass(PropertyClass):
255 def __init__(Prop, name, bases, obj_dict):
--> 256 super().__init__(name, bases, obj_dict)
257
258 if (not Prop.namespace.world is owl_world):
~/anaconda3/lib/python3.6/site-packages/owlready2/prop.py in __init__(Prop, name, bases, obj_dict)
78
79 if not range is False:
---> 80 Prop.range.extend(range)
81
82 if not inverse_property is False:
~/anaconda3/lib/python3.6/site-packages/owlready2/util.py in extend(self, l)
58 def append(self, x): old = list(self); super().append(x) ; self._callback(self._obj, old)
59 def insert(self, i, x): old = list(self); super().insert(i, x) ; self._callback(self._obj, old)
---> 60 def extend(self, l): old = list(self); super().extend(l) ; self._callback(self._obj, old)
61 def remove(self, x): old = list(self); super().remove(x) ; self._callback(self._obj, old)
62 def __delitem__(self, i): old = list(self); super().__delitem__(i) ; self._callback(self._obj, old)
~/anaconda3/lib/python3.6/site-packages/owlready2/prop.py in _range_changed(Prop, old)
143 for x in new - old:
144 if isinstance(x, ClassConstruct): x._set_ontology(Prop.namespace.ontology)
--> 145 x2 = _universal_datatype_2_abbrev.get(x) or x.storid
146 Prop.namespace.ontology.add_triple(Prop.storid, rdf_range, x2)
147
AttributeError: type object 'list' has no attribute 'storid'
With the traceback info, though, I still could not find the answer. I would be very thankful if anyone could help figure out what the >>
does in the code.