logging in or signing up drools euos05 Jacob Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINTLite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 847 Category: Entertainment License: All Rights Reserved Like it (0) Dislike it (1) Added: December 04, 2007 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript DroolsAn Open Source Java Rules Engine: Brian Sam-Bodden Principal Partner Integrallis Software, LLC. October 17 - 20, 2005 Drools An Open Source Java Rules EngineContents: A simple problem – Recipe Finder Recipe Finder – Procedural Implementation Introducing Drools Recipe Finder – The Drools Way ContentsContents: Rule Engine Applications Domain Specific Languages Integrating Drools Drools Loan Calculator Choosing to use a Rule Engine Choosing a Rule Engine ContentsRecipe Finder Application: Problem: Given a list of Ingredients and Recipes determine which recipes can be prepared Recipe Finder ApplicationRecipe Finder - Domain: 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);Recipe Finder - Domain: Recipe Finder - Domain Recipe Finder Domain ModelRecipe Finder - Procedural: Recipe Finder - Procedural Traditional Procedural Approach Loop over all recipes …check each recipe against available ingredients …save the matching recipesRecipe Finder - Procedural: Recipe Finder - Procedural Matching Ingredients and Recipes for ( Recipe recipe : recipes ) { for ( Ingredient ingredient : ingredients ) { recipe.matchIngredient(ingredient); } if (recipe.getIsComplete()) { searchResults.addMatch(recipe); } }Recipe Finder - Procedural: Recipe Finder - Procedural DEMODrools: 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/Drools – The Big Picture: Drools – The Big PictureRecipe Finder - Drools: Recipe Finder - Drools 2 Rules IngredientMatch Rule Matches an ingredient to a recipe RecipeMatch Rule Collects recipes with all ingredients matched Recipe Finder - Drools: Recipe Finder - Drools <rule name="IngredientMatch"> <parameter identifier="recipe"> <java:class>Recipe</java:class> </parameter> <parameter identifier="ingredient"> <java:class>Ingredient</java:class> </parameter> <java:condition> recipe.containsIngredient(ingredient) </java:condition> <java:consequence> if (recipe.matchIngredient(ingredient)) { drools.modifyObject(recipe); } </java:consequence> </rule>Recipe Finder - Drools: Recipe Finder - Drools <rule name=“RecipeMatch"> <parameter identifier="recipe"> <java:class>Recipe</java:class> </parameter> <java:condition> recipe.getIsComplete() </java:condition> <java:consequence> searchResults.addMatch(recipe); drools.retractObject(recipe); </java:consequence> </rule>Recipe Finder - Drools: Recipe Finder - Drools Rules are declarative Follow the pattern IF <condition> THEN <consequence> A rule firing (execution) can change the state of the WorkingMemory therefore possibly triggering other rules to fireRecipe Finder – DRL File: Recipe Finder – DRL File DRL Files are XML Contain one or more Rules Several Semantic Modules Available: Java Groovy Python Recipe Finder - Loading the Rules: 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();Recipe Finder – Asserting Facts: Recipe Finder – Asserting Facts // assert facts - ingredients workingMemory.assertObject(rice); workingMemory.assertObject(chocolateCake); workingMemory.assertObject(eggs); … // assert facts - recipes workingMemory.assertObject(riceAndBeans); workingMemory.assertObject(chocolateCake); workingMemory.assertObject(pancakes); workingMemory.assertObject(rancheroEggs);Recipe Finder – Application Data: Recipe Finder – Application Data // create Search Results object SearchResults searchResults = new SearchResults(); // set application data – Search Results workingMemory .setApplicationData("searchResults" ,searchResults);Recipe Finder – Rule Firing: Recipe Finder – Rule Firing workingMemory.fireAllRules(); Output: Using drl: recipefinder.java.drl … You can make Rice and Beans You can make Ranchero EggsRecipe Finder - Drools: Recipe Finder - Drools DEMORule Engines - Applications: Rule Engines - Applications Knowledge Discovery Path Optimization Insurance Fraud Detection Email & Spam Filters Retail, Holiday Promotions Credit Scoring Domain Specific Languages: 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 knowledgeIntegrating Drools: 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)Loan Calculator - DSL Example: 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 RulesLoan Calculator - DSL Example: Loan Calculator - DSL ExampleLoan Calculator - DSL Example: Loan Calculator - DSL Example <rule name="XYZ-FicoScore"> <loans:condition> <loans:lender name="XYZ Mortage" /> <loans:application> <loans:fico> <loans:less-than>680</loans:less-than> </loans:fico> </loans:application> </loans:condition> <loans:actions> <loans:application name="messages"> <loans:add> Declined by XYZ Mortgage because a FICO score of at least 680 is required </loans:add> </loans:application> </loans:actions> </rule>Loan Calculator - DSL Example: 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 DeployerLoan Calculator - Code: Loan Calculator - Code // A Simple Drools-enabled SSB @Stateless public class LoanCalculatorServiceBean implements … // Inject RuleBase from JNDI @Resource(name = "java:/drools/LoansRuleBase") protected RuleBase ruleBase; public LoanApplication submitApplication(…) { //Create a Working Memory WorkingMemory workingMemory = ruleBase.newWorkingMemory();Loan Calculator - Code: Loan Calculator - Code CODELoan Calculator - Demo: Loan Calculator - Demo DEMOChoosing to use a Rule Engine: Choosing to use a Rule Engine Don’t 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 changingChoosing to use a Rule Engine: 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 expertiseChoosing a Rule Engine: 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 ComplianceQuestions: QuestionsShameless Plug ;-): Shameless Plug ;-)Thank You!: Thank You! Please fill out the speaker evaluation You can contact me further at … bsbodden@integrallis.com Stand by…for an important Announcement!: Stand by… for an important Announcement! You do not have the permission to view this presentation. In order to view it, please contact the author of the presentation.
drools euos05 Jacob Download Post to : URL : Related Presentations : Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Uploaded from authorPOINTLite Insert YouTube videos in PowerPont slides with aS Desktop Copy embed code: (To copy code, click on the text box) Embed: URL: Thumbnail: WordPress Embed Customize Embed The presentation is successfully added In Your Favorites. Views: 847 Category: Entertainment License: All Rights Reserved Like it (0) Dislike it (1) Added: December 04, 2007 This Presentation is Public Favorites: 0 Presentation Description No description available. Comments Posting comment... Premium member Presentation Transcript DroolsAn Open Source Java Rules Engine: Brian Sam-Bodden Principal Partner Integrallis Software, LLC. October 17 - 20, 2005 Drools An Open Source Java Rules EngineContents: A simple problem – Recipe Finder Recipe Finder – Procedural Implementation Introducing Drools Recipe Finder – The Drools Way ContentsContents: Rule Engine Applications Domain Specific Languages Integrating Drools Drools Loan Calculator Choosing to use a Rule Engine Choosing a Rule Engine ContentsRecipe Finder Application: Problem: Given a list of Ingredients and Recipes determine which recipes can be prepared Recipe Finder ApplicationRecipe Finder - Domain: 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);Recipe Finder - Domain: Recipe Finder - Domain Recipe Finder Domain ModelRecipe Finder - Procedural: Recipe Finder - Procedural Traditional Procedural Approach Loop over all recipes …check each recipe against available ingredients …save the matching recipesRecipe Finder - Procedural: Recipe Finder - Procedural Matching Ingredients and Recipes for ( Recipe recipe : recipes ) { for ( Ingredient ingredient : ingredients ) { recipe.matchIngredient(ingredient); } if (recipe.getIsComplete()) { searchResults.addMatch(recipe); } }Recipe Finder - Procedural: Recipe Finder - Procedural DEMODrools: 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/Drools – The Big Picture: Drools – The Big PictureRecipe Finder - Drools: Recipe Finder - Drools 2 Rules IngredientMatch Rule Matches an ingredient to a recipe RecipeMatch Rule Collects recipes with all ingredients matched Recipe Finder - Drools: Recipe Finder - Drools <rule name="IngredientMatch"> <parameter identifier="recipe"> <java:class>Recipe</java:class> </parameter> <parameter identifier="ingredient"> <java:class>Ingredient</java:class> </parameter> <java:condition> recipe.containsIngredient(ingredient) </java:condition> <java:consequence> if (recipe.matchIngredient(ingredient)) { drools.modifyObject(recipe); } </java:consequence> </rule>Recipe Finder - Drools: Recipe Finder - Drools <rule name=“RecipeMatch"> <parameter identifier="recipe"> <java:class>Recipe</java:class> </parameter> <java:condition> recipe.getIsComplete() </java:condition> <java:consequence> searchResults.addMatch(recipe); drools.retractObject(recipe); </java:consequence> </rule>Recipe Finder - Drools: Recipe Finder - Drools Rules are declarative Follow the pattern IF <condition> THEN <consequence> A rule firing (execution) can change the state of the WorkingMemory therefore possibly triggering other rules to fireRecipe Finder – DRL File: Recipe Finder – DRL File DRL Files are XML Contain one or more Rules Several Semantic Modules Available: Java Groovy Python Recipe Finder - Loading the Rules: 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();Recipe Finder – Asserting Facts: Recipe Finder – Asserting Facts // assert facts - ingredients workingMemory.assertObject(rice); workingMemory.assertObject(chocolateCake); workingMemory.assertObject(eggs); … // assert facts - recipes workingMemory.assertObject(riceAndBeans); workingMemory.assertObject(chocolateCake); workingMemory.assertObject(pancakes); workingMemory.assertObject(rancheroEggs);Recipe Finder – Application Data: Recipe Finder – Application Data // create Search Results object SearchResults searchResults = new SearchResults(); // set application data – Search Results workingMemory .setApplicationData("searchResults" ,searchResults);Recipe Finder – Rule Firing: Recipe Finder – Rule Firing workingMemory.fireAllRules(); Output: Using drl: recipefinder.java.drl … You can make Rice and Beans You can make Ranchero EggsRecipe Finder - Drools: Recipe Finder - Drools DEMORule Engines - Applications: Rule Engines - Applications Knowledge Discovery Path Optimization Insurance Fraud Detection Email & Spam Filters Retail, Holiday Promotions Credit Scoring Domain Specific Languages: 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 knowledgeIntegrating Drools: 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)Loan Calculator - DSL Example: 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 RulesLoan Calculator - DSL Example: Loan Calculator - DSL ExampleLoan Calculator - DSL Example: Loan Calculator - DSL Example <rule name="XYZ-FicoScore"> <loans:condition> <loans:lender name="XYZ Mortage" /> <loans:application> <loans:fico> <loans:less-than>680</loans:less-than> </loans:fico> </loans:application> </loans:condition> <loans:actions> <loans:application name="messages"> <loans:add> Declined by XYZ Mortgage because a FICO score of at least 680 is required </loans:add> </loans:application> </loans:actions> </rule>Loan Calculator - DSL Example: 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 DeployerLoan Calculator - Code: Loan Calculator - Code // A Simple Drools-enabled SSB @Stateless public class LoanCalculatorServiceBean implements … // Inject RuleBase from JNDI @Resource(name = "java:/drools/LoansRuleBase") protected RuleBase ruleBase; public LoanApplication submitApplication(…) { //Create a Working Memory WorkingMemory workingMemory = ruleBase.newWorkingMemory();Loan Calculator - Code: Loan Calculator - Code CODELoan Calculator - Demo: Loan Calculator - Demo DEMOChoosing to use a Rule Engine: Choosing to use a Rule Engine Don’t 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 changingChoosing to use a Rule Engine: 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 expertiseChoosing a Rule Engine: 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 ComplianceQuestions: QuestionsShameless Plug ;-): Shameless Plug ;-)Thank You!: Thank You! Please fill out the speaker evaluation You can contact me further at … bsbodden@integrallis.com Stand by…for an important Announcement!: Stand by… for an important Announcement!