Open miraculixx opened 9 years ago
Implement rules.NaturalLanguageRule
rules.NaturalLanguageRule
TableRuleset
# draft parser for natural language rule import re rule_text = re.split('If(.*)Then(.*)', 'If something and something else Then context.target = context.fare * 2, context.target2 = context.fare2 * 5') conditions = rule_text[1] actions = re.split('(.*=.*)[,]+', rule_text[2]) print "split rule", rule_text print "conditions" , conditions print "actions", actions for action in actions[1:]: split_action = re.split('context\.(.*)=(.*)', action) print "target", split_action
outputs this:
split rule ['', ' something and something else ', ' context.target = context.fare * 2, context.target2 = context.fare2 * 5', ''] conditions something and something else actions ['', ' context.target = context.fare * 2', ' context.target2 = context.fare2 * 5'] target [' ', 'target ', ' context.fare * 2', ''] target [' ', 'target2 ', ' context.fare2 * 5', '']
Implement
rules.NaturalLanguageRule
Expected behaviour:
TableRuleset
, but without the structure given in a dictionary)Sample code to parse text
outputs this: