TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
Building an english based rules engine
1. Building an English-based
Rules Engine Using .NET and
IronRuby
@KeithElder
Director, Software Engineering @ Quicken Loans
or
Aka: Professional Emailer and Typer
7. What We’ll Be Doing Today
If answer to question 2 is Very
Satisfied and client is a repeat client
then send them a discount coupon
in the mail.
Cylinder
RUBY C#
8. 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
9. 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
10. 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.
15. 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
16. 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
17. If Statement
If answer to question (d+) is (.+)
2 is Very Satisfied
Need a method that returns a bool and takes two
parameters
bool AnswerToQuestion(int num, string ans)
18. And Statement
And client is a repeat client
Need a method that returns a bool with no
parameters
bool ClientIsARepeatClient()
19. Then Statement
Then send them a discount coupon in the
mail
Need a method that returns void with no
parameters
void SendDiscountCoupon()
20. From English To Code
If answer to question 2 is Very Satisfied and
client is a repeat client then send them a
discount coupon in the mail.
if AnswerToQuestion(2, “Yes”) &&
ClientIsARepeatClient()
{
SendDiscountCoupon() ;
}
21. Now We Have Our Mapping
If answer to question 2 is Very Satisfied
And client is a repeat client
Then send them a discount coupon in the mail.
[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()
22. We Created A RuleSet
class 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() {}
}
27. 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
28. DEMO – RULES FOR THE SOUTH,
OTHER LANGUAGES AND
LANGUAGE VARIANCES
29. Building an English-based
Rules Engine Using .NET and
IronRuby
@KeithElder
Director, Software Engineering @ Quicken Loans
or
Aka: Professional Emailer and Typer
Editor's Notes
Having a childGrand CanyonVolcanoesOceanSomeone that has fought a disease and won
Sunset at North Pole, pretty amazing picture wouldn’t you agree?
Talk about what rule engines are.
We will be taking this fairly common english statement and use it as a basis for a rules engine. We’ll take this english text, and generate Ruby script which will then call into C# code. And of course it goes without saying that we can store the ruby script in the Cylinder and thus invoke this whenever we want. We’ll be using IronRuby to execute the Ruby Script.
http://en.wikipedia.org/wiki/Business_rules_engine#Types_of_rule_enginesForward chaining – works until a goal is metBackward chaining - works backward from the goal
http://en.wikipedia.org/wiki/Business_rules_engine#Types_of_rule_enginesForward chaining – works until a goal is metBackward chaining - works backward from the goal
I got this email from a fellow team member in marketing a few months ago. What he sent me was the rules that needed to process a particular feedback survey. We have lots of these surveys that collect data, and each has their own specific types of rules and what not. Now while we have a rules engine internally that we’ve built, and a pretty amazing one, it doesn’t really help us in this situation because:It requires a lot of trainingIt only runs on windows, this team member has a MacIt is very complicatedIt woldn’t *amaze* anyone in MarketingThink about this from my team member’s perspective (who is our client in this case). If we used his exact words to write these ruels, wouldn’t THAT BE AMAZING!? Answer: Yes.And this is what we did. So let’s take a look at a stripped down sample / demo UI.
Let’s look at the first three lines of the sample rules.
Let’s look at the first three lines of the sample rules.
Let’s look at the first three lines of the sample rules.
Let’s look at the first three lines of the sample rules.
Let’s look at the first three lines of the sample rules.
Let’s look at the first three lines of the sample rules.