Droolsand Rule Based Systems 2008 Srping

80 %
20 %
Information about Droolsand Rule Based Systems 2008 Srping

Published on April 27, 2009

Author: hemapani

Source: slideshare.net

Description

Presentation at IU, to the research group

Drools and Rule Based Systems Srinath Perera

Rule Engine Terms Expert Systems / Business rules engine / Production Systems / Inference Engines are used to address rule engines based on their implementations. Usually a Rule engine usually includes three parts. Facts represented as working memory or another set of rules e.g. Prolog  road(a,b) or Drools objects Set of rules that declaratively define conditions or situations e.g. Prolog route(X,Z) <- road(X,Z) Actions executed or inference derived based on the rules

Terms Expert Systems / Business rules engine / Production Systems / Inference Engines are used to address rule engines based on their implementations.

Usually a Rule engine usually includes three parts.

Facts represented as working memory or another set of rules e.g. Prolog  road(a,b) or Drools objects

Set of rules that declaratively define conditions or situations e.g. Prolog route(X,Z) <- road(X,Z)

Actions executed or inference derived based on the rules

Rules Allow users to specify the requirements declarative, using a logic based languages. (Say what should happen, not how to do it). Rules may trigger other rules. Four types of rules (from http://www.w3.org/2000/10/swap/doc/rule-systems) Derivation or Deduction Rules – Each rules express if some statements are true, another statement must be true. Called logical implication. E.g. Prolog Transformation Rules- transform between knowledge bases, e.g. therom proving Integrity Constraints – verification rules Reaction or Event-Condition-Action (ECA) Rules – includes a actions in addition to inference. e.g. Drools

Allow users to specify the requirements declarative, using a logic based languages. (Say what should happen, not how to do it). Rules may trigger other rules.

Four types of rules (from http://www.w3.org/2000/10/swap/doc/rule-systems)

Derivation or Deduction Rules – Each rules express if some statements are true, another statement must be true. Called logical implication. E.g. Prolog

Transformation Rules- transform between knowledge bases, e.g. therom proving

Integrity Constraints – verification rules

Reaction or Event-Condition-Action (ECA) Rules – includes a actions in addition to inference. e.g. Drools

Production Systems Drools belongs to the category of rule engines called production systems [1] (which execute actions based on conditions) Drools use forward chaining[2] (start with data and execute actions to infer more data ) Priorities assigned to rules are used to decide the order of rule execution They remember all results and use that to optimize new derivations (dynamic programming like) http://en.wikipedia.org/wiki/AI_production http://en.wikipedia.org/wiki/Forward_chaining

Drools belongs to the category of rule engines called production systems [1] (which execute actions based on conditions)

Drools use forward chaining[2] (start with data and execute actions to infer more data )

Priorities assigned to rules are used to decide the order of rule execution

They remember all results and use that to optimize new derivations (dynamic programming like)

http://en.wikipedia.org/wiki/AI_production

http://en.wikipedia.org/wiki/Forward_chaining

Why rule engines? ~[1],[2][3] Simplify complicated requirements with declarative logic, raising the level of abstraction of the system Externalize the business logic (which are too dynamic) from comparatively static code base Intuitive and readable than code, easily understood by business people/ non technical users Create complex interactions which can have powerful results, even from simple facts and rules. Different approach to the problem, some problem are much easier using rules. Ability to specify explicit time and dates for rules to take effect Real-World Rule Engines http://www.infoq.com/articles/Rule-Engines Why are business rules better than traditional code? http://www.edmblog.com/weblog/2005/11/why_are_busines.html Rules-based Programming with JBoss Rules/Drools www.codeodor.com

Simplify complicated requirements with declarative logic, raising the level of abstraction of the system

Externalize the business logic (which are too dynamic) from comparatively static code base

Intuitive and readable than code, easily understood by business people/ non technical users

Create complex interactions which can have powerful results, even from simple facts and rules.

Different approach to the problem, some problem are much easier using rules.

Ability to specify explicit time and dates for rules to take effect

Real-World Rule Engines http://www.infoq.com/articles/Rule-Engines

Why are business rules better than traditional code? http://www.edmblog.com/weblog/2005/11/why_are_busines.html

Rules-based Programming with JBoss Rules/Drools www.codeodor.com

When not to use rule engines? It is slower then usual code most of the time, so unless one of the following is true is should not be used Complexity of logic is hard to tackle Logic changes too often Required to use by non technical users Interactions between rules could be quite complex, and one mistake could change the results drastically and unexpected way e.g recursive rules Due to above testing and debugging is required, so if results are hard to verified it should not be used.

It is slower then usual code most of the time, so unless one of the following is true is should not be used

Complexity of logic is hard to tackle

Logic changes too often

Required to use by non technical users

Interactions between rules could be quite complex, and one mistake could change the results drastically and unexpected way e.g recursive rules

Due to above testing and debugging is required, so if results are hard to verified it should not be used.

Drools Facts as a Object repository of java objects New objects can be added, removed or updated support if <query> then <action> type rules Queries use OOP format Support not, or, and, forall and exists completing first order logic

Facts as a Object repository of java objects

New objects can be added, removed or updated

support if <query> then <action> type rules

Queries use OOP format

Support not, or, and, forall and exists completing first order logic

Patterns Have a OOP based intuitive rule format. We presents examples using a insurance quota example. Following rule reject all customers whose age less than 17. rule &quot;MinimumAge&quot; when     c : Customer(age < 17) then     c.reject(); end Conditions support <, >, ==, <=, >=, matches / not matches, contains / not contains. And following rules provide a discount if customer is married or older than 25. rule &quot;Discount&quot; when     c : Customer( married == true || age > 25) then     c.addDiscount(10); end

Have a OOP based intuitive rule format. We presents examples using a insurance quota example.

Following rule reject all customers whose age less than 17.

rule &quot;MinimumAge&quot; when     c : Customer(age < 17) then     c.reject(); end Conditions support <, >, ==, <=, >=, matches / not matches, contains / not contains. And following rules provide a discount if customer is married or older than 25.

rule &quot;Discount&quot; when     c : Customer( married == true || age > 25) then     c.addDiscount(10); end

OR, AND, eval() OR – true if either of the statements true E.g. Customer(age > 50) or Vehicle( year > 2000) AND – provide logical, if no connectivity is define between two statements, “and” is assumed by default. For an example. c : Customer( timeSinceJoin > 2); not (Accident(customerid == c.name)) and c : Customer( timeSinceJoin > 2) and     not (Accident(customerid == c.name)) are the same. eval(boolean expressions) – with eval(..) any Boolean expression can be used. E.g. C:Customer(age > 20) eval(C.calacuatePremium() > 1000)

OR – true if either of the statements true

E.g. Customer(age > 50) or Vehicle( year > 2000)

AND – provide logical, if no connectivity is define between two statements, “and” is assumed by default. For an example.

c : Customer( timeSinceJoin > 2); not (Accident(customerid == c.name))

and

c : Customer( timeSinceJoin > 2) and     not (Accident(customerid == c.name))

are the same.

eval(boolean expressions) – with eval(..) any Boolean expression can be used.

E.g. C:Customer(age > 20)

eval(C.calacuatePremium() > 1000)

Not Not – negation or none can be found. E.g. not Plan( type = “home”) is true if no plan of type home is found. Following is true if customer has take part in no accidents. rule &quot;NoAccident&quot; when     c : Customer( timeSinceJoin > 2);     not (Accident(customerid == c.name)) then     c.addDiscount(10); end

Not – negation or none can be found. E.g.

not Plan( type = “home”)

is true if no plan of type home is found. Following is true if customer has take part in no accidents.

rule &quot;NoAccident&quot; when     c : Customer( timeSinceJoin > 2);     not (Accident(customerid == c.name)) then     c.addDiscount(10); end

For all True if all objects selected by first part of the query satisfies rest of the conditions. For an example following rule give 25 discount to customers who has brought every type of plans offered. rule &quot;OtherPlans&quot; when     forall ($plan : PlanCategory() c : Customer(plans contains $plan)) then     c.addDiscount(25); end

True if all objects selected by first part of the query satisfies rest of the conditions. For an example following rule give 25 discount to customers who has brought every type of plans offered.

rule &quot;OtherPlans&quot; when     forall ($plan : PlanCategory() c : Customer(plans contains $plan)) then     c.addDiscount(25); end

Exists True if at least one matches the query, This is Different for just having Customer(), which is like for each which get invoked for each matching set. Following rule give a discount for each family where two members having plans rule “FamilyMembers&quot; when $c : Customer()     exists (Customer( name contains $c.family)) then     c.addDiscount(5); end

True if at least one matches the query,

This is Different for just having Customer(), which is like for each which get invoked for each matching set.

Following rule give a discount for each family where two members having plans

Conflict resolution Each rule may define attributes There are other parameters you can found from [1]. E.g. rule &quot;MinimumAge&quot; salience = 10 when     c : Customer(age < 17) then     c.reject(); end salience define priority of the rule and decide their activation order. http://labs.jboss.com/drools/documentation.html

Each rule may define attributes There are other parameters you can found from [1]. E.g.

rule &quot;MinimumAge&quot; salience = 10

when     c : Customer(age < 17) then     c.reject(); end

salience define priority of the rule and decide their activation order.

http://labs.jboss.com/drools/documentation.html

Drools Performance Measuring Rule engine performance is tricky. Main factors are number of objects and number of rules. But results depends on nature of rules. A user feedback [1] claims Drools about 4 times faster than JRules [4]. [2] shows a comparison between Drools, Jess [5] and Microsoft rule engine. Overall they are comparable in performance. http://blog.athico.com/2007/08/drools-vs-jrules-performance-and-future.html http://geekswithblogs.net/cyoung/articles/54022.aspx Jess - http://herzberg.ca.sandia.gov/jess/ JRules http://www.ilog.com/products/jrules/ (SequentialRete) 16ms/15ms 4ms/4ms 100 1219 JRules Drools Objects rules

Measuring Rule engine performance is tricky.

Main factors are number of objects and number of rules. But results depends on nature of rules.

A user feedback [1] claims Drools about 4 times faster than JRules [4].

[2] shows a comparison between Drools, Jess [5] and Microsoft rule engine. Overall they are comparable in performance.

http://blog.athico.com/2007/08/drools-vs-jrules-performance-and-future.html

http://geekswithblogs.net/cyoung/articles/54022.aspx

Jess - http://herzberg.ca.sandia.gov/jess/

JRules http://www.ilog.com/products/jrules/

Drools Performance Contd. I have ran the well known rule engine bench mark [1] implementation provided with Drools. (On linbox3 - 1GB memory, 4 CPU 3.20GHz ) http://www.cs.utexas.edu/ftp/pub/ops5-benchmark-suite/HOW.TO.USE 2642 1305 34 1661 1001 34 956 697 34 420 393 34 Waltz DB 9030 3873 31 1582 958 31 Waltz Time (ms) Object Count Rule Count Bench Marks

I have ran the well known rule engine bench mark [1] implementation provided with Drools. (On linbox3 - 1GB memory, 4 CPU 3.20GHz )

http://www.cs.utexas.edu/ftp/pub/ops5-benchmark-suite/HOW.TO.USE

Data Mining Use Case

Rule based Solution We represent Queries as Objects that include bounds and list of selected data products We represent Data products as Objects that include location and time it was collected. Then following two rules will solve the problem Rule 1. For each data item, if it match spatial and temporal boundaries, add it to data collected for query Rule 2. When temporal end time is passed, invoke the data mining workflow with collected data

We represent Queries as Objects that include bounds and list of selected data products

We represent Data products as Objects that include location and time it was collected.

Then following two rules will solve the problem

Rule 1. For each data item, if it match spatial and temporal boundaries, add it to data collected for query

Rule 2. When temporal end time is passed, invoke the data mining workflow with collected data

 

Concrete Rules RULE 1. For each data item, if it match spatial and temporal boundaries of a Query, add it to data collected for query when      q: Query(completed = false);      d: Data( x > q.minX && x < q.maxX && y > q.minY && y < q.maxY && timeStamp > q.start && timestamp < q.end) then      q.addDataProduct(d); end RULE 2. When temporal end time is passed, invoke the data mining workflow with collected data when      system:System()      q: Query(completed = false, end < system.currentTime); then      q.completed = true;      q.runDataMiningAndInvokeWorkflow(); end

RULE 1. For each data item, if it match spatial and temporal boundaries of a Query, add it to data collected for query

when      q: Query(completed = false);      d: Data( x > q.minX && x < q.maxX

&& y > q.minY && y < q.maxY

&& timeStamp > q.start && timestamp < q.end) then      q.addDataProduct(d); end RULE 2. When temporal end time is passed, invoke the data mining workflow with collected data

when      system:System()      q: Query(completed = false, end < system.currentTime); then      q.completed = true;      q.runDataMiningAndInvokeWorkflow(); end

Conclusion Drools provide a OOP based intuitive rule language based on Rete (which is state of art public algorithm) It has good performance, comparable with Jess (which I not free). It is Open source, has a healthy and active community and JBoss cooperation backing it Extensively used in business rule community

Drools provide a OOP based intuitive rule language based on Rete (which is state of art public algorithm)

It has good performance, comparable with Jess (which I not free).

It is Open source, has a healthy and active community and JBoss cooperation backing it

Extensively used in business rule community

Add a comment

Related pages

Rule Based Systems - Documents - docslide.us

×Close Share Rule Based Systems. Embed
Read more

Rule Based Systems - Documents - docslide.us

Rule Based Systems. If then Rules to solve problems What is forward chaining? What is backward chaining? Expert systems. RB Deduction Systems. Rule looks ...
Read more

Rule Based Systems Rule based systems / Knowledge based ...

Slide 1 Rule Based Systems Rule based systems / Knowledge based systems/ Expert Systems have played and plays an important role in the AI industry.
Read more

Production Systems Productions systems are rule based ...

Slide 1 Production Systems Productions systems are rule based forward chaining systems. They are based on forward chained reasoning, ...
Read more

rule refinement in inductive knowledge based systems ...

Share rule refinement in inductive knowledge based systems. ... Droolsand Rule Based Systems 2008 Srping. Knowledge Management in a Knowledge Based Discipline.
Read more

1 Rule Based Systems Introduction to Production System ...

Download 1 Rule Based Systems Introduction to Production System Architecture. Transcript. Slide 1 ;
Read more