<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Drools_introduction</id>
	<title>Drools introduction - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Drools_introduction"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Drools_introduction&amp;action=history"/>
	<updated>2026-04-19T09:29:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=Drools_introduction&amp;diff=68524&amp;oldid=prev</id>
		<title>Fstachecki: /* Rule Engine ⌘ */</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Drools_introduction&amp;diff=68524&amp;oldid=prev"/>
		<updated>2018-09-11T10:15:56Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Rule Engine ⌘&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Drools Filip|00]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;noprint&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;slideshow style=&amp;quot;nobleprog&amp;quot; headingmark=&amp;quot;⌘&amp;quot; incmark=&amp;quot;…&amp;quot; scaled=&amp;quot;false&amp;quot; font=&amp;quot;Trebuchet MS&amp;quot; headingmark2=&amp;quot;。&amp;quot; lang=&amp;quot;中文版&amp;quot; &amp;gt;&lt;br /&gt;
;title: Drools introduction&lt;br /&gt;
;author: &amp;lt;br/&amp;gt;安博 Bernard Szlachta (bs@nobleprog.com), Filip Stachecki (filip@nobleprog.pl)&lt;br /&gt;
&amp;lt;/slideshow&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Can I use your material}} &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Drools=&lt;br /&gt;
== Approaches to Business Analysis and Design⌘ ==&lt;br /&gt;
* Data First (RDMS)&lt;br /&gt;
** first approach to analysis focused on data&lt;br /&gt;
* Object Orientation (OOP)&lt;br /&gt;
** business logic was mixed up with data&lt;br /&gt;
* Processes First (BPMS)&lt;br /&gt;
** process management tools allowed analysts to create executable process models&lt;br /&gt;
* Rules First (BRMS)&lt;br /&gt;
** having rules and processes, a person can derive everything else&lt;br /&gt;
&lt;br /&gt;
==Business Rule Approach⌘==&lt;br /&gt;
===Terms and Business Rules vocabulary⌘===&lt;br /&gt;
* A &amp;#039;&amp;#039;&amp;#039;term&amp;#039;&amp;#039;&amp;#039; is a noun or noun phrase that workers recognize and use in business communications of all kinds (in agreements, deals, licenses, certifications, warranties, manuals, ...)&lt;br /&gt;
* A term carries a particular meaning for the business, which should be unambiguous given a particular context of usage (e.g. customer, order, invoice, employee)&lt;br /&gt;
* A term is a word or expression that has a precisely limited meaning in some uses or is peculiar to a science, art, profession, trade, or special subject&lt;br /&gt;
* Every term requires a careful definition:&lt;br /&gt;
** Customer: one that purchases some commodity or service; especially, one that purchases systematically or frequently&lt;br /&gt;
&lt;br /&gt;
===Terms⌘===&lt;br /&gt;
Term should be:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Basic&amp;#039;&amp;#039;&amp;#039; (should represent something fundamental to business, cannot be derived)&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Countable&amp;#039;&amp;#039;&amp;#039; (a thing whose instances can be counted - employee instead of staff)&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Non-procedural&amp;#039;&amp;#039;&amp;#039; (term is about knowledge, not about the actions)&lt;br /&gt;
&lt;br /&gt;
The collection of all terms and definitions are the core part of a business vocabulary. &lt;br /&gt;
&lt;br /&gt;
Such terms are crucial for expressing business rules effectively.&lt;br /&gt;
&lt;br /&gt;
===Fact Types⌘===&lt;br /&gt;
* Connections between terms are expressed using verbs and verb phrases - &amp;#039;&amp;#039;&amp;#039;fact types&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
* Fact type &amp;quot;customer places order&amp;quot; can be used in BR &amp;quot;A customer has always placed at least one order.&amp;quot;&lt;br /&gt;
* Fact types extend business vocabulary:&lt;br /&gt;
** add standard verbs and verb phrases&lt;br /&gt;
** by connecting terms they bring structure to the vocabulary&lt;br /&gt;
* At least one term can be involved in connections:&lt;br /&gt;
** person smokes (one term)&lt;br /&gt;
** customer places order (two terms - a majority of connections)&lt;br /&gt;
** person visits city on date (three terms)&lt;br /&gt;
&lt;br /&gt;
===Graphical Concept Models⌘===&lt;br /&gt;
[[File:ClipCapIt-140905-142125.PNG|500px]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;Ronald Ross, Business Rule Concepts: Getting to the Point of Knowledge, Figure 1-1, simple concept model in graphical form&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Business Rules⌘===&lt;br /&gt;
[[File:ClipCapIt-140905-143445.PNG]]&lt;br /&gt;
* Rules are familiar to us all in real life. &lt;br /&gt;
* We play games by rules, we live under a legal system based on rules, we set rules for our children, and so on.&lt;br /&gt;
* Thinking about the control aspect of any organized activity in terms of rules is actually very natural (try explaining any game without explaining the rules the game is based).&lt;br /&gt;
&lt;br /&gt;
====What is a Business Rule?⌘====&lt;br /&gt;
The SBVR follows a common-sense definition of ‘business rule’:&lt;br /&gt;
 Business Rule: rule that is under business jurisdiction&lt;br /&gt;
*‘Under business jurisdiction’ means that the business can enact, revise, and discontinue their business rules as they see fit.&lt;br /&gt;
* If a rule is not under business jurisdiction in that sense, then it is not a business rule. &lt;br /&gt;
* For example, the ‘law’ of gravity is obviously not a business rule. Neither are the ‘rules’ of mathematics.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
====Two categories of Rules⌘====&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Structural Rule&amp;#039;&amp;#039;&amp;#039; (aka Definitional): a business rule can be ill-conceived, misunderstood or misapplied, but it cannot be violated directly.&lt;br /&gt;
** Necessity or impossibility&lt;br /&gt;
*** Associate Trainer is a trainer who signed Associate Trainer Agreement&lt;br /&gt;
*** Premium Customer is a customer who orders more than $1mln in a calendar year&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Operative Rule&amp;#039;&amp;#039;&amp;#039; (aka Behavioural): A business rule that can be violated directly.&lt;br /&gt;
** Obligation or prohibition&lt;br /&gt;
*** e.g. Every employee must sign employment agreement&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Business Rule “Mantra”⌘====&lt;br /&gt;
 “Rules are based on facts, and facts are based on terms.”&lt;br /&gt;
&amp;lt;table border=&amp;quot;0&amp;quot; cellpadding=&amp;quot;10&amp;quot; cellspacing=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;
		&amp;lt;tr&amp;gt;&lt;br /&gt;
			&amp;lt;td&amp;gt;[[File:RuleFactTerm.png]]&amp;lt;/td&amp;gt;&lt;br /&gt;
			&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Terms&amp;#039;&amp;#039;&amp;#039;&amp;lt;br/&amp;gt;&lt;br /&gt;
*Employee&lt;br /&gt;
*Employee number&lt;br /&gt;
*Car&lt;br /&gt;
*Car registration number&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Facts&amp;#039;&amp;#039;&amp;#039;&amp;lt;br/&amp;gt;&lt;br /&gt;
*Car has car registration number&lt;br /&gt;
*Employee drives car&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Rules&amp;#039;&amp;#039;&amp;#039;&amp;lt;br/&amp;gt;&lt;br /&gt;
*Each employee must be uniquely identifiable.&lt;br /&gt;
* Each car always has exactly one car registration number.&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Exercise ⌘====&lt;br /&gt;
# For a Pizza Company, create a fact model&lt;br /&gt;
# Write a couple of rules a Pizza Company can have based on the fact model&lt;br /&gt;
[[Pizza Rules Sample Answer]]&lt;br /&gt;
&lt;br /&gt;
===Business Rules Approach architecture⌘===&lt;br /&gt;
[[File:ClipCapIt-150708-132606.PNG]]&lt;br /&gt;
&lt;br /&gt;
== Artificial Intelligence ⌘==&lt;br /&gt;
[[File:Drools-ai.jpg]]&lt;br /&gt;
&amp;lt;!-- * Neural Networks, Genetic Algorithms, Decision Trees, Frame Systems and Expert Systems --&amp;gt;&lt;br /&gt;
* Expert Systems are also known as Knowledge-based Systems and Knowledge-based Expert Systems &lt;br /&gt;
* Drools is a Rule Engine that uses the rule-based approach to implement an Expert System and is more correctly classified as a Production Rule System.&lt;br /&gt;
&lt;br /&gt;
== Rule Engine ⌘==&lt;br /&gt;
:[[File:Drools-ruleengine.PNG]]&lt;br /&gt;
&amp;lt;p style=&amp;quot;font-size:10px&amp;quot;&amp;gt;Drools documentation, Figure 1.1. High-level View of a Rule Engine&amp;lt;/p&amp;gt;&lt;br /&gt;
* The &amp;#039;&amp;#039;&amp;#039;Rules&amp;#039;&amp;#039;&amp;#039; are stored in the Production Memory&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Facts&amp;#039;&amp;#039;&amp;#039; that the &amp;#039;&amp;#039;&amp;#039;Inference Engine&amp;#039;&amp;#039;&amp;#039; matches against are kept in the &amp;#039;&amp;#039;&amp;#039;Working Memory&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
* Facts are asserted into the Working Memory where they may then be &amp;#039;&amp;#039;&amp;#039;modified&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;retracted&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
* A system with a large number of rules and facts may result in many rules being true for the same fact assertion; these rules are said &amp;#039;&amp;#039;&amp;#039;to be in conflict&amp;#039;&amp;#039;&amp;#039;. &lt;br /&gt;
* The &amp;#039;&amp;#039;&amp;#039;Agenda&amp;#039;&amp;#039;&amp;#039; manages the execution order of these conflicting rules using a &amp;#039;&amp;#039;&amp;#039;Conflict Resolution&amp;#039;&amp;#039;&amp;#039; strategy.&lt;br /&gt;
&lt;br /&gt;
=== Advantages of a Rule Engine ⌘===&lt;br /&gt;
* Declarative Programming (&amp;quot;What&amp;quot;, not &amp;quot;How&amp;quot;)&lt;br /&gt;
* Explanation Facility - we can see &amp;quot;how&amp;quot; engine solved the problem  &lt;br /&gt;
* Logic and Data Separation (breaking OO coupling of data and logic)&lt;br /&gt;
* Speed and Scalability (Rete, Leaps, PHREAK)&lt;br /&gt;
* Centralization of Knowledge (Documentation)&lt;br /&gt;
* Tool Integration&lt;br /&gt;
* Understandable Rules (DSL)&lt;br /&gt;
&lt;br /&gt;
=== When should you use RE? ⌘===&lt;br /&gt;
* The problem may not be complex but there is no non-fragile way of building a solution for it&lt;br /&gt;
* The problem is beyond any obvious algorithmic solution&lt;br /&gt;
* The logic changes often&lt;br /&gt;
* Domain experts (or business analysts) are readily available, but are nontechnical&lt;br /&gt;
* There are too many rules to manage them in the code&lt;br /&gt;
* We need rules to be explicit and documented&lt;br /&gt;
&lt;br /&gt;
=== When shouldn&amp;#039;t you use RE? ⌘===&lt;br /&gt;
* Maintaining the infrastructure is more expensive than the gains&lt;br /&gt;
* With system which hardly ever change&lt;br /&gt;
* There is no person understanding RE&lt;br /&gt;
&lt;br /&gt;
=== Alternatives to Rule Engine ⌘===&lt;br /&gt;
* Scripting  &lt;br /&gt;
* Decision Tables (Lookup tables, DMN) &lt;br /&gt;
* Other data-driven solutions&lt;br /&gt;
&amp;lt;!-- &lt;br /&gt;
&lt;br /&gt;
===Reasoning Systems ⌘===&lt;br /&gt;
There are two main types of reasoning:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;forward chaining&amp;#039;&amp;#039;&amp;#039; (data driven)&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;backward chaining&amp;#039;&amp;#039;&amp;#039; (goal-driven)&lt;br /&gt;
&lt;br /&gt;
===Forward vs Backward Chaining⌘===&lt;br /&gt;
[[File:ClipCapIt-150708-163424.PNG]]&lt;br /&gt;
FORWARD CHAINING = Data Driven Approach&lt;br /&gt;
BACKWARD CHAINING = Goal-Driven Approach&lt;br /&gt;
Drools is Hybrid Reasoning Systems (HRS) --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What are Rules ⌘==&lt;br /&gt;
Rules are the guidelines which instruct people &amp;#039;&amp;#039;&amp;#039;what&amp;#039;&amp;#039;&amp;#039; to do &amp;#039;&amp;#039;&amp;#039;when&amp;#039;&amp;#039;&amp;#039; certain conditions happen&lt;br /&gt;
&lt;br /&gt;
=== Rules Examples ⌘===&lt;br /&gt;
* When the booking form arrives, then we send the confirmation letter&lt;br /&gt;
* When there are no bookings 14 days before the course commences, then we cancel the course&lt;br /&gt;
&lt;br /&gt;
=== Rules Syntax ⌘===&lt;br /&gt;
 When (if)        Then&lt;br /&gt;
 Condition        Action&lt;br /&gt;
 Left side        Right side&lt;br /&gt;
 LHS              RHS&lt;br /&gt;
&lt;br /&gt;
 Example          &lt;br /&gt;
 if it rains      take an umbrella&lt;br /&gt;
&lt;br /&gt;
=== Rules Syntax ⌘===&lt;br /&gt;
:[[File:ClipCapIt-150708-182520.PNG]]&lt;br /&gt;
&lt;br /&gt;
 Rule &amp;quot;Next delegate discount&amp;quot;&lt;br /&gt;
   When&lt;br /&gt;
      $NumberOfDelegates &amp;gt; 1&lt;br /&gt;
   Then&lt;br /&gt;
      $Price = $Price - $Price*($numberOfDelegates-1)*10%&lt;br /&gt;
 End&lt;br /&gt;
===Domain Specific Language Rules⌘===&lt;br /&gt;
:[[File:ClipCapIt-171026-120855.PNG]]&lt;br /&gt;
* DSL is a way non-technical people can write &amp;#039;&amp;#039;&amp;#039;executable&amp;#039;&amp;#039;&amp;#039; rules in Drools environment&lt;br /&gt;
* DSL is ultimately transformed to rules (mvel or java)&lt;br /&gt;
* .dsl file contain the transformations (mapping)&lt;br /&gt;
&lt;br /&gt;
== The Business Rules Manifesto ⌘==&lt;br /&gt;
http://www.businessrulesgroup.org/brmanifesto.htm&lt;br /&gt;
 Rules are not process and not procedure.  They should not be contained in either of these.&lt;br /&gt;
&lt;br /&gt;
 Rules build on facts, and facts build on concepts as expressed by terms.&lt;br /&gt;
&lt;br /&gt;
 If something cannot be expressed, then it is not a rule.&lt;br /&gt;
&lt;br /&gt;
 Business rules should be expressed in such a way that they can be validated for correctness by business people.&lt;br /&gt;
&lt;br /&gt;
 Exceptions to rules are expressed by other rules.&lt;/div&gt;</summary>
		<author><name>Fstachecki</name></author>
	</entry>
</feed>