building an english based rules engine
DESCRIPTION
TRANSCRIPT
![Page 1: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/1.jpg)
Building an English-based Rules Engine Using .NET and IronRuby
@KeithElder
Director, Software Engineering @ Quicken Loansor
Aka: Professional Emailer and Typer
![Page 2: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/2.jpg)
Quicken Loans
![Page 3: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/3.jpg)
![Page 4: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/4.jpg)
WHAT AMAZES YOU?
![Page 5: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/5.jpg)
![Page 6: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/6.jpg)
ARE RULE ENGINES AMAZING?
![Page 7: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/7.jpg)
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
![Page 8: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/8.jpg)
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.
![Page 9: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/9.jpg)
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.
![Page 10: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/10.jpg)
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.
![Page 11: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/11.jpg)
DEMO
![Page 12: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/12.jpg)
What This Is Not
• Natural language processing• Machine learning
![Page 13: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/13.jpg)
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
![Page 14: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/14.jpg)
HOW DOES IT WORK?
![Page 15: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/15.jpg)
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
![Page 16: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/16.jpg)
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
![Page 17: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/17.jpg)
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 (.+)
![Page 18: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/18.jpg)
And Statement
And client is a repeat client
Need a method that returns a bool with no parameters
bool ClientIsARepeatClient()
![Page 19: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/19.jpg)
Then Statement
Then send them a discount coupon in the mail
Need a method that returns void with no parameters
void SendDiscountCoupon()
![Page 20: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/20.jpg)
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.
![Page 21: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/21.jpg)
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.
![Page 22: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/22.jpg)
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() {}
}
![Page 23: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/23.jpg)
SERIOUSLY DUDE WHERE’S THE RUBY, THAT’S THE ONLY REASON I’M HERE
![Page 24: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/24.jpg)
CONVERTING ENGLISH TO RUBY
![Page 25: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/25.jpg)
What Do We Know?
• Statements• Which functions those statements
map to
![Page 26: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/26.jpg)
DEMO
![Page 27: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/27.jpg)
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
![Page 28: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/28.jpg)
DEMO – RULES FOR THE SOUTH, OTHER LANGUAGES AND LANGUAGE VARIANCES
![Page 29: Building an english based rules engine](https://reader036.vdocuments.site/reader036/viewer/2022081413/5479c04db379595e2b8b47f5/html5/thumbnails/29.jpg)
Building an English-based Rules Engine Using .NET and IronRuby
@KeithElder
Director, Software Engineering @ Quicken Loansor
Aka: Professional Emailer and Typer