[rules-users] How to use not operator in drool.

Mark Proctor mproctor at codehaus.org
Thu Sep 13 05:27:28 EDT 2007


not ( SomeClass(....) ) is an existential conditional eleemnt operator, 
it goes at the head of pattern, and checks if the pattern plus its field 
constraints exist in the session; it will cause a rule to fire once 
whether there is 1 or 100 matching patterns.

SomeClass( somefield not in ('x, 'y', 'z) ) is a field constraint on a 
pattern, it checks if the value of a field is in a list of values, it 
will cause the rule to fire for each and every possible rule match.

Mark
JOSHI, GAURAV wrote:
>
> Thank's for your sugession of using "not in" instead of "not" but my 
> problem is that "not" can also come without "in".
>
>  
>
> Actually I am making a generator of rule file from expression like
>
>  ((NOT (ENDS WITH (G10.2, ",")))
>
>  
>
>  ((NOT (G13.1 IN ("1","2","3"))) OR (G250.8 = Y)))
>
>  
>
> Where G13.2, G250.8, G10.2 are variables coming from a map inserted in 
> working memory.
>
>  
>
> I am accessing these variables from map.
>
>  
>
> My rules are as follows
>
>  
>
> This rule is working fine.
>
>  
>
> rule "Editable_G10.3"
>
> when
>
>  
>
> * ((Map( this["G10.3"] !=8))||(Map( this["G10.2"] ==19)))*
>
>  
>
> then
>
> System.out.println("comming 
> here----------------------------------------------------->");
>
> End
>
>  
>
> *This is not working*
>
>  
>
> rule "Mandatory_G10.3"
>
> when
>
> * (not((Map( this["G10.3"] !=8))||(Map( this["G10.2"] ==19)))) *
>
> Then
>
> System.out.println("comming 
> here----------------------------------------------------->");
>
> End
>
>  
>
> In also tried following approaches:
>
> 1)      *eval(not((Map( this["G10.3"] !=8))||(Map( this["G10.2"] 
> ==19)))) *
>
> * *
>
> *2) eval(!((Map( this["G10.3"] !=8))||(Map( this["G10.2"] ==19)))) *
>
> * *
>
> But in both cases it is giving same error:
>
> org.drools.rule.InvalidRulePackage: Rule Compilation error : [Rule 
> name=ValidationRuleExp_G10.3, agendaGroup=MAIN, salience=0, no-loop=false]
>
>       
> com/telekurs/nva/mde/fe/ak/validation/Rule_ValidationRuleExp_G10_3_0.java 
> (11:495) : Cannot use this in a static context
>
>       
> com/telekurs/nva/mde/fe/ak/validation/Rule_ValidationRuleExp_G10_3_0.java 
> (11:500) : Type mismatch: cannot convert from String to int
>
>  
>
> I am trying to find out some general concept so that I can change just 
> achieve the functionality of not.
>
>  
>
> Thanks
>
> Gaurav
>
>  
>
> ------------------------------------------------------------------------
>
> *From:* rules-users-bounces at lists.jboss.org 
> [mailto:rules-users-bounces at lists.jboss.org] *On Behalf Of *Edson Tirelli
> *Sent:* Wednesday, September 12, 2007 10:20 PM
> *To:* Rules Users List
> *Subject:* Re: [rules-users] How to use not operator in drool.
>
>  
>
>
>    Remove your "eval" and use "or" instead of "||" for the OR CE.
>
>    Although, I feel that this is not what you want... what you want is 
> simply:
>
> when
>     Map( this['city'] not in ( "mumbai", "delhi" ) )
> then
>     //...
> end
>  
>     []s
>     Edson
>
> 2007/9/12, Gaurav2007 <gaurav.a.joshi at capgemini.com 
> <mailto:gaurav.a.joshi at capgemini.com>>:
>
>
> Hi ALL,
>
> I am using drool4.0.1 in my application i am able to use IN,OR,AND 
> operator
> but i am facing problem in using not operator.
>
> my requirement of not operator is just like a not gate.
>
> the way i am using it is :
>
> eval(not((Map( this["city"] !="mumbai"))||(Map( this["city"] =="delhi"))))
>
>
> so can you please help me out to solve this problem:
> should i use not operator or some thing else in drool.
>
> Thanks,
>
>
> --
> View this message in context: 
> http://www.nabble.com/How-to-use-not-operator-in-drool.-tf4430240.html#a12638430 
> <http://www.nabble.com/How-to-use-not-operator-in-drool.-tf4430240..html#a12638430>
> Sent from the drools - user mailing list archive at Nabble.com 
> <http://Nabble.com>.
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org <mailto: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 <http://www.jboss.com>
>
> This message contains information that may be privileged or 
> confidential and is the property of the Capgemini Group. It is 
> intended only for the person to whom it is addressed. If you are not 
> the intended recipient, you are not authorized to read, print, retain, 
> copy, disseminate, distribute, or use this message or any part 
> thereof. If you receive this message in error, please notify the 
> sender immediately and delete all copies of this message.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070913/2aa9b17f/attachment.html 


More information about the rules-users mailing list