Transcript

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

eBusiness Technologies (ebTech)

Introduction to Rule-based Applications

Dr. Adrian GiurcaBrandenburg University of Technology

Cottbus, Germany

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Who I am

• Adrian Giurca (42 years old )• I was with University of Craiova from 1990• From 2005 I work at Brandenburg University

of Technology in Cottbus, Germany• During the years, I taught Logic Programming,

Software Engineering, Web Technologies, eBusiness Technologies, Semantic Web, and others.

http://adrian-giurca.blogspot.com/ http://inf.ucv.ro/~giurca http://www.informatik.tu-cottbus.de/~agiurca

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

This lecture is about rule based applications

• Rules are best used in applications with a dynamic business logic i.e. applications where changes in the business logic are frequently and they need to be immediately reflected in the application behavior.

• Rules applies successfully in domains such as: o insurance (insurance rating), o financial services (loans, claims routing and

management, fraud detection), o government (tax calculations), o telecom customer (care and billing), o e-commerce (personalizing the user's experience,

recommender systems, auctions)

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

The student main activity: Ask questions

• Whenever you need please ask questions!• (I have many open questions too... )

o Stop me and ask...o Maybe you'll get an answer (If I have one...)o Or I will answer you in the next lecture

• You can ask in RO. I'm pleased to speak RO• Slides are in English (they are not just for

you)

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Your knowledge on rules

• Do you know rule languages? Prolog, Lisp,

Guru, Godel, Mercury,...

• Do you use rule languages?

Prolog, Lisp, Guru,...

• What rule-based applications you built?

?

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

What do you know about programming?

Modeling UML,...

LanguagesJava, C, C+

+, ...

ParadigmsProcedural, OOP,

Functional, Declarative, ...

MethodologiesRUP, Extreme,

Agile,...

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

What's your preferred programming model?

Modeling UML?

LanguagesJava? Paradigms

OOP?

MethodologiesAgile?

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Embedding rules in Java – Using Libraries

• Prolog 2 Java:o SWI-Prolog JPL: http://www.swi-rolog.org/packages/jpl/ o JProlog: http://www.cs.kuleuven.ac.be/~bmd/PrologInJ

ava/

• And many others...But:• Did you used them ever?• Are they easy to be used?• What about the programming model? How

you design your application?

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Business community use natural language (NL) to express rules

• If all of the following are true, then the car's potential theft rating is low:o car's price is less that $20,000,o car model is not on the list of 'High Theft

Probability Auto'.• If the car has no airbags, then the car's

potential occupant injury rating is extremely high.

• If the driver is a young driver, is married and located in CA, NY or VA, then increase policy premium by $700.

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Logic programming (LP) is great

1.Has a well established semantics2.Well known engine(s)3.You have to learn the syntax and (at least)

the operational semantics4.With LP background one can easily

understand other solutions

• Can you model the above rules in Prolog?• Can you use them in an insurance scoring

application ?• Can you change the rules at runtime?

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Slide No. 11

• This is Slide No. 11 (half time) and we don't know yet how to use rules in a large application?!

(Yet) Open Questions:– How to model such an application? Which modeling

language I have to use?– Which rule library to use?– How to separate the rules – logic from the rest of application – logic?– How to debug the application?– How to maintain/re-factor?

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

This Course Goals

• To learn you basic rule modeling• To introduce the basics of a Java-based rule

engine:

A project of

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Facts about Drools

• Open-Source, Forward-Chaining Production Rule System

• Reuse rules across applications and Service-Oriented Architectures

• The runtime provides dynamic assertion and remove of rules

• Offers support for temporal rules that are executed within specified time periods or constraints

• Drools Rule Language (DRL) uses Java to express field constraints, functions, and consequences

• Drools Workbench IDE features include syntax coloring, outline view, basic rule validation and error reporting

• Blog: http://blog.athico.com/

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Rules are based on domain vocabularies

• Many software engineers design vocabularies using UML

• UML class diagrams can be straightforward mapped to Java.

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Can we use UML to design rules?

• If the driver is a young driver, is married and located in CA, NY or VA, then increase policy premium by $700.

Conditions

Variables

Actions

Rule Symbol

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

URML–UML-based language for rule modeling

• URML supports modeling of o derivation rules (aka Prolog rules), o production rules (aka Expert Systems rules) o reaction rules (Event-Condition-Action rules).

• A rule is represented graphically as a circle with a rule identifier.

• Incoming arrows represent rule conditions or triggering events

• Outgoing arrows represent rule conclusions or produced actions.

• Ask me later if you are interested!

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Drools Rule Language (is almost Java!!)

rule "DP_01"agenda-group "driver-premium"salience 10when//If young driver, married and located in //one of CA, NY or VA$driver:YoungDriver(maritalStatus == MaritalStatus.MARRIED,usState == "CA" || == "NY" || == "VA", $policy:vehicleInsurancePolicy)then//increase policy premium by $700$policy.setPremium($policy.getPremium()+ 700);$driver.setPolicy($policy)drools.modifyObject($driver);end

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Can you write this rule using logic ? (Of course)

IF youngDriver($driver)ANDmaritalStatus($driver, "married") AND(usState($driver, "CA") OR usState($driver, "NY") OR usState($driver, "VA")) AND vehicleInsurancePolicy($driver, $policy) ANDTHENpremium($policy, $premium) ANDretract(premium($policy, $premium)) ANDretract(vehicleInsurancePolicy($driver, $policy)) ANDassert(premium($policy, $premium+700)) ANDassert(vehicleInsurancePolicy($driver, $policy))

• Logic works fine. Is enough.

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

What about this representation?

IF driver($driver, type("youngDriver"), maritalStatus("married"), vehicleInsurancePolicy(policy($premium)))AND....

• Logic works fine?! Is enough?! Hmm...• How can I connect my rules with already existent Java

classes in my application?• Add more classes... Mappings... Increase complexity...• Better use a Java syntax for rules... and a Java-based rule

engine!

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Many commercial usages of rule engines

• IBM Rules (former ILOG Rules), http://www.ilog.com/

• Oracle Business Rules, http://www.oracle.com/technology/products/ias/business_rules

• Fair Isaac, http://www.fairisaac.com/ • Innovations, http://www.innovations.de/ • Pegasystems, http://www.pega.com/ • Computer Associates, http://www.ca.com/ • Gensym, http://www.gensym.com/ • Corticon, http://www.corticon.com/

Adrian Giurca, eBusiness Technologies, Craiova, March 2009

Do you like rule-based applications?

• Attend the next lecture o Tomorrow at 4PM in the same room

top related