[rules-users] Compiled template rule ordering

Patrick Conreaux pgconreaux at gmail.com
Thu Dec 8 19:40:30 EST 2016


Hi,

I am attempting to compile a rule template and expecting the resulting rules
to preserve the ordering of the template and of the rows in the CSV file.
However, it doesn't appear that ordering is preserved. Is this a bug, or is
there a workaround?
I would like to rely on the implicit top-down salience by having rules in a
specified order within the same file. (I'm aware that mutually exclusive
rules are preferred, but this greatly complicates maintaining the rules for
my use case, as does maintaining salience values.)

Using the (slightly-modified) cheese example, this template...

template header
age
type
log

package org.drools.examples.templates;

global java.util.List list;

rule "first rule"
when
eval(true)
then
System.out.println("first rule");
end

template "cheesefans"
rule "Cheese fans_@{row.rowNumber}"
    when
        Person(age == @{age})
        Cheese(type == "@{type}")
    then
        list.add("@{log}");
end
end template

rule "last rule"
when
eval(true)
then
System.out.print("last rule");
end


 ...results in the following output, where the first and last rule appear
at the top followed
by the template rules in *reverse *row order. Any suggestions to achieve
the desired order?


package org.drools.examples.templates;
global java.util.List list;
rule "first rule"
when
eval(true)
then
System.out.println("first rule");
end
rule "last rule"
when
eval(true)
then
System.out.print("last rule");
end

rule "Cheese fans_3"
    when
        Person(age == Really old guy)
        Cheese(type == "65")
    then
        list.add("provolone");
end

rule "Cheese fans_2"
    when
        Person(age == Young guy)
        Cheese(type == "21")
    then
        list.add("cheddar");
end

rule "Cheese fans_1"
    when
        Person(age == Old guy)
        Cheese(type == "42")
    then
        list.add("stilton");
end

Cheers,
Patrick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20161208/5f5e2498/attachment.html 


More information about the rules-users mailing list