building an english based rules engine
DESCRIPTION
TRANSCRIPT
Building an English-based Rules Engine Using .NET and IronRuby
@KeithElder
Director, Software Engineering @ Quicken Loansor
Aka: Professional Emailer and Typer
Quicken Loans
WHAT AMAZES YOU?
ARE RULE ENGINES AMAZING?
What We’ll Be Doing Today
RUBY C#
If answer to question 2 is Very Satisfied and client is a repeat client then send them a discount coupon in the mail.Cylinde
r
A business rules engine is a software system that executes one or more business rules in a runtime production environment. It enables these company policies and other operational decisions to be defined, tested, executed and maintained separately from application code.
A deterministic rule engine may forgo both forward chaining and backward chaining, and instead utilize Domain-specific language approaches to better describe policy. This approach is often easier to implement and maintain, and provides performance advantages over forward or backward chaining systems.
Real World Example
You know what would be amazing? If I could create a way for someone in Marketing to enter rules just like above.
DEMO
What This Is Not
• Natural language processing• Machine learning
What It Is
• Ignoring the ceremony of the English language and taking only the parts we care about
• Pattern matching• Mapping the text to Code
HOW DOES IT WORK?
First – Identify Connectors
If answer to question 2 is Very Satisfied and client is a repeat client then send them a discount coupon in the mail.
CONNECTORS
Easier to Process
If answer to question 2 is Very Satisfied And client is a repeat client Then send them a discount coupon in the mail.CONNECTORS
If Statement
If answer to question 2 is Very Satisfied
Need a method that returns a bool and takes two parameters
bool AnswerToQuestion(int num, string ans)
If answer to question (\d+) is (.+)
And Statement
And client is a repeat client
Need a method that returns a bool with no parameters
bool ClientIsARepeatClient()
Then Statement
Then send them a discount coupon in the mail
Need a method that returns void with no parameters
void SendDiscountCoupon()
From English To Code
if AnswerToQuestion(2, “Yes”) && ClientIsARepeatClient() { SendDiscountCoupon() ;}
If answer to question 2 is Very Satisfied and client is a repeat client then send them a discount coupon in the mail.
Now We Have Our Mapping
[If(@"answer to question (\d+) is (.+)")] bool AnswerToQuestion(params string[] args)
[And(@"client is a repeat client")] bool ClientIsARepeatClient()
[Then(@"send them a discount coupon in the mail")] void SendDiscountCoupon()
If answer to question 2 is Very Satisfied And client is a repeat client Then send them a discount coupon in the mail.
We Created A RuleSetclass public SurveyRuleSet{
[If(@"answer to question (\d+) is (.+)")] public bool AnswerToQuestion(params string[] args) {}
[And(@"client is a repeat client")] public bool ClientIsARepeatClient() {}
[Then(@"send them a discount coupon in the mail")] public void SendDiscountCoupon() {}
}
SERIOUSLY DUDE WHERE’S THE RUBY, THAT’S THE ONLY REASON I’M HERE
CONVERTING ENGLISH TO RUBY
What Do We Know?
• Statements• Which functions those statements
map to
DEMO
Cool Features
• Support for variances in the language
• Could support any language, it’s just text after all
• Allows us to define our own DSL
DEMO – RULES FOR THE SOUTH, OTHER LANGUAGES AND LANGUAGE VARIANCES
Building an English-based Rules Engine Using .NET and IronRuby
@KeithElder
Director, Software Engineering @ Quicken Loansor
Aka: Professional Emailer and Typer