[rules-users] Problem implementing multiple evals

Wolfgang Laun wolfgang.laun at gmail.com
Sat Jan 29 02:34:34 EST 2011


I'm sending this again, as it seems it didn't make the list yesterday.
Sorry if you receive this twice.
-W


On 28 January 2011 08:25, Wolfgang Laun <wolfgang.laun at gmail.com> wrote:

> The rule you have shown is not capable of producing that error message.
> Which version of Drools are you using?
>
> (1) You cannot use "=" (in: MyEvent(prop1="XYZ") to compare two values.
> (2) You cannot use "matches" in eval, where Java expressions are expected
> (in:  eval((prop3 matches ...).
> (3) You must use one argument for a call to count (in: accumulate(...,
> count())), even though this argument does not matter.
> (4) You should not use eval where it is not necessary.
> (5) Your must use correct regular expressions, there is an error in:
> matches ("MatchOne|MatchTwo){1}::"+... and also in: matches
> "(second|Third{1}_CONNECT".
> (6) It is highly unusual to use a repeat count of 1 for a subpattern in a
> regular expression.
>
> Anyway, below is a correct version of the LHS *except for the patterns, *where
> I don't know what you really need to match.
>
> Moreover, I urgently suggest that you
>
>    - DO NOT post the same question twice within 24 hours. Cleaning up the
>    mess takes time.
>    - Read the Drools Expert documentation before you write rules.
>    - Start with simple conditions and test that they work.
>    - Read the Drools Expert documentation.
>    - Build and test more complex patterns once simple patterns work as
>    expected.
>    - Read the Java documentation on regular expressions.
>
> The following code has been compiled successfully using Drools 5.1.1, but
> some regular expressions contain errors, which will throw an exception at
> runtime.
>
> declare MyEvent
>   @role( event )
>   prop1 : String
>   prop2 : int
>   prop3 : String
> end
>
> function String getFirstNameRegex(){ return "blah"; }
> function String getMMSCNameRegex(){ return "gaga"; }
> function String getServerID(){ return "R2D2"; }
> function int getNodeCount(){ return 20; }
> function int getConnectionCount(){ return 20; }
> function int getThirdNodeCount(){ return 20; }
>
> rule "or-or-or"
> when
>
>     MyEvent(prop1 == "XYZ") over window:time(1m) from entry-point MyStream
>     or
>     ( MyEvent() over window:time(1m) from entry-point MyStream
>       and
>       Number($i1 : doubleValue > (getNodeCount()*0.35) ) from accumulate(
>
>                        MyEvent(
>                        prop1 == "CONNECT",
>                        prop2 == 3,
>                        prop3 matches ("match " + getFirstNameRegex() + "
> Connect")
>                        ) over window:time(1m) from entry-point MyStream,
>                        count(1) )
>
>     )
>     or
>     ( MyEvent() over window:time(1m) from entry-point MyStream
>       and
>       Number($i2 : doubleValue > (getConnectionCount()*0.4) ) from
> accumulate(
>
>                        MyEvent(
>                        prop1 matches "(second|Third{1}_CONNECT",
>                        prop2 == 1,
>                        prop3 matches ("MatchOne|MatchTwo){1}::" +
> getMMSCNameRegex()+", failure")
>                        ) over window:time(1m) from entry-point MyStream,
>                        count(1) )
>
>     )
>     or
>     ( MyEvent() over window:time(1m) from entry-point MyStream
>       and
>       Number($i3 : doubleValue > (getThirdNodeCount()*0.5) ) from
> accumulate(
>
>                        MyEvent(
>                        prop1 matches "(E1|E2){1}_CONNECT",
>                        prop2 == 3,
>                        prop3 matches ("REPT (one|five|seven){1}::" +
> getServerID()+" is down")
>                        ) over window:time(1m) from entry-point MyStream,
>                        count(1) )
>     )
> then
>     System.out.println( "match" );
> end
>
> -W
>
>
>
>
>
> On 28 January 2011 07:08, Ayush <ayush.vatsyayan at alcatel-lucent.com>wrote:
>
>>
>>
>> When I'm trying to execute multiple evals I'm getting errors. Below is
>> what
>> I'm trying to do
>>
>>          MyEvent(prop1="XYZ") over window:time(1m) from entry-point
>> MyStream
>>               or
>>             (MyEvent() over window:time(1m) from entry-point MyStream
>>                and
>>                Number($i1 : doubleValue)
>>                from accumulate(
>>                        MyEvent(
>>                        prop1 == "CONNECT",
>>                        prop2 == 3,
>>                        eval((prop3 matches ("match "+getFirstNameRegex()+"
>> Connect")) == true)
>>                        ) over window:time(1m) from entry-point MyStream,
>> count()
>>                )
>>                and
>>                eval($i1 > getNodeCount()*0.35))
>>        or
>>                (MyEvent() over window:time(1m) from entry-point MyStream
>>                and
>>                Number($i2 : doubleValue)
>>                from accumulate(
>>                        MyEvent(
>>                        prop1 matches "(second|Third{1}_CONNECT",
>>                        prop2 == 1,
>>                        eval((prop3 matches
>> ("MatchOne|MatchTwo){1}::"+getMMSCNameRegex()+", failure")) == true)
>>                        ) over window:time(1m) from entry-point MyStream,
>> count()
>>                )
>>                and
>>                eval($i2 > getConnectionCount()*0.4))
>>        or
>>                (MyEvent() over window:time(1m) from entry-point MyStream
>>                and
>>                Number($i3 : doubleValue)
>>                from accumulate(
>>                        MyEvent(
>>                        prop1 matches "(E1|E2){1}_CONNECT",
>>                        prop2 == 3,
>>                        eval((prop3 matches ("REPT (one|five|seven){1}::
>> "+getServerID()+" is down")) == true)
>>                        ) over window:time(1m) from entry-point MyStream,
>> count()
>>                )
>>                and
>>                eval($i3 > getThirdNodeCount()*0.5))
>>
>> When I'm trying to execute the above LHS I get
>> org.drools.rule.InvalidPatternException: Required Declarations not bound:
>> '$i1'.
>>
>> I even tried using below approach
>>
>>       AlertReceivedEvent() over window:time(1m) from entry-point
>> NotificationStream
>>
>>                $I1 : Double() from getIsgNodeCount()
>>
>>                Number(doubleValue > $I1) from accumulate(
>>                        AlertReceivedEvent(
>>                                entity == "NPMMS_NE_CONNECT",
>>                                probableCause == 3,
>>                                eval((specificProblems matches ("REPT ISG
>> NPMMS::Unable to connect to "+getPxmmsNameRegex()+" node: PXMMS")) ==
>> true)
>>                        ) over window:time(1m) from entry-point
>> NotificationStream, count()
>>                )
>>
>>
>> But when I'm placing parentheses () around it, it throws exception stating
>> mismatched input '$I1' expecting ')' in rule. For now I'd placed these 3
>> statements in separate rules. Can anyone please help me solving it?
>>  Thanks
>> in advance.
>> --
>> View this message in context:
>> http://drools-java-rules-engine.46999.n3.nabble.com/Problem-implementing-multiple-evals-tp2365761p2365761.html
>> Sent from the Drools - User mailing list archive at Nabble.com.
>> _______________________________________________
>> 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/20110129/e71a3c76/attachment.html 


More information about the rules-users mailing list