<div dir="ltr"><div><div>A <i>rule template </i>is a text (file) intended to be expanded repeatedly using different sets of template parameters, similar to a macro processor. Each expansion will generate - more or less - the same rule, unless you put the flexibility into the parameter, which just passes the buck to the code driving the expansion.<br>
</div><br></div><div>Let&#39;s say that you want to be alerted if one of your lucky numbers becomes a fact. You can write a template, create a collection of your lucky numbers and run the expander to create one rule for each of your lucky numbers. This is explained in section &quot;Expanding a Template&quot;.<br>
<br></div><div>Most of the time, sets of almost identical rules can be avoided if facts containing parameter sets are inserted and rules are written to match the values from a ParameterSet fact rather than literals, as would be done by generated rules. Consider<br>
</div><div>  when<br></div><div>     Integer( valueOf == 7 ) <br></div><div><div>  when<br>
</div><div>     Integer( valueOf == 13 ) <br>
</div><div>as opposed to</div><div>   when<br></div><div>      Parameter( $n: number )<br></div><div>      Integer( valueOf == $n )<br></div><div>with appropriate Parameter facts (7, 13).<br><br></div><div>-W<br></div><div>
<br></div><div><br>
</div></div><div><br><br><br><br><br><div><br><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 18 June 2013 16:58, Jason Allen <span dir="ltr">&lt;<a href="mailto:jason.allen@data-sign.com" target="_blank">jason.allen@data-sign.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">All,<div><br></div><div>I saw this question was asked a couple of months ago with no reply, but thought I would try again.</div>
<div><br></div><div>In using a Rule Template, I&#39;m trying to determine a way to dynamically generate rules based on a value in the data.</div><div><br></div><div>There is a data set, that has various pieces data, depending on a column value, the rule that is generated is relatively different.  Different enough that I wouldn&#39;t want the generated a rule for each row of data, because many of the rules generated would never fire.</div>
<div><br></div><div>In the drools expert docs, it lists under 6.1.7 Rule Templates the ability to &quot;conditionally generate rules based on the values in the data&quot;, but I can&#39;t seem to find the syntax for how to do that.</div>
<div><br></div><div>Does anyone know the answer to this?</div><div><br></div><div>I would picture it looking something like this</div><div><br></div><div>if (&quot;@{RevenueCode}&quot; == &quot;NR&quot;)</div><div><div style="margin:0px;font-size:11px;font-family:Monaco">
rule &quot;RevenueMapperRule_1&quot;</div><div style="margin:0px;font-size:11px;font-family:Monaco">when</div><div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">        </span>claim1 : ClaimFact (ProgramType in (&quot;FC&quot;, &quot;FCP&quot;, &quot;FALSE&quot;, &quot;FALSE&quot;),</div>
<div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">                                        </span>ProcedureCode == &quot;NR&quot;,</div><div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">                                        </span>(serviceBegin &gt;= &quot;01-Oct-2003&quot; &amp;&amp; serviceBegin &lt;= &quot;31-Dec-2030&quot;),</div>
<div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">                                        </span>modifier1 in (&quot;U&quot;),</div><div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">                                        </span>typeofBill == &quot;3&quot;);</div>
<div style="margin:0px;font-size:11px;font-family:Monaco">then</div><div style="margin:0px;font-size:11px;font-family:Monaco"><span style="white-space:pre-wrap">        </span>claim1.setResultSPCCode(&quot;507.11&quot;);</div><div style="margin:0px;font-size:11px;font-family:Monaco">
<span style="white-space:pre-wrap">        </span>list.add(claim1);</div><div style="margin:0px;font-size:11px;font-family:Monaco">end</div></div><div>end if</div><div><br></div><div>Essentially, the only time this rule would be generated is if RevenueCode in the Rules Spreadsheet had a value of &quot;NR&quot;.</div>
<div><br></div><div>If this is not possible, how should I be thinking about this problem?  Feels weird to generate a bunch of rules that will never fire, simply because there is no way to conditionally generate a rule.  Maybe the answer is to create separate rule files and template definitions?  That also feels like an over complication.</div>
<div><br></div><div>Thoughts?</div><div><br></div><div>Thanks in advance!</div><div><br></div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div><br></div>