Drools An Open Source Java Rules Engine - PowerPoint PPT Presentation

1 / 41
About This Presentation
Title:

Drools An Open Source Java Rules Engine

Description:

Drools Loan Calculator. Choosing to use a Rule Engine. Choosing a Rule Engine ... Loan Calculator - DSL Example. Problem. Application for Mortgage Origination ... – PowerPoint PPT presentation

Number of Views:4206
Avg rating:3.0/5.0
Slides: 42
Provided by: desi71
Category:

less

Transcript and Presenter's Notes

Title: Drools An Open Source Java Rules Engine


1
DroolsAn Open Source Java Rules Engine
Brian Sam-Bodden Principal Partner Integrallis
Software, LLC.
October 17 - 20, 2005
2
Contents
  • A simple problem Recipe Finder
  • Recipe Finder Procedural Implementation
  • Introducing Drools
  • Recipe Finder The Drools Way

3
Contents
  • Rule Engine Applications
  • Domain Specific Languages
  • Integrating Drools
  • Drools Loan Calculator
  • Choosing to use a Rule Engine
  • Choosing a Rule Engine

4
Recipe Finder Application
  • Problem Given a list of Ingredients and Recipes
    determine which recipes can be prepared

5
Recipe Finder - Domain
  • The POJOs Recipes and Ingredients
  • // Ingredients
  • Ingredient rice new Ingredient("rice")
  • Ingredient beans new Ingredient("beans")
  • // Recipes
  • Recipe riceAndBeans new Recipe("Rice and
    Beans")
  • riceAndBeans.addIngredient(rice)
  • riceAndBeans.addIngredient(beans)

6
Recipe Finder - Domain
  • Recipe Finder Domain Model

7
Recipe Finder - Procedural
  • Traditional Procedural Approach
  • Loop over all recipes
  • check each recipe against available ingredients
  • save the matching recipes

8
Recipe Finder - Procedural
  • Matching Ingredients and Recipes
  • for ( Recipe recipe recipes )
  • for ( Ingredient ingredient
    ingredients )
  • recipe.matchIngredient(ingredient)
  • if (recipe.getIsComplete())
  • searchResults.addMatch(recipe)

9
Recipe Finder - Procedural
DEMO
10
Drools
  • Forward Chaining Inference Engine
  • Based on Rete algorithm
  • Supports several languages for expressing Rules
  • Created by Bob McWhirter
  • Hosted at Codehaus
  • Open source, BSD Style License
  • Simple API (few classes to master)
  • http//drools.org/

11
Drools The Big Picture
12
Recipe Finder - Drools
  • 2 Rules
  • IngredientMatch Rule
  • Matches an ingredient to a recipe
  • RecipeMatch Rule
  • Collects recipes with all ingredients matched

13
Recipe Finder - Drools
identifier"recipe" Recipeaclass identifier"ingredient"
Ingredient

recipe.containsIngredient(ingredient)

if (recipe.matchIngredient(ingredient))
drools.modifyObject(recipe)
ule
14
Recipe Finder - Drools
identifier"recipe" Recipeaclass
recipe.getIsComplete()

searchResults.addMatch(recipe)
drools.retractObject(recipe)

15
Recipe Finder - Drools
  • Rules are declarative
  • Follow the pattern
  • IF THEN
  • A rule firing (execution) can change the state of
    the WorkingMemory therefore possibly triggering
    other rules to fire

16
Recipe Finder DRL File
  • DRL Files are XML
  • Contain one or more Rules
  • Several Semantic Modules Available
  • Java
  • Groovy
  • Python

17
Recipe Finder - Loading the Rules
// URL for DRL File URL url RecipeFinder.class
.getResource("recipefinder.java.drl") //
Create RuleBase RuleBase ruleBase
RuleBaseLoader.loadFromUrl(url) //Create a
Working Memory WorkingMemory workingMemory
ruleBase.newWorkingMemory()
18
Recipe Finder Asserting Facts
// assert facts - ingredients workingMemory.assert
Object(rice) workingMemory.assertObject(chocolate
Cake) workingMemory.assertObject(eggs) //
assert facts - recipes workingMemory.assertObject(
riceAndBeans) workingMemory.assertObject(chocolat
eCake) workingMemory.assertObject(pancakes) work
ingMemory.assertObject(rancheroEggs)
19
Recipe Finder Application Data
// create Search Results object SearchResults
searchResults new SearchResults() // set
application data Search Results workingMemory
.setApplicationData("searchResults"
,searchResults)
20
Recipe Finder Rule Firing
workingMemory.fireAllRules() Output Using drl
recipefinder.java.drl You can make Rice and
Beans You can make Ranchero Eggs
21
Recipe Finder - Drools
DEMO
22
Rule Engines - Applications
  • Knowledge Discovery
  • Path Optimization
  • Insurance Fraud Detection
  • Email Spam Filters
  • Retail, Holiday Promotions
  • Credit Scoring

23
Domain Specific Languages
  • Drools supports Domain Specific Languages
  • High-level abstract programming languages used to
    increase productivity
  • Uses XML W3C Schema be define and represent
    business rules
  • Enable sources closer to the knowledge to express
    that knowledge

24
Integrating Drools
  • In J2SE
  • Use native Drools APIs
  • Use JSR-94 Integration
  • Spring Pojo-Driven Rules
  • In J2EE
  • Stateless Session Beans
  • JNDI
  • MBeans for Management
  • RuleSet Storage
  • File System or Database (DIY)

25
Loan Calculator - DSL Example
  • Problem
  • Application for Mortgage Origination
  • Need for business people to easily author rules
  • Solution
  • Web based application
  • DSL for Loan Officers to enter Rules

26
Loan Calculator - DSL Example
27
Loan Calculator - DSL Example



680



Declined by XYZ Mortgage because
a FICO score of at least 680 is required


28
Loan Calculator - DSL Example
  • Steps
  • Define XSD loans.xsd
  • Implement
  • org.drools.smf.ConditionFactory
  • org.drools.smf.ConsequenceFactory
  • Integrate into JBoss-based application
  • Web UI
  • Stateless Session Bean Services
  • MBeans for Management
  • JBoss Drools Deployer

29
Loan Calculator - Code
// A Simple Drools-enabled SSB _at_Stateless public
class LoanCalculatorServiceBean implements
// Inject RuleBase from JNDI _at_Resource(name
"java/drools/LoansRuleBase") protected RuleBase
ruleBase public LoanApplication
submitApplication() //Create a Working
Memory WorkingMemory workingMemory

ruleBase.newWorkingMemory()
30
Loan Calculator - Code
CODE
31
Loan Calculator - Demo
DEMO
32
Choosing to use a Rule Engine
  • Dont use a Rule Engine if
  • Problems are computationally intensive and based
    on few well known rules
  • If your rules are not likely to change over
    time
  • You need a Rule Engine if
  • Need a clean separation of business policy from
    technology
  • Large number of business rules that are
    constantly changing

33
Choosing to use a Rule Engine
  • Procedural thinking execution path is predefined
  • If there is no exact recipe, ill defined problems
    dealing with search, discovery and evaluation
  • If it is hard to produce a flow chart or diagram
    then it is equally hard to produce a program
  • Rule based programming is the only technique to
    codify expertise

34
Choosing a Rule Engine
  • Authoring
  • Rule Language Support
  • Business people friendly
  • Management
  • Complex decision making need to be monitored
  • Deployment
  • Hot Deploy
  • Performance
  • Rule Caching
  • Pre-compilation
  • Standard Compliance

35
Questions
36
Shameless Plug -)
37
Thank You!
Please fill out the speaker evaluation You can
contact me further at bsbodden_at_integrallis.com
38
Stand byfor an important Announcement!
39
(No Transcript)
40
(No Transcript)
41
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com