We have a winner! Many thanks Michal, hope I can return the favor one day.
salience ( return getSalience4() )
for the record, my function looks something like (after tempate evaluation):
<pre>
function int getSalience4(){
int salience = 0;
if("VALUE"=="VALUE") salience += 1000;
return salience;
}
</pre>
I think the combination activation-group and dynamic salience for rule-template projects
are pretty useful.
Just for anyone interested, the tempate code looks something like this:
<pre>
rule "Some Rule_(a){row.rowNumber}"
activation-group "@{PARAM1}-@{PARAM2}"
salience ( return getSalience(a){row.rowNumber}() )
</pre>
where PARAM1 and PARAM2 make up a kind of key. I only want to execute one rule that
matches that key, no matter how many options there are.
Rules that have additional parameters get higher salience than rules with less parameters,
so here is my function.
<pre>
function int getSalience(a){row.rowNumber}(){
int salience = 0;
if("@{PARAM3}"=="@{PARAM3}") salience += 1000;
if("@{PARAM4}"=="@{PARAM4}") salience += 1000;
return salience;
}
</pre>
A concrete example could be pizza. So there are 3 types of pizza, all are grouped in the
same activation-group.
cheese, pepperoni
cheese, pepperoni, sausage
cheese, pepperoni, meatball, pepper
Any cheese and pepperoni pizza should could match all these rules, but more toppings is
always better for me.
So cheese, pepperoni, onion, pepper getts a salience of 2000, and is the only rule
evaluated.
On Tue Sep 1 18:39:13 EDT 2009, Michal Bali michalbali at gmail.com wrote:
does this work?
salience ( return getSalience() )
or this:
salience ( getSalience();)
On Tue, Sep 1, 2009 at 6:50 PM, Bill Tarr <javatestcase at yahoo.com> wrote:
Possibily just a simple MVEL error, but I've been struggling for
a while
and thought I'd see if anyone could help.
I just want to run a logic test to determine salience for some rules I am
generating with rules-templates. Even after making the logical test "true"
I can't get any of variation to compile.
(true ? "1000" : "0")
**produces**
Unable to build expression for 'salience' : not a statement, or badly
formed structure
( true ? 1000 : 0)
**produces**
Unable to build expression for 'salience' : invalid number literal: 1000
salience ( getSalience() )
...
function int getSalience(){return 0;}
**produces**
Unable to build expression for 'salience' : org.mvel2.util.MethodStub
cannot be cast to java.lang.Class'( getSalienceNONCDW() )'
Seems like I am missing something simple, but I've tried many variations on
the above, and have been unable to find any working examples of using a
logical test in salience, so if anyone has any direction it would be greatly
appreciated.
Thanks!
Bill