manfred-kaiser / business-rule-engine

Python DSL for setting up business intelligence rules
GNU General Public License v3.0
69 stars 21 forks source link

Rules evaluation error in when clause #14

Closed ailton-moreira closed 3 years ago

ailton-moreira commented 3 years ago

I have param that is a string e.g params = { 'text': 'Hello World'}

My rules is: rules = """ rule "Say Hello" when text == 'Hello World' then runHelloFunction() end
""" But, when I try to run it gives me an error FormulaError: ('Not a valid formula:\n%s', "=text = 'Hello World'").

How can I compare strings there?

manfred-kaiser commented 3 years ago

The rule engine is using MS Excel like formulas. To compare a string in Excel, only one = is used.

from business_rule_engine import RuleParser

def runHelloFunction():
   print("this is from runHelloFunction")
   return True

params = { 'text': 'Hello World'}

rules = """
rule "print hello world"
when
    text = "Hello World"
then
    runHelloFunction()
end
"""

parser = RuleParser()
parser.register_function(runHelloFunction)
parser.register_function(print)
parser.parsestr(rules)
parser.execute(params)
ailton-moreira commented 3 years ago

@manfred-kaiser thank you :) it works