[jboss-svn-commits] JBL Code SVN: r15257 - labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Sep 20 03:52:01 EDT 2007
Author: michael.neale at jboss.com
Date: 2007-09-20 03:52:01 -0400 (Thu, 20 Sep 2007)
New Revision: 15257
Added:
labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/DT_Config.png
labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/DT_Table1.png
labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/DT_Table2.png
Modified:
labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/Section-Examples.xml
Log:
DT documentation
Added: labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/DT_Config.png
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/DT_Config.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/DT_Table1.png
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/DT_Table1.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/DT_Table2.png
===================================================================
(Binary files differ)
Property changes on: labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/DT_Table2.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/Section-Examples.xml
===================================================================
--- labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/Section-Examples.xml 2007-09-20 06:01:25 UTC (rev 15256)
+++ labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/Section-Examples.xml 2007-09-20 07:52:01 UTC (rev 15257)
@@ -1081,9 +1081,129 @@
<!-- Trouble Ticket example -->
<section>
- <title>Pricing Rule DT Example</title>
+ <title>Pricing Rule Decision Table Example</title>
- <para></para>
+ <para>The Pricing Rule decision table demonstrates the use of a decision
+ table in a spreadsheet (XLS format) in calculating the retail cost of an
+ insurance policy. The purpose of the set of rules provided is to calculate
+ a base price, and an additional discount for a car driver applying for a
+ specific policy. The drivers age, history and the policy type all
+ contribute to what the basic premium is, and an additional chunk of rules
+ deals with refining this with a subtractive percentage discount.</para>
+
+ <programlisting><emphasis role="bold">Name:</emphasis> Example Policy Pricing
+ <emphasis role="bold">Main class:</emphasis> org.drools.examples.PricingRuleDTExample
+ <emphasis role="bold">Type:</emphasis> java application
+ <emphasis role="bold">Rules file:</emphasis> ExamplePolicyPricing.xls
+ <emphasis role="bold">Objective:</emphasis> demonstrate spreadsheet based decision tables.
+ </programlisting>
+
+ <section>
+ <title>Executing the example</title>
+
+ <para>Open the PricingRuleDTExample.java and execute it as a Java
+ application. It should produce the following console output:</para>
+
+ <programlisting>Cheapest possible
+BASE PRICE IS: 120
+DISCOUNT IS: 20 </programlisting>
+
+ <para>The code to the execute the example is very similar to the other
+ examples. The rules are loaded, the facts inserted and a stateless
+ session is used. What is different is how the rules are obtained:</para>
+
+ <programlisting>SpreadsheetCompiler compiler = new SpreadsheetCompiler();
+String drl = compiler.compile(getSpreadsheetStream(), InputType.XLS);
+</programlisting>
+
+ <para>Note the use of the SpreadsheetCompiler class. It is what takes
+ the XLS (as a binary InputStream to the XLS file), and outputs ordinary
+ DRL (which is then dealt with in the usual way). You can (if you like)
+ also print out the DRL. If you use the BRMS, all this is of course taken
+ care of for you.</para>
+
+ <para>There are 2 facts used in this example, Driver, and Policy. Both
+ are used with their default values. The Driver is 30 years old, has had
+ no prior claims and currently has a risk profile of LOW. The Policy
+ being applied for is COMPREHENSIVE, and the policy has not yet been
+ approved.</para>
+ </section>
+
+ <section>
+ <title>The decision table</title>
+
+ <para>In this decision table, each row is a rule, and each column is a
+ condition or an action.</para>
+
+ <figure>
+ <title>Decision table configuration</title>
+
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="DT_Config.png" />
+ </imageobject>
+ </mediaobject>
+ </figure>
+
+ <para>Referring to the above, we have the RuleSet declaration, which
+ provides the package name. There are also other optional items you can
+ have here, such as Variables for global variables, and Imports for
+ importing classes. In this case, the namespace of the rules is the same
+ as the fact classes we are using, so we can omit it.</para>
+
+ <para>Moving further down, we can see the RuleTable declaration. The
+ name after this (Pricing bracket) is used as the prefix for all the
+ generated rules. Below that, we have CONDITION or ACTION - this
+ indicates the purpose of the column (ie does it form part of the
+ condition, or an action of a rule that will be generated).</para>
+
+ <para>You can see there is a Driver which is spanned across 3 cells,
+ this means the template expressions below it apply to that fact. So we
+ look at the drivers age range (which uses $1 and $2 with comma separated
+ values), locationRiskProfile, and priorClaims in the respective columns.
+ In the action columns, we are setting the policy base price, and then
+ logging a message.</para>
+
+ <figure>
+ <title>Base price calculation</title>
+
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="DT_Table1.png" />
+ </imageobject>
+ </mediaobject>
+ </figure>
+
+ <para>Referring to the above, we can see there are broad category
+ brackets (indicated by the comment in the left most column). As we know
+ the details of our driver and their policy, we can tell (with a bit of
+ thought) that they should match row number 18, as they have no prior
+ accidents, and are 30 years old. This gives us a base price of
+ 120.</para>
+
+ <figure>
+ <title>Discount calculation</title>
+
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="DT_Table2.png" />
+ </imageobject>
+ </mediaobject>
+ </figure>
+
+ <para>Referring to the above, we are seeing if there is any discount we
+ can give our driver. Based on the Age bracket, number of priot claims,
+ and the policy type, a discount is provided. In our case, the drive is
+ 3, with no priors, and they are applying for COMPREHENSIVE, this means
+ we can give a discount of 20%. Note that this is actually a separate
+ table, but in the same worksheet. This different templates apply.</para>
+
+ <para>It is important to note that decision tables generate rules, this
+ means they aren't simply top down logic, but more a means to capture
+ data that generate rules (this is a subtle difference that confuses some
+ people). The evaluation of the rules is not "top down" necessarily, all
+ the normal indexing and mechanics of the rule engine still apply.</para>
+ </section>
</section>
<section>
More information about the jboss-svn-commits
mailing list