[rules-users] what's wrong with this rule?...
Edson Tirelli
tirelli at post.com
Tue Mar 6 16:18:47 EST 2007
Vlad,
You should not use the "return" keyword and the ";" inside the result
block as it is implicit. Also, remember that anything inside eval() is
pure java code, so you cant do $count < 4 if $count is an Integer object.
Finally, try to always avoid eval() when writing rules.
Try something like:
*rule* "FG.23C"
*when*
*exists*
Record( $psc : psc == "323",
pa == "7[0-9]*",
sa == "F39040"
|== "F38010"
|== "F38090" )
$count : Integer( intValue < 4 ) *from* *accumulate *(
Record( psc == "323",
pa *matches* "8[0-9]995",
sa *matches* "F390[4-8][2-5]" ),
init ( *int* count = 0; ),
action( count += count; ),
result( *new* Integer(count) )
)
*then*
System.out.println( "rule FC.23C has failed" );
System.out.println();
*end*
**
Please, let me know if it works.
[]s
Edson
Olenin, Vladimir (MOH) wrote:
> Hi,
>
> I have the following rule:
>
> *rule* "FG.23C"
>
> *when*
>
> *exists*
>
> Record( $psc : psc == "323",
>
> pa == "7[0-9]*",
>
> sa == "F39040"
>
> |== "F38010"
>
> |== "F38090" )
>
> $count : Integer() *from* *accumulate *(
>
> Record( psc == "323",
>
> pa *matches* "8[0-9]995",
>
> sa *matches* "F390[4-8][2-5]" ),
>
> init ( *int* count = 0; ),
>
> action( count += count; ),
>
> result( *return* *new* Integer(count); )
>
> )
>
> *eval* ($count < 4 )
>
> *then*
>
> System.out.println( "rule FC.23C has failed" );
>
> System.out.println();
>
> *end*
>
> * *
>
> And for some reason I can’t compile correctly: I’m getting the
> following error:
>
> org.drools.rule.InvalidRulePackage: Rule Compilation error This method
> must return a result of type Integer Syntax error on token "(", ;
> expected Syntax error on token ")", delete this token
>
> at org.drools.rule.Package.checkValidity(_Package.java:367_)
>
> at
> org.drools.common.AbstractRuleBase.addPackage(_AbstractRuleBase.java:244_)
>
> at moh.ohfs.rules.RulesTest.readRule(_RulesTest.java:70_)
>
> at moh.ohfs.rules.RulesTest.main(_RulesTest.java:22_)
>
> All brackets seem to be matching…. This happens on 3.1M build.
>
> Thanks,
>
> Vlad
>
>------------------------------------------------------------------------
>
>_______________________________________________
>rules-users mailing list
>rules-users at lists.jboss.org
>https://lists.jboss.org/mailman/listinfo/rules-users
>
>
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com
More information about the rules-users
mailing list