Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add natural language support #10

Open
miraculixx opened this issue Nov 20, 2014 · 0 comments
Open

Add natural language support #10

miraculixx opened this issue Nov 20, 2014 · 0 comments

Comments

@miraculixx
Copy link
Owner

Implement rules.NaturalLanguageRule

Expected behaviour:

  1. Parse a text string that has a rule in it in natural language (similar to a TableRuleset, but without the structure given in a dictionary)
  2. Create a TableRuleset

Sample code to parse text

# 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', '']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant