[rules-users] Compiled template rule ordering

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[rules-users] Compiled template rule ordering

Patrick Conreaux
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

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users