[rules-users] OR operator

Jaikiran Pai jai_forums2005 at yahoo.co.in
Mon Aug 13 09:47:36 EDT 2007


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. 

---------------------------------
  _______________________________________________  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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070813/3d4c52e8/attachment.html 


More information about the rules-users mailing list