Posted by
felix on
URL: http://owlready.306.s1.nabble.com/Mixing-Python-OWL-SWRL-and-Reasoning-tp2653p2654.html
Hi Carsten,
just my 2 cents, I might be wrong here tho:
a rule is specified using a string of a valid SWRL rule. i.e., it is not possible to evaluate a python function within the SWRL rule, simply because the reasoner is unable to do so.
in your example, what you intended to be a function call "get_per_tablet_cost" is interpreted as an entity, which cannot be found within the ontology
instead, you could use two separate SWRL rules. as a nice side effect, this also increases cohesion:
1. Insert costs per tablet into the ontology, see
https://owlready2.readthedocs.io/en/latest/rule.html: 'Drug(?d), price(?d, ?p), number_of_tablets(?d, ?n), divide(?r, ?p, ?n) -> price_per_tablet(?d, ?r)'
2. Classification regarding the class "ExpensiveDrug" depending on the price: 'Drug(?d), price_per_tablet(?d, ?p), greaterThanOrEqual(?p, 10) -> ExpensiveDrug(?d)'
if there is a large number of rules, it may make sense to generate the SWRL strings using python functions defined within the respective classes. for this, mixing python and owl will probably come in real handy
Best,
Felix