[jboss-svn-commits] JBL Code SVN: r19410 - labs/jbossrules/branches/irooskov_docs/drools-docs/drools-docs-referenceguide/en/Chapter-Rule_Language.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Apr 4 01:47:38 EDT 2008
Author: irooskov at redhat.com
Date: 2008-04-04 01:47:38 -0400 (Fri, 04 Apr 2008)
New Revision: 19410
Modified:
labs/jbossrules/branches/irooskov_docs/drools-docs/drools-docs-referenceguide/en/Chapter-Rule_Language/Section-Rule.xml
Log:
updated with corrections while going through reference guide
Modified: labs/jbossrules/branches/irooskov_docs/drools-docs/drools-docs-referenceguide/en/Chapter-Rule_Language/Section-Rule.xml
===================================================================
--- labs/jbossrules/branches/irooskov_docs/drools-docs/drools-docs-referenceguide/en/Chapter-Rule_Language/Section-Rule.xml 2008-04-04 01:21:08 UTC (rev 19409)
+++ labs/jbossrules/branches/irooskov_docs/drools-docs/drools-docs-referenceguide/en/Chapter-Rule_Language/Section-Rule.xml 2008-04-04 05:47:38 UTC (rev 19410)
@@ -306,7 +306,7 @@
</mediaobject>
</figure>
- <para>At the top of the ER diagram you can see that the pattern consists
+ <para>At the top of the ER diagram it can be seen that the pattern consists
of zero or more constraints and has an optional pattern binding. The
rail road diagram below shows the syntax for this.</para>
@@ -332,14 +332,14 @@
</example>
<para>To be able to refer to the matched object use a pattern binding
- variable such as '$c'. While this example variable is prefixed with a $
+ variable such as <emphasis>$c</emphasis>. While this example variable is prefixed with a $
symbol, it is optional, but can be useful in complex rules as it helps
- to more easily differentiation between variables and fields.</para>
+ to more easily differentiate between variables and fields.</para>
<example>
<title>Pattern</title>
- <programlisting>$c : Cheese( )</programlisting>
+<screen>$c : Cheese( )</screen>
</example>
<para>Inside of the Pattern parenthesis is where all the action happens.
@@ -385,8 +385,8 @@
It has an implicit 'and' connective semantics.<example>
<title>Constraint Group connective ','</title>
- <programlisting># Cheese type is stilton and price < 10 and age is mature.
-Cheese( type == "stilton", price < 10, age == "mature" )</programlisting>
+<screen># Cheese type is stilton and price < 10 and age is mature.
+Cheese( type == "stilton", price < 10, age == "mature" )</screen>
</example>The above example has 3 constraint groups, each with a
single constraint:</para>
@@ -410,8 +410,8 @@
<example>
<title>&& and || Constraint Connectives</title>
- <programlisting>Cheese( type == "stilton" && price < 10, age == "mature" ) // Cheese type is "stilton" and price < 10, and age is mature
-Cheese( type == "stilton" || price < 10, age == "mature" ) // Cheese type is "stilton" or price < 10, and age is mature</programlisting>
+<screen>Cheese( type == "stilton" && price < 10, age == "mature" ) // Cheese type is "stilton" and price < 10, and age is mature
+Cheese( type == "stilton" || price < 10, age == "mature" ) // Cheese type is "stilton" or price < 10, and age is mature</screen>
</example>
<para>The above example has two constraint groups. The first has 2
@@ -440,8 +440,8 @@
<para><example>
<title>Using parenthesis to change evaluation priority</title>
- <programlisting># Cheese type is stilton and ( price is less than 20 or age is mature ).
-Cheese( type == "stilton" && ( price < 20 || age == "mature" ) ) </programlisting>
+<screen># Cheese type is stilton and ( price is less than 20 or age is mature ).
+Cheese( type == "stilton" && ( price < 20 || age == "mature" ) ) </screen>
</example>In the above example, the use of parenthesis makes the ||
connective be evaluated before the && connective.</para>
@@ -453,8 +453,8 @@
<example>
<title>Not Equivalent connectives</title>
- <programlisting>Cheese( ( type == "stilton", price < 10 ) || age == "mature" ) // invalid as ',' cannot be embedded in an expression
-Cheese( ( type == "stilton" && price < 10 ) || age == "mature") // valid as '&&' can be embedded in an expression</programlisting>
+<screen>Cheese( ( type == "stilton", price < 10 ) || age == "mature" ) // invalid as ',' cannot be embedded in an expression
+Cheese( ( type == "stilton" && price < 10 ) || age == "mature") // valid as '&&' can be embedded in an expression</screen>
</example>
<section>
@@ -496,7 +496,7 @@
<para>A field is an accessible method on the object. If your model
objects follow the Java bean pattern, then fields are exposed using
"getXXX" or "isXXX" methods (these are methods that take no
- arguments, and return something). You can access fields either by
+ arguments, and return something). Fields can be accessed either by
using the bean-name convention (so "getType" can be accessed as
"type") - we use the standard jdk Introspector class to do this
mapping.</para>
@@ -505,10 +505,9 @@
Cheese(type == ...) uses the getType() method on the a cheese
instance. If a field name cannot be found it will resort to calling
the name as a no argument method; "toString()" on the Object for
- instance can be used with Cheese(toString == ..) - you use the full
- name of the method with correct capitalization, but not brackets. Do
- please make sure that you are accessing methods that take no
- parameters, and are in-fact "accessors" (as in, they don't change
+ instance can be used with Cheese(toString == ..) - use the full
+ name of the method with correct capitalization, but not brackets. Make sure that to access methods that take no
+ parameters, and are in-fact <emphasis>accessors</emphasis> (as in, they don't change
the state of the object in a way that may effect the rules -
remember that the rule engine effectively caches the results of its
matching in between invocations to make it faster).</para>
@@ -565,8 +564,8 @@
</mediaobject>
</figure>
- <para>You can do checks against fields that are or maybe null, using
- == and != as you would expect, and the literal "null" keyword, like:
+ <para>Checks can be performed against fields that are or might be null, using
+ == and != as would be expected, and the literal "null" keyword, like:
Cheese(type != null). If a field is null the evaluator will not
throw an exception and will only return true if the value is a null
check. Coercion is always attempted if the field and the value are
@@ -628,7 +627,7 @@
<example>
<title>Regular Expression Constraint</title>
- <programlisting>Cheese( type matches "(Buffalo)?\S*Mozerella" )</programlisting>
+<screen>Cheese( type matches "(Buffalo)?\S*Mozerella" )</screen>
</example>
</simplesect>
@@ -641,14 +640,14 @@
fields. Returns true when the match is false. Typically that
regexp is a String, but variables that resolve to a valid regexp
are also allowed.It is important to note that
- <emphasis>different from Java</emphasis>, if you write a String
- regexp directly on the source file, <emphasis>you don't need to
+ <emphasis>different from Java</emphasis>, when writing a String
+ regexp directly on the source file, <emphasis>there is no need to
escape '\'</emphasis>. Example:</para>
<example>
<title>Regular Expression Constraint</title>
- <programlisting>Cheese( type not matches "(Buffulo)?\S*Mozerella" )</programlisting>
+<screen>Cheese( type not matches "(Buffulo)?\S*Mozerella" )</screen>
</example>
</simplesect>
@@ -664,8 +663,8 @@
<example>
<title>Contains with Collections</title>
- <programlisting>CheeseCounter( cheeses contains "stilton" ) // contains with a String literal
-CheeseCounter( cheeses contains $var ) // contains with a variable</programlisting>
+<screen>CheeseCounter( cheeses contains "stilton" ) // contains with a String literal
+CheeseCounter( cheeses contains $var ) // contains with a variable</screen>
</example>
</simplesect>
@@ -681,8 +680,8 @@
<example>
<title>Literal Constraints with Collections</title>
- <programlisting>CheeseCounter( cheeses not contains "cheddar" ) // not contains with a String literal
-CheeseCounter( cheeses not contains $var ) // not contains with a variable</programlisting>
+<screen>CheeseCounter( cheeses not contains "cheddar" ) // not contains with a String literal
+CheeseCounter( cheeses not contains $var ) // not contains with a variable</screen>
<blockquote>
<para><emphasis role="bold">NOTE: </emphasis>for backward
@@ -704,7 +703,7 @@
<example>
<title>Literal Constraints with Collections</title>
- <programlisting>CheeseCounter( cheese memberOf $matureCheeses )</programlisting>
+<screen>CheeseCounter( cheese memberOf $matureCheeses )</screen>
</example>
</simplesect>
@@ -718,7 +717,7 @@
<example>
<title>Literal Constraints with Collections</title>
- <programlisting>CheeseCounter( cheese not memberOf $matureCheeses )</programlisting>
+<screen>CheeseCounter( cheese not memberOf $matureCheeses )</screen>
</example>
</simplesect>
@@ -733,7 +732,7 @@
<example>
<title>Text with soundslike (Sounds Like)</title>
- <programlisting>Cheese( name soundslike 'foobar' )</programlisting>
+<screen>Cheese( name soundslike 'foobar' )</screen>
<para>This will match a cheese with a name of "fubar"</para>
</example>
@@ -770,15 +769,14 @@
<example>
<title>Numeric Literal Restriction</title>
- <programlisting>Cheese( quantity == 5 )</programlisting>
+<screen>Cheese( quantity == 5 )</screen>
</example>
</simplesect>
<simplesect>
<title>Date</title>
- <para>The date format "dd-mmm-yyyy" is supported by default. You
- can customize this by providing an alternative date format mask
+ <para>The date format "dd-mmm-yyyy" is supported by default. This can be customized by providing an alternative date format mask
as a System property ("drools.dateformat" is the name of the
property). If more control is required, use the inline-eval
constraint.</para>
@@ -786,7 +784,7 @@
<example>
<title>Date Literal Restriction</title>
- <programlisting>Cheese( bestBefore < "27-Oct-2007" )</programlisting>
+<screen>Cheese( bestBefore < "27-Oct-2007" )</screen>
</example>
</simplesect>
@@ -798,7 +796,7 @@
<example>
<title>String Literal Restriction</title>
- <programlisting>Cheese( type == "stilton" )</programlisting>
+<screen>Cheese( type == "stilton" )</screen>
</example>
</simplesect>
@@ -812,7 +810,7 @@
<example>
<title>Boolean Literal Restriction</title>
- <programlisting>Cheese( smelly == true )</programlisting>
+<screen>Cheese( smelly == true )</screen>
</example>
</simplesect>
@@ -826,7 +824,7 @@
<example>
<title>Boolean Literal Restriction</title>
- <programlisting>Cheese( smelly == SomeClass.TRUE )</programlisting>
+ <screen>Cheese( smelly == SomeClass.TRUE )</screen>
</example>
</simplesect>
</section>
@@ -859,8 +857,9 @@
<example>
<title>Bound Field using '==' operator</title>
- <programlisting>Person( likes : favouriteCheese )
-Cheese( type == likes )</programlisting>
+<screen>Person( likes : favouriteCheese )
+Cheese( type == likes )
+</screen>
<para>'likes' is our variable, our Declaration, that is bound to
the favouriteCheese field for any matching Person instance and
@@ -876,8 +875,9 @@
<example>
<title>Bound Fact using 'contains' operator</title>
- <programlisting>$stilton : Cheese( type == "stilton" )
-Cheesery( cheeses contains $stilton )</programlisting>
+<screen>$stilton : Cheese( type == "stilton" )
+Cheesery( cheeses contains $stilton )
+</screen>
</example>
</section>
@@ -906,9 +906,9 @@
<example>
<title>Return Value Restriction</title>
- <programlisting>Person( girlAge : age, sex == "F" )
+<screen>Person( girlAge : age, sex == "F" )
Person( age == ( girlAge + 2) ), sex == 'M' )
-</programlisting>
+</screen>
</example>
</section>
</section>
@@ -917,10 +917,10 @@
<title>Compound Value Restriction</title>
<para>The compound value restriction is used where there is more
- than one possible value, currently only the 'in' and 'not in'
+ than one possible value, currently only the <emphasis>in</emphasis> and <emphasis>not in</emphasis>
evaluators support this. The operator takes a parenthesis enclosed
comma separated list of values, which can be a variable, literal,
- return value or qualified identifier. The 'in' and 'not in'
+ return value or qualified identifier. The <emphasis>in</emphasis> and <emphasis>not in</emphasis>
evaluators are actually sugar and are rewritten as a multi
restriction list of != and == restrictions.</para>
@@ -941,9 +941,9 @@
<example>
<title>Compound Restriction using 'in'</title>
- <programlisting>Person( $cheese : favouriteCheese )
+<screen>Person( $cheese : favouriteCheese )
Cheese( type in ( "stilton", "cheddar", $cheese )
-</programlisting>
+</screen>
</example>
</section>
@@ -982,9 +982,10 @@
<example>
<title>Multi Restriction</title>
- <programlisting>Person( age > 30 && < 40 ) // simple multi restriction using a single &&
+<screen>Person( age > 30 && < 40 ) // simple multi restriction using a single &&
Person( age ( (> 30 && < 40) || (> 20 && < 25) ) ) // more complex multi restriction using groupings of multi restrictions
-Person( age > 30 && < 40 || location == "london" ) // mixing muti restrictions with constraint connectives</programlisting>
+Person( age > 30 && < 40 || location == "london" ) // mixing muti restrictions with constraint connectives
+</screen>
</example>
</section>
</section>
@@ -1023,9 +1024,9 @@
<example>
<title>Return Value operator</title>
- <programlisting>Person( girlAge : age, sex = "F" )
+<screen>Person( girlAge : age, sex = "F" )
Person( eval( girlAge == boyAge + 2 ), sex = 'M' )
-</programlisting>
+</screen>
</example>
</section>
@@ -1039,10 +1040,10 @@
Working Memory is not aware of any of the nested values, and do not
know when they change; they should be considered immutable while any
of their parent references are inserted into the Working Memory. If
- you wish to modify a nested value you should remove he parent objects
- first and re-assert afterwards. If you only have a single parent at
- the root of the graph, when in the MVEL dialect, you can use the
- 'modify' keyword and its block setters to write the nested accessor
+ it is wished to modify a nested value the parent objects should be removed
+ first and re-assert afterwards. If there is only a single parent at
+ the root of the graph, when in the MVEL dialect, the
+ <emphasis>modify</emphasis> keyword can be used and its block setters to write the nested accessor
assignments while retracting and inserting the the root parent object
as required. Nested accessors can be used either side of the operator
symbol.</para>
@@ -1050,17 +1051,22 @@
<example>
<title>Nested Accessors</title>
- <programlisting>$p : Person( )
-Pet( owner == $p, age > $p.children[0].age ) // Find a pet who is older than their owners first born child</programlisting>
+<screen>$p : Person( )
+Pet( owner == $p, age > $p.children[0].age ) // Find a pet who is older than their owners first born child
+</screen>
<para>is internally rewriten as an MVEL inline eval:</para>
- <programlisting>$p : Person( )
-Pet( owner == $p, eval( age > $p.children[0].age ) ) // Find a pet who is older than their owners first born child</programlisting>
+<screen>$p : Person( )
+Pet( owner == $p, eval( age > $p.children[0].age ) ) // Find a pet who is older than their owners first born child
+</screen>
</example>
- <remark>NOTE: nested accessors have a much greater performance cost
- than direct field access, so use them carefully.</remark>
+ <note>
+ <para>
+ Nested accessors have a much greater performance cost
+ than direct field access, so use them carefully.</para>
+ </note>
</section>
</section>
@@ -1089,17 +1095,18 @@
<example>
<title>prefixAnd</title>
- <programlisting>(and Cheese( cheeseType : type )
- Person( favouriteCheese == cheeseType ) )
-</programlisting>
+<screen>(and Cheese( cheeseType : type )
+Person( favouriteCheese == cheeseType ) )
+</screen>
</example>
<example>
<title>implicit root prefixAnd</title>
- <programlisting>when
+<screen>when
Cheese( cheeseType : type )
- Person( favouriteCheese == cheeseType )</programlisting>
+ Person( favouriteCheese == cheeseType )
+</screen>
</example>
<para>Infix 'and' is supported along with explicit grouping with
@@ -1121,8 +1128,9 @@
<example>
<title>infixAnd</title>
- <programlisting>Cheese( cheeseType : type ) and Person( favouriteCheese == cheeseType ) //infixAnd
-(Cheese( cheeseType : type ) and (Person( favouriteCheese == cheeseType ) or Person( favouriteCheese == cheeseType ) ) //infixAnd with grouping</programlisting>
+<screen>Cheese( cheeseType : type ) and Person( favouriteCheese == cheeseType ) //infixAnd
+(Cheese( cheeseType : type ) and (Person( favouriteCheese == cheeseType ) or Person( favouriteCheese == cheeseType ) ) //infixAnd with grouping
+</screen>
</example>
</section>
More information about the jboss-svn-commits
mailing list