[jboss-svn-commits] JBL Code SVN: r14974 - labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Sep 9 13:21:37 EDT 2007
Author: mark.proctor at jboss.com
Date: 2007-09-09 13:21:37 -0400 (Sun, 09 Sep 2007)
New Revision: 14974
Modified:
labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/Section-Examples.xml
Log:
-changed examples order.
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-09 16:06:09 UTC (rev 14973)
+++ labs/jbossrules/trunk/documentation/manual/en/Chapter-Examples/Section-Examples.xml 2007-09-09 17:21:37 UTC (rev 14974)
@@ -13,8 +13,194 @@
examples.</para>
<section>
+ <title>Hello World</title>
+
+ <programlisting><emphasis role="bold">Name:</emphasis> Hello World
+<emphasis role="bold">Main class:</emphasis> org.drools.examples.HelloWorldExample
+<emphasis role="bold">Type:</emphasis> java application
+<emphasis role="bold">Rules file:</emphasis> HelloWorld.drl
+<emphasis role="bold">Objective:</emphasis> demonstrate basic rules in use
+</programlisting>
+
+ <para>The "Hello World" example shows a simple example of rules usage, and
+ both the MVEL dialect and Java dialect. Lets take a quick look at the
+ rules.</para>
+
+ <example>
+ <title>HelloWorld example: rule "Hello World"</title>
+
+ <programlisting>rule "Hello World"
+ dialect "mvel"
+ when
+ m : Message( status == Message.HELLO, message : message )
+ then
+ System.out.println( message );
+ modify ( m ) { message = "Goodbyte cruel world",
+ status = Message.GOODBYE };
+end</programlisting>
+ </example>
+
+ <para>The <emphasis role="bold">LHS (when)</emphasis> section of the rule
+ states that it will be activated for each <emphasis>Message</emphasis>
+ object inserted into the working memory whose <emphasis>status</emphasis>
+ is <emphasis>Message.HELLO</emphasis>. Besides that, two variable binds
+ are created: "<emphasis>message</emphasis>" variable is bound to the
+ <emphasis>message</emphasis> attribute and "<emphasis>m</emphasis>"
+ variable is bound to the <emphasis>pattern</emphasis> itself.</para>
+
+ <para>The <emphasis role="bold">RHS (consequence, then)</emphasis> section
+ of the rule is written using the MVEL expression language, as declared by
+ the rule's attribute <emphasis>dialect</emphasis>. After printing the
+ content of the <emphasis>message</emphasis> bound variable to the default
+ console, the rule changes the values of the <emphasis>message</emphasis>
+ and <emphasis>status</emphasis> attributes of the <emphasis>m</emphasis>
+ bound variable; using MVEL's 'modify' keyword which allows you to apply a
+ block of setters in one statement, with the engine being automatically
+ notified of the changes at the end of the block.</para>
+
+ <example>
+ <title>HelloWorld example: rule "Good Bye"</title>
+
+ <programlisting>rule "Good Bye"
+ dialect "java"
+ when
+ Message( status == Message.GOODBYE, message : message )
+ then
+ System.out.println( message );
+end</programlisting>
+ </example>
+
+ <para>The "Good Bye" rule is similar to the "Hello World" but matches
+ Message objects whose status is Message.GOODBYE instead, printing its
+ message to the default console.</para>
+ </section>
+
+ <section>
+ <title>State Example</title>
+
+ <para>This example is actually implemented in three different versions to
+ demonstrate different ways of implementing the same basic behavior: rules
+ forward chaining, i.e., the ability the engine has to evaluate, activate
+ and fire rules in sequence, based on changes on the facts in the working
+ memory.</para>
+
+ <section>
+ <title>Understanding the State Example</title>
+
+ <para><programlisting><emphasis role="bold">Name:</emphasis> State Example
+<emphasis role="bold">Main class:</emphasis> org.drools.examples.StateExampleUsingSalience
+<emphasis role="bold">Type:</emphasis> java application
+<emphasis role="bold">Rules file:</emphasis> StateExampleUsingSalience.drl
+</programlisting>Each State class has fields for its name and its current
+ state (see org.drools.examples.State class). The two possible states for
+ each objects are:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>NOTRUN</para>
+ </listitem>
+
+ <listitem>
+ <para>FINISHED</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>In the example we have four objects: A, B, C and D. Initially all
+ are set to state NOTRUN. A Bootstrap rule fires setting A to state
+ FINISHED which then causes B to change to state FINISHED. C and D are
+ both dependent on B - causing a conflict which is resolved by setting
+ salience values.</para>
+
+ <para></para>
+
+ <para>Before digging into the differences between the examples, it is
+ important to note some common concepts to all examples.</para>
+
+ <para>The first important concept is the use of <emphasis
+ role="bold">dynamic facts</emphasis>. As mentioned previously in the
+ documentation, in order for the engine to see and react to fact's
+ properties change, the application must tell the engine that changes
+ occurred. This can be done explicitly in the rules, by calling the
+ <emphasis role="bold">update()</emphasis> memory action as seen in the
+ "Hello World" example, or implicitly by letting the engine know that the
+ facts implement PropertyChangeSupport as defined by the
+ <emphasis>Javabeans specification</emphasis>. This example demonstrates
+ how to use PropertyChangeSupport to avoid the need for explicit update()
+ calls in the rules. To make use of this feature, make sure your facts
+ implement the PropertyChangeSupport as the org.drools.example.State
+ class does and use the following code to insert the facts into the
+ working memory:</para>
+
+ <programlisting> // By setting dynamic to TRUE, Drools will use JavaBean
+ // PropertyChangeListeners so you don't have to call update().
+ final boolean dynamic = true;
+
+ session.insert( fact,
+ dynamic );
+</programlisting>
+
+ <para></para>
+
+ <para></para>
+ </section>
+
+ <section>
+ <title>State Example using Salience</title>
+
+ <para></para>
+
+ <para></para>
+
+ <para></para>
+ </section>
+ </section>
+
+ <section>
+ <title>Fibonacci Example</title>
+
+ <para></para>
+ </section>
+
+ <section>
+ <title>Golfing Example</title>
+
+ <para></para>
+ </section>
+
+ <section>
+ <title>Trouble Ticket</title>
+
+ <para></para>
+ </section>
+
+ <section>
+ <title>Pricing Rule DT Example</title>
+
+ <para></para>
+ </section>
+
+ <section>
+ <title>Shopping Example</title>
+
+ <para></para>
+ </section>
+
+ <section>
+ <title>Honest Politician Example</title>
+
+ <para></para>
+ </section>
+
+ <section>
<title>Sudoku Example</title>
+ <programlisting><emphasis role="bold">Name:</emphasis> Sudoku
+<emphasis role="bold">Main class:</emphasis> org.drools.examples.HelloWorldExample
+<emphasis role="bold">Type:</emphasis> java application
+<emphasis role="bold">Rules file:</emphasis> HelloWorld.drl
+<emphasis role="bold">Objective:</emphasis> demonstrate basic rules in use
+</programlisting>
+
<para>This example demonstrates how Drools can be used to find a solution
in a large potential solution space based on a number of constraints. We
use the popular puzzle of Sudoku. This example also shows how Drools can
@@ -463,185 +649,6 @@
</section>
<section>
- <title>Hello World</title>
-
- <programlisting><emphasis role="bold">Name:</emphasis> Hello World
-<emphasis role="bold">Main class:</emphasis> org.drools.examples.HelloWorldExample
-<emphasis role="bold">Type:</emphasis> java application
-<emphasis role="bold">Rules file:</emphasis> HelloWorld.drl
-<emphasis role="bold">Objective:</emphasis> demonstrate basic rules in use
-</programlisting>
-
- <para>The "Hello World" example shows a simple example of rules usage, and
- both the MVEL dialect and Java dialect. Lets take a quick look at the
- rules.</para>
-
- <example>
- <title>HelloWorld example: rule "Hello World"</title>
-
- <programlisting>rule "Hello World"
- dialect "mvel"
- when
- m : Message( status == Message.HELLO, message : message )
- then
- System.out.println( message );
- modify ( m ) { message = "Goodbyte cruel world",
- status = Message.GOODBYE };
-end</programlisting>
- </example>
-
- <para>The <emphasis role="bold">LHS (when)</emphasis> section of the rule
- states that it will be activated for each <emphasis>Message</emphasis>
- object inserted into the working memory whose <emphasis>status</emphasis>
- is <emphasis>Message.HELLO</emphasis>. Besides that, two variable binds
- are created: "<emphasis>message</emphasis>" variable is bound to the
- <emphasis>message</emphasis> attribute and "<emphasis>m</emphasis>"
- variable is bound to the <emphasis>pattern</emphasis> itself.</para>
-
- <para>The <emphasis role="bold">RHS (consequence, then)</emphasis> section
- of the rule is written using the MVEL expression language, as declared by
- the rule's attribute <emphasis>dialect</emphasis>. After printing the
- content of the <emphasis>message</emphasis> bound variable to the default
- console, the rule changes the values of the <emphasis>message</emphasis>
- and <emphasis>status</emphasis> attributes of the <emphasis>m</emphasis>
- bound variable; using MVEL's 'modify' keyword which allows you to apply a
- block of setters in one statement, with the engine being automatically
- notified of the changes at the end of the block.</para>
-
- <example>
- <title>HelloWorld example: rule "Good Bye"</title>
-
- <programlisting>rule "Good Bye"
- dialect "java"
- when
- Message( status == Message.GOODBYE, message : message )
- then
- System.out.println( message );
-end</programlisting>
- </example>
-
- <para>The "Good Bye" rule is similar to the "Hello World" but matches
- Message objects whose status is Message.GOODBYE instead, printing its
- message to the default console.</para>
- </section>
-
- <section>
- <title>State Example</title>
-
- <para>This example is actually implemented in three different versions to
- demonstrate different ways of implementing the same basic behavior: rules
- forward chaining, i.e., the ability the engine has to evaluate, activate
- and fire rules in sequence, based on changes on the facts in the working
- memory.</para>
-
- <section>
- <title>Understanding the State Example</title>
-
- <para><programlisting><emphasis role="bold">Name:</emphasis> State Example
-<emphasis role="bold">Main class:</emphasis> org.drools.examples.StateExampleUsingSalience
-<emphasis role="bold">Type:</emphasis> java application
-<emphasis role="bold">Rules file:</emphasis> StateExampleUsingSalience.drl
-</programlisting>Each State class has fields for its name and its current
- state (see org.drools.examples.State class). The two possible states for
- each objects are:</para>
-
- <itemizedlist>
- <listitem>
- <para>NOTRUN</para>
- </listitem>
-
- <listitem>
- <para>FINISHED</para>
- </listitem>
- </itemizedlist>
-
- <para>In the example we have four objects: A, B, C and D. Initially all
- are set to state NOTRUN. A Bootstrap rule fires setting A to state
- FINISHED which then causes B to change to state FINISHED. C and D are
- both dependent on B - causing a conflict which is resolved by setting
- salience values.</para>
-
- <para></para>
-
- <para>Before digging into the differences between the examples, it is
- important to note some common concepts to all examples.</para>
-
- <para>The first important concept is the use of <emphasis
- role="bold">dynamic facts</emphasis>. As mentioned previously in the
- documentation, in order for the engine to see and react to fact's
- properties change, the application must tell the engine that changes
- occurred. This can be done explicitly in the rules, by calling the
- <emphasis role="bold">update()</emphasis> memory action as seen in the
- "Hello World" example, or implicitly by letting the engine know that the
- facts implement PropertyChangeSupport as defined by the
- <emphasis>Javabeans specification</emphasis>. This example demonstrates
- how to use PropertyChangeSupport to avoid the need for explicit update()
- calls in the rules. To make use of this feature, make sure your facts
- implement the PropertyChangeSupport as the org.drools.example.State
- class does and use the following code to insert the facts into the
- working memory:</para>
-
- <programlisting> // By setting dynamic to TRUE, Drools will use JavaBean
- // PropertyChangeListeners so you don't have to call update().
- final boolean dynamic = true;
-
- session.insert( fact,
- dynamic );
-</programlisting>
-
- <para></para>
-
- <para></para>
- </section>
-
- <section>
- <title>State Example using Salience</title>
-
- <para></para>
-
- <para></para>
-
- <para></para>
- </section>
- </section>
-
- <section>
- <title>Fibonacci Example</title>
-
- <para></para>
- </section>
-
- <section>
- <title>Golfing Example</title>
-
- <para></para>
- </section>
-
- <section>
- <title>Trouble Ticket</title>
-
- <para></para>
- </section>
-
- <section>
- <title>Pricing Rule DT Example</title>
-
- <para></para>
- </section>
-
- <section>
- <title>Shopping Example</title>
-
- <para></para>
- </section>
-
- <section>
- <title>Honest Politician Example</title>
-
- <para></para>
- </section>
-
- <section>
<title>Conways Game of Life</title>
<para></para>
More information about the jboss-svn-commits
mailing list