SlideShare a Scribd company logo
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
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
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
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
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.
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
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
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)
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
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
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
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
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/   (Sequential\Rete) 16ms/15ms 4ms/4ms 100 1219 JRules Drools Objects rules
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
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
 
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
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

More Related Content

PDF
Rules Programming tutorial
PDF
Developing Configurable and High Performance Apps in Drools
PDF
Introducing Drools
PPTX
JBoss Drools - Pure Java Rule Engine
PPT
Introduction to Drools
PPTX
Rule Engine & Drools
PDF
Drools
PPTX
Rule Engine: Drools .Net
Rules Programming tutorial
Developing Configurable and High Performance Apps in Drools
Introducing Drools
JBoss Drools - Pure Java Rule Engine
Introduction to Drools
Rule Engine & Drools
Drools
Rule Engine: Drools .Net

What's hot (19)

ODP
Drools BeJUG 2010
ODP
Drools & jBPM Info Sheet
PPTX
Drools Ecosystem
PDF
Rules Engine - java(Drools) & ruby(ruleby)
PPTX
Jboss drools 4 scope - benefits, shortfalls
PPTX
Drools
PPTX
Rules engine
PPTX
Data structures
ODP
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
PDF
Brms best practices_2011_oct_final
PPT
Effective Spring Transaction Management
PPTX
[Java eeconf 2016] spring jta principles of work with transactions. Dmytro S...
KEY
SOLID Principles
DOCX
TY.BSc.IT Java QB U2
PPT
Spring Transaction
PPS
CS101- Introduction to Computing- Lecture 23
ODP
Java Persistence API
PDF
Meg bernal insight2014 4219
PPT
Slice: OpenJPA for Distributed Persistence
Drools BeJUG 2010
Drools & jBPM Info Sheet
Drools Ecosystem
Rules Engine - java(Drools) & ruby(ruleby)
Jboss drools 4 scope - benefits, shortfalls
Drools
Rules engine
Data structures
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
Brms best practices_2011_oct_final
Effective Spring Transaction Management
[Java eeconf 2016] spring jta principles of work with transactions. Dmytro S...
SOLID Principles
TY.BSc.IT Java QB U2
Spring Transaction
CS101- Introduction to Computing- Lecture 23
Java Persistence API
Meg bernal insight2014 4219
Slice: OpenJPA for Distributed Persistence
Ad

Similar to Droolsand Rule Based Systems 2008 Srping (20)

PPT
Flex 360 Rules Engine
PPT
Flex 360 Rules Engine
PPT
Obey The Rules: Implementing a Rules Engine in Flex
PPTX
Boston 16 03
PPT
Biz Talk Demo slideshare
PPTX
performancetestingjmeter-121109061704-phpapp02 (1)
PPTX
performancetestingjmeter-121109061704-phpapp02
PPS
ABPerformance Quick Tour
DOCX
BoardSprintUser Story ScenarioDesignDevelopmentTestUAT Release1U .docx
PPTX
Telecom Churn Analysis
ODP
Buenos Aires Drools Expert Presentation
PPT
Graphical Business Rules Management
PPT
Graphical Business Rules Management
PPT
Oracle Sql Tuning
PPT
Performance testing and j meter
PPTX
Drools rule Concepts
PDF
130214 wei wu - extracting business rules and removing duplication with iris
PPTX
Hard versus Soft real time system
PPTX
Mobile company services fitting to customer consumtion profile-spring sim2011...
PPTX
Romanov moscow-spring sim2011-finished
Flex 360 Rules Engine
Flex 360 Rules Engine
Obey The Rules: Implementing a Rules Engine in Flex
Boston 16 03
Biz Talk Demo slideshare
performancetestingjmeter-121109061704-phpapp02 (1)
performancetestingjmeter-121109061704-phpapp02
ABPerformance Quick Tour
BoardSprintUser Story ScenarioDesignDevelopmentTestUAT Release1U .docx
Telecom Churn Analysis
Buenos Aires Drools Expert Presentation
Graphical Business Rules Management
Graphical Business Rules Management
Oracle Sql Tuning
Performance testing and j meter
Drools rule Concepts
130214 wei wu - extracting business rules and removing duplication with iris
Hard versus Soft real time system
Mobile company services fitting to customer consumtion profile-spring sim2011...
Romanov moscow-spring sim2011-finished
Ad

More from Srinath Perera (20)

PDF
Book: Software Architecture and Decision-Making
PDF
Data science Applications in the Enterprise
PDF
An Introduction to APIs
PDF
An Introduction to Blockchain for Finance Professionals
PDF
AI in the Real World: Challenges, and Risks and how to handle them?
PDF
Healthcare + AI: Use cases & Challenges
PDF
How would AI shape Future Integrations?
PDF
The Role of Blockchain in Future Integrations
PDF
Future of Serverless
PDF
Blockchain: Where are we? Where are we going?
PDF
Few thoughts about Future of Blockchain
PDF
A Visual Canvas for Judging New Technologies
PDF
Privacy in Bigdata Era
PDF
Blockchain, Impact, Challenges, and Risks
PPTX
Today's Technology and Emerging Technology Landscape
PDF
An Emerging Technologies Timeline
PDF
The Rise of Streaming SQL and Evolution of Streaming Applications
PDF
Analytics and AI: The Good, the Bad and the Ugly
PDF
Transforming a Business Through Analytics
PDF
SoC Keynote:The State of the Art in Integration Technology
Book: Software Architecture and Decision-Making
Data science Applications in the Enterprise
An Introduction to APIs
An Introduction to Blockchain for Finance Professionals
AI in the Real World: Challenges, and Risks and how to handle them?
Healthcare + AI: Use cases & Challenges
How would AI shape Future Integrations?
The Role of Blockchain in Future Integrations
Future of Serverless
Blockchain: Where are we? Where are we going?
Few thoughts about Future of Blockchain
A Visual Canvas for Judging New Technologies
Privacy in Bigdata Era
Blockchain, Impact, Challenges, and Risks
Today's Technology and Emerging Technology Landscape
An Emerging Technologies Timeline
The Rise of Streaming SQL and Evolution of Streaming Applications
Analytics and AI: The Good, the Bad and the Ugly
Transforming a Business Through Analytics
SoC Keynote:The State of the Art in Integration Technology

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Hybrid model detection and classification of lung cancer
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
Tartificialntelligence_presentation.pptx
PDF
STKI Israel Market Study 2025 version august
PDF
August Patch Tuesday
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
1. Introduction to Computer Programming.pptx
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Developing a website for English-speaking practice to English as a foreign la...
NewMind AI Weekly Chronicles - August'25-Week II
Hybrid model detection and classification of lung cancer
Univ-Connecticut-ChatGPT-Presentaion.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Tartificialntelligence_presentation.pptx
STKI Israel Market Study 2025 version august
August Patch Tuesday
A contest of sentiment analysis: k-nearest neighbor versus neural network
WOOl fibre morphology and structure.pdf for textiles
Group 1 Presentation -Planning and Decision Making .pptx
1. Introduction to Computer Programming.pptx
O2C Customer Invoices to Receipt V15A.pptx
NewMind AI Weekly Chronicles – August ’25 Week III
Web App vs Mobile App What Should You Build First.pdf
Assigned Numbers - 2025 - Bluetooth® Document
1 - Historical Antecedents, Social Consideration.pdf
Getting started with AI Agents and Multi-Agent Systems
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Developing a website for English-speaking practice to English as a foreign la...

Droolsand Rule Based Systems 2008 Srping

  • 1. Drools and Rule Based Systems Srinath Perera
  • 2. 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
  • 3. 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
  • 4. 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
  • 5. 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
  • 6. 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.
  • 7. 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
  • 8. 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
  • 9. 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)
  • 10. 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
  • 11. 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
  • 12. 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
  • 13. 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
  • 14. 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/ (Sequential\Rete) 16ms/15ms 4ms/4ms 100 1219 JRules Drools Objects rules
  • 15. 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
  • 17. 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
  • 18.  
  • 19. 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
  • 20. 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