[rules-users] Trouble getting Dynamic Salience working

James Owen jco2009 at att.net
Wed Sep 2 02:07:50 EDT 2009


Just a quick observance, but this is also an excellent example of  
subsumption of rules (almost).  The first rule conditions elements are  
all contained in the second rule.  However, the action items are  
different.  Therefore the first rule should say that the topping does  
not contain sausage nor pepperoni...  Or, the objects could be written  
so that there would be something to flag a cheese-only pizza otherwise  
both rules would fire as written.  :-(

SDG
James Owen
Founder October Rules Fest
Senior Consultant / Architect KBSC
http://www.kbsc.com
http://www.OctoberRulesFest.org
Twitter: OctRulesFest
Blogs:
http://JavaRules.blogspot.com [Rulebased Systems Blog]
http://ORF2009.blogspot.com [October Rules Fest Blog]
http://exscg.blogspot.com/ [Expert Systems Consulting Group Blog]

"If I have seen a little further it is by standing on the shoulders of  
giants."
Sir Isaac Newton in a letter to Robert Hooke, 5 Feb 1676

Come to October Rules Fest and stand on the shoulders of the Giants of  
the industry; if only for a week.



On Sep 1, 2009, at 9:29 PM, Greg Barton wrote:

> I hope you're not going through all of that trouble just to get the  
> functionality from that concrete example.  You get that for free  
> with Drools' default conflict resolution, which includes  
> "specificity."  Specificity means that rules with the more specific  
> conditions, and all else equal, are fired first.  So between these  
> two rules, only the CheeseSausagePepperoniPepper one fires:
>
> rule "CheeseOnly"
> 	when
> 		p : Pizza( )
> 		t1: Topping( pizza == p, name == "cheese" )
> 	then
> 		System.out.println( "Eating cheese pizza" );
> 		retract( t1 );
> 		retract( p );
> end
>
> rule "CheeseSausagePepperoniPepper"
> 	when
> 		p : Pizza( )
> 		t1: Topping( pizza == p, name == "cheese" )
> 		t2: Topping( pizza == p, name == "sausage" )
> 		t3: Topping( pizza == p, name == "pepperoni" )
> 		t4: Topping( pizza == p, name == "pepper" )
> 	then
> 		System.out.println( "Eating cheese sausage pepperoni pepper  
> pizza" );
> 		retract( t4 );
> 		retract( t3 );
> 		retract( t2 );
> 		retract( t1 );
> 		retract( p );
> end
>
> See the attached project.
>
> --- On Tue, 9/1/09, Bill Tarr <javatestcase at yahoo.com> wrote:
>
>> From: Bill Tarr <javatestcase at yahoo.com>
>> Subject: [rules-users]  Trouble getting Dynamic Salience working
>> To: rules-users at lists.jboss.org
>> Date: Tuesday, September 1, 2009, 7:28 PM
>> 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_@{row.rowNumber}"
>>
>>     activation-group "@{PARAM1}-@{PARAM2}"
>>     salience ( return getSalience@{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@{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
>>
>>
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
>
> < 
> DroolsSpecificity 
> .tar.gz>_______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090902/24ddb9c7/attachment.html 


More information about the rules-users mailing list