<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">


<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>RE: How to write a rule that fires when it matches against specific facts in working memory.</TITLE>


<!-- Converted from text/plain format -->
<BR>

<P><FONT SIZE=2>Edson,<BR>
<BR>
That worked beautifully !<BR>
<BR>
Drools is looking more and more promising for what we need to do.<BR>
<BR>
Thanks for all your help,<BR>
<BR>
Gurvinder<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: Edson Tirelli-4 [via Drools - Java Rules Engine] [<a href="/user/SendEmail.jtp?type=node&node=2381946&i=0" target="_top" rel="nofollow">[hidden email]</a>]<BR>
Sent: Sat 1/29/2011 10:59 PM<BR>
To: Gurvinder Narula1<BR>
Subject: Re: How to write a rule that fires when it matches against specific facts in working memory.<BR>
<BR>
<BR>
 Â&nbsp; Up to Drools 5, the accumulate function API supports only a single argument to the function, but that argument can be an array or a list. So what I do on my own implementations is to pass the $param as one element of the array and $o as the other. It is not ideal, but it is how you can do that in Drools 5. In Drools 6 I will change the API to support multiple parameters, but I've been postponing that because when I do it, it will break existing implementations of the interface.<BR>
<BR>
 Â&nbsp; Anyway, if you are using the MVEL dialect, creating a list is as simple as wrapping it in [ ], as you could see in my previous e-mail.<BR>
<BR>
$options : List() from accumulate(Â<BR>
 Â&nbsp; Â&nbsp; Â $op : Option(),<BR>
 Â&nbsp; Â&nbsp; Â matchAll( [ ${param}, $op ] ) )<BR>
<BR>
 Â&nbsp; Â Edson<BR>
<BR>
2011/1/29 groovenarula &lt;[hidden email]&gt;<BR>
<BR>
<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Edson,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I did manage to use the 'CollectSetAccumulateFunction' as a template for the<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MatchAll and have also successfully 'called' the accumulate function from a<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rule written in a .drl file. But I'm stuck at one point - how to send the<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value of $param to the accumulate method ? From what I understand, the<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; accumulate method is invoked for each fact - so if I write<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Â&nbsp; Â&nbsp; MatchAll( $o ) it will invoke the accumulate method and passing $o fact<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to the method via the 'Object value' parameter.<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; So far so go, however, I'm stuck on how to pass the value of '$param' to the<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; accumulate method (or any other method like init, getResult for that<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; matter).<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; One option I can think of is to change the definition of the Option fact to<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; include a 'param' field and then write a rule that sets the value of that<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; field to $param (so every Options param field would get set to the value of<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $param). I can then extract that in the accumulate method it self. But is<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; there a better way that I might be missing ?<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thanks in advance,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gurvinder<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; View this message in context: <A href="http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2369936.html?by-user=t" target="_top" rel="nofollow" link="external">http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2369936.html</A> &lt;<A href="http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2369936.html?by-user=t&by-user=t" target="_top" rel="nofollow" link="external">http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2369936.html?by-user=t</A>&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sent from the Drools - User mailing list archive at Nabble.com.<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _______________________________________________<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rules-users mailing list<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [hidden email]<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A HREF="https://lists.jboss.org/mailman/listinfo/rules-users" target="_top" rel="nofollow" link="external">https://lists.jboss.org/mailman/listinfo/rules-users</A><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>
<BR>
<BR>
<BR>
<BR>
--<BR>
Â&nbsp; Edson Tirelli<BR>
Â&nbsp; JBoss Drools Core Development<BR>
Â&nbsp; JBoss by Red Hat @ www.jboss.com<BR>
<BR>
<BR>
_______________________________________________<BR>
rules-users mailing list<BR>
[hidden email]<BR>
<A HREF="https://lists.jboss.org/mailman/listinfo/rules-users" target="_top" rel="nofollow" link="external">https://lists.jboss.org/mailman/listinfo/rules-users</A><BR>
<BR>
<BR>
<BR>
________________________________<BR>
<BR>
If you reply to this email, your message will be added to the discussion below:<BR>
<A href="http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2380361.html?by-user=t" target="_top" rel="nofollow" link="external">http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2380361.html</A><BR>
To unsubscribe from How to write a rule that fires when it matches against specific facts in working memory., click here &lt;<A href="http://drools-java-rules-engine.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=2294599&code=Z25hcnVsYTFAbGEtei1ib3kuY29tfDIyOTQ1OTl8MjAzMTM1NDY2Mw==&by-user=t" target="_top" rel="nofollow" link="external">http://drools-java-rules-engine.46999.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=2294599&code=Z25hcnVsYTFAbGEtei1ib3kuY29tfDIyOTQ1OTl8MjAzMTM1NDY2Mw==</A>&gt; .<BR>
<BR>
</FONT>
</P>



<br><hr align="left" width="300">
View this message in context: <a href="http://drools-java-rules-engine.46999.n3.nabble.com/How-to-write-a-rule-that-fires-when-it-matches-against-specific-facts-in-working-memory-tp2294599p2381946.html">RE: How to write a rule that fires when it matches against specific facts in working memory.</a><br>
Sent from the <a href="http://drools-java-rules-engine.46999.n3.nabble.com/Drools-User-f47000.html">Drools - User mailing list archive</a> at Nabble.com.<br>