[rules-users] Count matching facts
Edson Tirelli
tirelli at post.com
Tue Jan 29 10:46:36 EST 2008
Sorry, my previous suggestion will count the same process name multiple
times. There are a few ways to avoid it. I would probably use a helper fact:
rule XYZ
when
$p : Process( $name : name )
not( ProcessCount( name == $name ) )
Number( $count : intValue) from accumulate(
$i : Process( name == $name, this != $p ),
count( $i ) )
then
System.out.println( "There are "+$count+" instances of processes
named "+$name );
insert( new ProcessCount( $name, $count ) );
end
Hope it helps,
Edson
2008/1/29, Edson Tirelli <tirelli at post.com>:
>
>
> Try that:
>
> rule XYZ
> when
> $p : Process( $name : name )
> Number( $count : intValue) from accumulate(
> $i : Process( name == $name, this != $p ),
> count( $i ) )
> then
> System.out.println( "There are "+$count+" instances of processes named
> "+$name );
> end
>
> []s
> Edson
>
>
> 2008/1/29, cfili <cfilippelli at cerner.com>:
> >
> >
> > I am having a hard time finding an example of what I am trying to do, so
> > maybe someone here could help me. What I am trying to do is determine
> > how
> > many facts fall into the same category.
> >
> > My facts are 'processes' and one of their attributes is a 'name'. My
> > goal
> > is to determine how many processes with the same name are running. The
> > problem is I do not know ahead of time the process names available, I
> > want
> > to determine that set at runtime. Also, once I determine the count for
> > a
> > given name, I do not want to run it again for the other processes that
> > fall
> > in that name category.
> >
> > I think "from collect" is probably what I want to use here, but I am not
> > sure how to grab the names in my Pattern from the fact I am currently
> > iterating on.
> >
> > Thanks.
> > --
> > View this message in context:
> > http://www.nabble.com/Count-matching-facts-tp15160392p15160392.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
> >
>
>
>
> --
> Edson Tirelli
> JBoss Drools Core Development
> Office: +55 11 3529-6000
> Mobile: +55 11 9287-5646
> JBoss, a division of Red Hat @ www.jboss.com
--
Edson Tirelli
JBoss Drools Core Development
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/20080129/e09b772c/attachment.html
More information about the rules-users
mailing list