SWRL Rules in Owlready throwing AttributeError

Posted by nas on
URL: http://owlready.306.s1.nabble.com/SWRL-Rules-in-Owlready-throwing-AttributeError-tp2019.html

Hello,

Hope everyone is doing well. I am working on a project and I am trying to implement some SWRL rules. I followed the documentation and wrote the following:

rule1 = Imp()
rule1.set_as_rule("MathModel(?m), Current(?m, ?c), Voltage(?m, ?v), multiply(?r, ?c, ?v) -> PowerElectrical(?m, ?r)")

but whenever I try to run it, it throws this error:

Traceback (most recent call last):
  File "ontologystuff.py", line 83, in <module>
    rule1.set_as_rule("MathModel(?m), Current(?m, ?c), Voltage(?m, ?v), multiply(?r, ?c, ?v) -> PowerElectrical(?m, ?r)")
  File "/Users/nasirsharaf/anaconda3/lib/python3.6/site-packages/owlready2/rule.py", line 146, in set_as_rule
    atom.arguments = arguments
AttributeError: 'str' object has no attribute 'arguments'

At one point, I tried this instead:

rule1 = Imp()
rule1.set_as_rule("MathModel(?m), Current(?m, ?c), Voltage(?m, ?v), multiply(?r, ?c, ?v) -> PowerElectrical(?m, ?r)", [])

but then it said that it could not find MathModel even though I made the class in the line right above it:

Traceback (most recent call last):
  File "ontologystuff.py", line 83, in <module>
    rule1.set_as_rule("MathModel(?m), Current(?m, ?c), Voltage(?m, ?v), multiply(?r, ?c, ?v) -> PowerElectrical(?m, ?r)",[])
  File "/Users/nasirsharaf/anaconda3/lib/python3.6/site-packages/owlready2/rule.py", line 135, in set_as_rule
    entity = _find_entity(atom, namespaces)
  File "/Users/nasirsharaf/anaconda3/lib/python3.6/site-packages/owlready2/rule.py", line 173, in _find_entity
    raise ValueError("Cannot find entity '%s'!" % name)
ValueError: Cannot find entity 'MathModel'!

Can anyone help me? I would greatly appreciate it