Re: SWRL Rules in Owlready throwing AttributeError
Posted by
Jiba on
URL: http://owlready.306.s1.nabble.com/SWRL-Rules-in-Owlready-throwing-AttributeError-tp2019p2037.html
Hi,
I think the problem is in the definition of your class and/or your properties. The second argument of set_as_rule() is the list of namespaces (or ontologies) where entities are searched. If you pass an empty list, no ontologies are searched and thus the class and properties cannot be found.
Here is a way to implement your ontology:
from owlready2 import *
onto = get_ontology("
http://test.org/t.owl")
with onto:
class MathModel(Thing): pass
class Current(Thing >> float, FunctionalProperty): pass
class Voltage(Thing >> float, FunctionalProperty): pass
class PowerElectrical(Thing >> float, FunctionalProperty): pass
m = MathModel(Current = 2.0, Voltage = 3.0)
rule1 = Imp()
rule1.set_as_rule("MathModel(?m), Current(?m, ?c), Voltage(?m, ?v), multiply(?r, ?c, ?v) -> PowerElectrical(?m, ?r)")
onto.save("/tmp/t.owl")
sync_reasoner_pellet(infer_property_values = True, infer_data_property_values = True)
print(m.PowerElectrical)
Jiba