Drools Expert User Guide
Total Page:16
File Type:pdf, Size:1020Kb
Drools Expert User Guide Version 5.5.0.CR1 by The JBoss Drools team [http://www.jboss.org/drools/team.html] ....................................................................................................................................... vii 1. Introduction ................................................................................................................. 1 1.1. Artificial Intelligence ............................................................................................ 1 1.1.1. A Little History ......................................................................................... 1 1.1.2. Knowledge Representation and Reasoning ................................................ 2 1.1.3. Rule Engines and Production Rule Systems (PRS) .................................... 3 1.1.4. Hybrid Reasoning Systems (HRS) ............................................................ 5 1.1.5. Expert Systems ........................................................................................ 8 1.1.6. Recommended Reading ........................................................................... 9 1.2. Why use a Rule Engine? .................................................................................. 12 1.2.1. Advantages of a Rule Engine ................................................................. 13 1.2.2. When should you use a Rule Engine? ..................................................... 14 1.2.3. When not to use a Rule Engine .............................................................. 15 1.2.4. Scripting or Process Engines .................................................................. 15 1.2.5. Strong and Loose Coupling .................................................................... 16 1.3. Rete Algorithm .................................................................................................. 16 2. User Guide ................................................................................................................. 23 2.1. The Basics ....................................................................................................... 23 2.1.1. Stateless Knowledge Session ................................................................. 23 2.1.2. Stateful Knowledge Session .................................................................... 26 2.1.3. Methods versus Rules ............................................................................ 31 2.1.4. Cross Products ...................................................................................... 32 2.2. Inference .......................................................................................................... 33 2.2.1. Buss Pass Example ............................................................................... 33 2.3. Truth Maintenance with Logical Objects ............................................................. 35 2.3.1. Overview ............................................................................................... 35 2.4. Decision Tables in Spreadsheets ....................................................................... 40 2.4.1. When to Use Decision Tables ................................................................. 41 2.4.2. Overview ............................................................................................... 41 2.4.3. How Decision Tables Work ..................................................................... 43 2.4.4. Spreadsheet Syntax ............................................................................... 46 2.4.5. Creating and integrating Spreadsheet based Decision Tables .................... 55 2.4.6. Managing Business Rules in Decision Tables .......................................... 56 2.4.7. Rule Templates ...................................................................................... 57 2.5. Templates ........................................................................................................ 59 2.5.1. The Rule Template File .......................................................................... 60 2.5.2. Expanding a Template ............................................................................ 61 2.5.3. Example ................................................................................................ 63 2.6. More on building and deploying ......................................................................... 66 2.6.1. Knowledge Base by Configuration Using Changesets ............................... 66 2.6.2. Knowledge Agent ................................................................................... 67 2.7. Logging ............................................................................................................ 70 3. API Reference ............................................................................................................ 73 3.1. Building ............................................................................................................ 73 iii Drools Expert User Guide 3.1.1. Building Using Code ............................................................................... 73 3.1.2. Building Using Configuration and the ChangeSet XML .............................. 78 3.1.3. Changing the Default Build Result Severity .............................................. 81 3.2. Deploying ......................................................................................................... 82 3.2.1. KnowledgePackage and Knowledge Definitions ........................................ 82 3.2.2. KnowledgeBase ..................................................................................... 83 3.2.3. In-Process Building and Deployment ....................................................... 85 3.2.4. Building and Deployment in Separate Processes ...................................... 86 3.2.5. StatefulknowledgeSessions and KnowledgeBase Modifications ................. 87 3.2.6. KnowledgeAgent .................................................................................... 87 3.3. Running ............................................................................................................ 90 3.3.1. KnowledgeBase ..................................................................................... 90 3.3.2. StatefulKnowledgeSession ...................................................................... 91 3.3.3. KnowledgeRuntime ................................................................................. 91 3.3.4. Agenda .................................................................................................. 99 3.3.5. Event Model ......................................................................................... 103 3.3.6. KnowledgeRuntimeLogger .................................................................... 106 3.3.7. StatelessKnowledgeSession .................................................................. 106 3.3.8. Commands and the CommandExecutor ................................................. 110 3.3.9. Marshalling .......................................................................................... 118 3.3.10. Persistence and Transactions .............................................................. 120 3.3.11. Drools Clips ....................................................................................... 122 4. Rule Language Reference ........................................................................................ 125 4.1. Overview ........................................................................................................ 125 4.1.1. A rule file ............................................................................................. 125 4.1.2. What makes a rule ............................................................................... 126 4.2. Keywords ........................................................................................................ 126 4.3. Comments ...................................................................................................... 128 4.3.1. Single line comment ............................................................................. 128 4.3.2. Multi-line comment ............................................................................... 129 4.4. Error Messages .............................................................................................. 129 4.4.1. Message format ................................................................................... 129 4.4.2. Error Messages Description .................................................................. 130 4.4.3. Other Messages ................................................................................... 134 4.5. Package ......................................................................................................... 134 4.5.1. import .................................................................................................. 135 4.5.2. global .................................................................................................. 136 4.6. Function ......................................................................................................... 137 4.7. Type Declaration ............................................................................................. 138 4.7.1. Declaring New Types ........................................................................... 139 4.7.2. Declaring Metadata .............................................................................. 141 4.7.3. Declaring Metadata for Existing