[rules-users] OR operator
Edson Tirelli
tirelli at post.com
Mon Aug 13 12:35:37 EDT 2007
Jaikiran,
This is only supported in Drools 4.
In 3.0.x, you will have to use either a predicate or do what you were
doing, but note that as Mark mentioned, the OR CE will cause subrule
generation, meaning the rule will fire twice if both conditions are true.
[]s
Edson
2007/8/13, Jaikiran Pai <jai_forums2005 at yahoo.co.in>:
>
> Thanks for the inputs, Mark.
>
> I just modified the Helloworld example to try this out. I added a
> collection to the Message class:
>
> public static class Message {
> public static final int HELLO = 0;
> public static final int GOODBYE = 1;
>
> private String message;
> private int status;
>
> private List headers = new ArrayList();
>
> public void setHeaders(List test) {
> //ignore the param as of now
> headers.add("hello header1");
> headers.add("hello header2");
> }
>
> public List getHeaders() {
> return this.headers;
> }
> ….
> }
>
> And then changed the rule to:
>
> rule "Hello World"
> when
> m : (Message (headers contains "hello header1" || contains
> "hello header2"))
> then
>
> System.out.println( "bye" );
>
> End
>
> However, the rule compilation fails with this error:
>
> org.drools.rule.InvalidRulePackage: unknown:7:49 Unexpected token '||'
> unknown:7:53 mismatched token: [@51,170:177='contains',<49>,7:53];
> expecting type ID
> unknown:8:1 mismatched token: [@58,199:202='then',<33>,8:1]; expecting
> type '('
> unknown:10:2 mismatched token: [@65,211:216='System',<5>,10:2]; expecting
> type ')'
>
> at org.drools.rule.Package.checkValidity(Unknown Source)
> at org.drools.common.AbstractRuleBase.addPackage(Unknown Source)
> at org.drools.examples.HelloWorldExample.readRule(*
> HelloWorldExample.java:65*)
> at org.drools.examples.HelloWorldExample.main(*
> HelloWorldExample.java:23*)
>
>
> I tried out a few more combinations with the || constraint, but each time
> it failed with similar errors complaining about the token.
>
> Anything that I am doing incorrectly, here? I am using 3.0.6 version.
>
> Regards,
> -Jaikiran
>
>
> *Mark Proctor <mproctor at codehaus.org>* wrote:
>
> using 'or' like that results in subrule generation, i.e. rules will fire
> for all matching combinatinos - this is not what people normally want. you
> can also do it using field constraints
>
> person : (Person (interests contains "Golf" || contains "Soccer")
>
> Jaikiran Pai wrote:
>
> Hi,
> This is a very newbie question. I have a Person object which contains a
> collection named "interests". This collection will contain the activities
> that the Person is interested in. If the person is interested in Golf,
> Soccer and Baseball, then this collection will contain these 3 strings. I am
> trying to write a rule which checks whether a person is interested in Soccer
> OR Golf and if he's interested then do further logic. I looked at the
> documentation for Drools syntax, and looks like this is how i have to write
> the rule:
> rule Testing
> when
> person : (Person (interests contains "Golf") or Person (interests
> contains "Soccer") )
> then
> System.out.println("I am interested");
> end
>
> Is this the correct way to do this? Is there a simpler construct like:
> person : Person (interests contains "Golf" or interests contains "Soccer"
> )
> I was thinking on the lines of the "," (and) operator :
>
> person : Person (interests contains "Golf", interests contains "Soccer" )
> Thank you.
> ------------------------------
> Why delete messages? Unlimited storage is just a click away.<http://in.rd.yahoo.com/tagline_mail_1/*http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/>
>
> ------------------------------
> _______________________________________________ rules-users mailing list rules-users at lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> ------------------------------
> Bollywood, fun, friendship, sports and more. You name it, we have it.<http://in.rd.yahoo.com/tagline_groups_1/*http://in.groups.yahoo.com>
>
>
> _______________________________________________
> 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 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070813/785eada9/attachment.html
More information about the rules-users
mailing list