[rules-users] How to design a rule using collect for filtering? Thanks.

Edson Tirelli tirelli at post.com
Wed Aug 15 13:13:22 EDT 2007


    This is a regression bug. InitialFact should not be shadowed. Can you
please open a JIRA for that?

   Thank you
      Edson

2007/8/15, Anh Vuong <anhtvuong at yahoo.com>:
>
> Thanks for your help, Edson.
> collect works in my simple test now, but not when I integrate with my
> code. Is there an easy way to debug LHS to see if collect stmt is
> evaluated?  I notice IllegalAccessError
>  since my app will load a selected list of jars upfront, so my questions
> are:
> 1) Can this error break collect?
> 2) How can I fix this error still using our own classLoader?
>
> Here is the stack trace:
> 2007 Aug 15, 09:08:13:193        Exception IllegalAccessError
> java.lang.IllegalAccessError: class
> org.drools.reteoo.InitialFactImplShadowProxy cannot access its superclass
> org.drools.reteoo.Init
> ialFactImpl
>         at java.lang.ClassLoader.defineClass1(Native Method)
>         at java.lang.ClassLoader.defineClass(Unknown Source)
>         at org.drools.rule.MapBackedClassLoader.fastFindClass(
> MapBackedClassLoader.java:60)
>         at org.drools.rule.MapBackedClassLoader.loadClass(
> MapBackedClassLoader.java:79)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at org.drools.reteoo.Rete$ObjectTypeConf.loadOrGenerateProxy(
> Rete.java:379)
>         at org.drools.reteoo.Rete$ObjectTypeConf.defineShadowProxyData(
> Rete.java:344)
>         at org.drools.reteoo.Rete$ObjectTypeConf.<init>(Rete.java:320)
>         at org.drools.reteoo.Rete.assertObject(Rete.java:145)
>         at org.drools.reteoo.ReteooRuleBase.assertObject(
> ReteooRuleBase.java:190)
>         at
> org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute
> (ReteooWorkingMemory.java:163)
>         at org.drools.common.AbstractWorkingMemory.executeQueuedActions(
> AbstractWorkingMemory.java:1241)
>         at org.drools.common.AbstractWorkingMemory.insert(
> AbstractWorkingMemory.java:858)
>         at org.drools.common.AbstractWorkingMemory.insert(
> AbstractWorkingMemory.java:822)
>         at org.drools.common.AbstractWorkingMemory.insert(
> AbstractWorkingMemory.java:623)
>
> Thanks,
> -av
>
>
> *Edson Tirelli <tirelli at post.com>* wrote:
>
>
>    No single simple answer here. You need to check what would better fit
> your use case.
>    The thing is: it is not possible to limit the number of matches to a
> collect statement... all matching instances WILL match it and be collected.
>
>    No really "clean" way I can think about, but a few possible options
> (haven't executed them, but shall work):
>
> 1. Simply execute the actions multiple times in the consequence:
>
> when
>    eventList : LinkedList( $size : size >= 5 ) from collect( Event(text
> matches ".*rule5.*" ))
> *then
>    for( int i = 0; i < $size/5; i++ )
> *
>        System.out.println("rule5 is fired " + eventList.size ());
> end
>
> 2. Flag used facts:
>
> when
>    eventList : LinkedList( size >= 5 ) from collect( Event(text matches
> ".*rule5.*", processed == false ))
> *then
> *   System.out.println("rule5 is fired " + eventList.size());
> *   for( int i = 0; i < 5; i++ ) {
>        Event e = **(Event) eventList.get ( i );**
>        e.setProcessed( true );
>        update( e );
> *
>    }
> end
>
> 2. Retract used facts:
>
> when
>    eventList : LinkedList( size >= 5 ) from collect( Event(text matches
> ".*rule5.*" ))
> *then
> *   System.out.println("rule5 is fired " + eventList.size());
> *   for( int i = 0; i < 5; i++ ) {
>        Event e = **(Event) eventList.get( i );* *
>        retract( e );
> *
>    }
> end
>
>     Hope it helps.
>
>     Edson
>
> 2007/8/10, Anh Vuong <anhtvuong at yahoo.com>:
> >
> > Hi,
> > I'd like to use keyword collect to do my filtering but its behaviour
> > confused me, please advise. I greatly appreciate your help.
> >
> > Problem 1:
> >
> > when
> > eventList : LinkedList(size == 5)
> > from collect( Event(text matches
> > ".*rule5.*" ))
> > *then* System.out.println(
> > "rule5 is fired " + eventList.size());
> > I still do not see any log msg after adding 5+ events. Is something
> > wrong with my rule?
> >
> > Problem 2:
> >
> > when
> > event: Event(text matches ".*rule5.*" ))
> > eventList : LinkedList(size == 5)
> > from collect( Event(text == event.text)
> >  *then * System.out.println(
> > "rule5 is fired " + eventList.size());
> > After adding 5 events, I see 5 log msg instead of one as I'd expect.
> > If I add more events, I will see more log. How do I tell LHS  to reset
> > the count from 0.
> > Basically, I want to take 1 event out of 5 similar events (suppressing
> > filtering). So if there are 10 similar events, my RHS should activate 2
> > times, not 10 times.
> >
> > Thanks,
> > -av
> >
> >  ------------------------------
> > Ready for the edge of your seat? Check out tonight's top picks<http://us.rd.yahoo.com/evt=48220/*http://tv.yahoo.com/>on Yahoo! TV.
> >
> > _______________________________________________
> > 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_______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
> ------------------------------
> Park yourself in front of a world of choices in alternative vehicles.
> Visit the Yahoo! Auto Green Center.<http://us.rd.yahoo.com/evt=48246/*http://autos.yahoo.com/green_center/;_ylc=X3oDMTE5cDF2bXZzBF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDZ3JlZW4tY2VudGVy>
>
>
> _______________________________________________
> 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/20070815/27419f2a/attachment.html 


More information about the rules-users mailing list