A rule template 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.

Let'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 "Expanding a Template".

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
  when
     Integer( valueOf == 7 )
  when
     Integer( valueOf == 13 )
as opposed to
   when
      Parameter( $n: number )
      Integer( valueOf == $n )
with appropriate Parameter facts (7, 13).

-W











On 18 June 2013 16:58, Jason Allen <jason.allen@data-sign.com> wrote:
All,

I saw this question was asked a couple of months ago with no reply, but thought I would try again.

In using a Rule Template, I'm trying to determine a way to dynamically generate rules based on a value in the data.

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't want the generated a rule for each row of data, because many of the rules generated would never fire.

In the drools expert docs, it lists under 6.1.7 Rule Templates the ability to "conditionally generate rules based on the values in the data", but I can't seem to find the syntax for how to do that.

Does anyone know the answer to this?

I would picture it looking something like this

if ("@{RevenueCode}" == "NR")
rule "RevenueMapperRule_1"
when
claim1 : ClaimFact (ProgramType in ("FC", "FCP", "FALSE", "FALSE"),
ProcedureCode == "NR",
(serviceBegin >= "01-Oct-2003" && serviceBegin <= "31-Dec-2030"),
modifier1 in ("U"),
typeofBill == "3");
then
claim1.setResultSPCCode("507.11");
list.add(claim1);
end
end if

Essentially, the only time this rule would be generated is if RevenueCode in the Rules Spreadsheet had a value of "NR".

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.

Thoughts?

Thanks in advance!


_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users