[rules-users] Problem with memberOf and/or eval used in collect statement

Edson Tirelli tirelli at post.com
Tue Sep 18 16:21:35 EDT 2007


    Chris,

    Do you really need to "collect" all these facts? Are you doing anything
with these lists? It would be easier if you can show me the full rule, but
seems to me that maybe you can avoid some or all of these collects. Remember
that collect is a heavy CE, so it is always good to avoid when possible.

    Anyway, there should be no problem if you use eval(). The problem in
JBRULES-1204 only affects memberOf operator, since the fix I implemented in
http://jira.jboss.org/jira/browse/JBRULES-1115 fixed the eval()s.

    I will fix 1204 asap.

    []s
    Edson


2007/9/18, Chris West <crayzfishr at gmail.com>:
>
> Edson,
>
> So now my dilemma is that I cannot use 4.0.0 due to JBRULES-1204, but I
> cannot use 4.0.1 or 4.0.2-SNAPSHOT due to JBRULES-1203.  Below is an
> actual block from my rule.  I'd like to transform it into something like
> "TestEval2" from my example, but it is more complicated.  Can it be
> rewritten like "TestEval2"?
>
>         $sorties: ArrayList() from collect (AirPlanSortie(event ==
> $currentEvent, spare == false, superSpare == false))
>
>         $statuses: ArrayList($sortieSize: size) from collect
> (SortieStatus(state != SortieState.CANCELLED, $sortie1: sortie, eval
> ($sorties.contains($sortie1))))
>
>         $launches: ArrayList(size > 0, size == $sortieSize) from collect
> (LaunchAircraftStatus(launched == true, $sortie0: sortie,
> eval($sortie0.getEvent().equals($currentEvent))))
>
> -Chris
>
>
> On 9/18/07, Edson Tirelli <tirelli at post.com> wrote:
> >
> >
> >     Chris,
> >
> >     Thanks for reporting this.
> >
> >     I fixed a bug in 4.0.0 (released in 4.0.1) that causes you to see
> > the correct value for "TestEval1" in 4.0.1 and later versions. Although,
> > at that time I missed the memberOf scenario. I know why it happens (shadow
> > fact related), but now I need to figure out a way to fix it.
> >
> >     May I ask you to open a ticket for that?
> >
> >     Thanks,
> >       Edson
> >
> >
> > 2007/9/18, Chris West < crayzfishr at gmail.com>:
> > >
> > > All,
> > >
> > > I'm having a problem using memberOf combined with a collect
> > > statement.  My test includes 3 rules each written to output the same results
> > > (I think), but I get different results (depending on which version of Drools
> > > I use).
> > >
> > > The rules are:
> > >
> > >
> > > rule "TestMemberOf"
> > >     salience 10
> > >     when
> > >         $messages: ArrayList() from collect (Message(status == 100))
> > >         $wrappers: ArrayList() from collect (Wrapper(message memberOf
> > > $messages))
> > >     then
> > >         System.out.println("TestMemberOf: " + $wrappers.size());
> > > end
> > >
> > > rule "TestEval1"
> > >     salience 9
> > >     when
> > >         $messages: ArrayList() from collect (Message(status == 100))
> > >         $wrappers: ArrayList() from collect (Wrapper($message:
> > > message, eval($messages.contains($message))))
> > >     then
> > >         System.out.println("TestEval1: " + $wrappers.size());
> > > end
> > >
> > > rule "TestEval2"
> > >     salience 8
> > >     when
> > >         $wrappers: ArrayList() from collect (Wrapper($message:
> > > message, eval($message.getStatus() == 100)))
> > >     then
> > >         System.out.println("TestEval2: " + $wrappers.size());
> > > end
> > >
> > >
> > >
> > > The output is (by version):
> > >
> > > 4.0.0
> > >
> > > TestMemberOf: 0
> > > TestEval1: 0
> > > TestEval2: 2
> > >
> > > 4.0.1
> > >
> > > TestMemberOf: 0
> > > TestEval1: 2
> > > TestEval2: 2
> > >
> > > 4.0.2.SNAPSHOT (taken 9/18/07)
> > >
> > > TestMemberOf: 0
> > > TestEval1: 2
> > > TestEval2: 2
> > >
> > >
> > > The correct output should be:
> > >
> > > TestMemberOf: 2
> > > TestEval1: 2
> > > TestEval2: 2
> > >
> > >
> > > Am I using memberOf correctly?  Is there some issue using an eval to
> > > test conditions on a list created by a collect?
> > >
> > > Any help would be appreciated.
> > >
> > > Attached is the full example.
> > >
> > > Thanks,
> > > -Chris West
> > >
> > >
> > >
> > > _______________________________________________
> > > 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
> >
> >
>
> _______________________________________________
> 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/20070918/011fe9c5/attachment.html 


More information about the rules-users mailing list