building an english based rules engine

29
Building an English-based Rules Engine Using .NET and IronRuby @KeithElder Director, Software Engineering @ Quicken Loans or Aka: Professional Emailer and Typer

Upload: keithelder

Post on 29-Nov-2014

542 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Building an english based rules engine

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

Quicken Loans

Page 3: Building an english based rules engine
Page 4: Building an english based rules engine

WHAT AMAZES YOU?

Page 5: Building an english based rules engine
Page 6: Building an english based rules engine

ARE RULE ENGINES AMAZING?

Page 7: Building an english based rules engine

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

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

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

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

DEMO

Page 12: Building an english based rules engine

What This Is Not

• Natural language processing• Machine learning

Page 13: Building an english based rules engine

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

HOW DOES IT WORK?

Page 15: Building an english based rules engine

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

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

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

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

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

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

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

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

SERIOUSLY DUDE WHERE’S THE RUBY, THAT’S THE ONLY REASON I’M HERE

Page 24: Building an english based rules engine

CONVERTING ENGLISH TO RUBY

Page 25: Building an english based rules engine

What Do We Know?

• Statements• Which functions those statements

map to

Page 26: Building an english based rules engine

DEMO

Page 27: Building an english based rules engine

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

DEMO – RULES FOR THE SOUTH, OTHER LANGUAGES AND LANGUAGE VARIANCES

Page 29: Building an english based rules engine

Building an English-based Rules Engine Using .NET and IronRuby

@KeithElder

Director, Software Engineering @ Quicken Loansor

Aka: Professional Emailer and Typer