[rules-users] Salience

Swindells, Thomas TSwindells at nds.com
Thu Jan 20 04:49:41 EST 2011


Another way is to have a helper fact to help with the logic.
In our case we have an "Affirmation" class with the tuple (name, subject, value).
However salience does still have a purpose and is still a useful and required tool to order groups of rules - you just have to make sure you don't abuse it.

rule "#1"
when
  $i : Item(type == 1)
then
   modify ($i)
   // do something...
   insert(new Affirmation("ItemProcessed", $i))
end

rule "#2"
when
  $i : Item(type == 2)
then
  modify ($i)
  // do something...
  insert(new Affirmation("ItemProcessed", $i))
end

// to handle other type of Item
rule "#catch-all"
salience -10
when
  $i : Item()
  not Affirmation(name == "ItemProcessed", subject == $i)
then
  modify ($i)
  // do something...
  insert(new Affirmation("ItemProcessed", $i))
end


> -----Original Message-----
> From: rules-users-bounces at lists.jboss.org [mailto:rules-users-
> bounces at lists.jboss.org] On Behalf Of Wolfgang Laun
> Sent: 19 January 2011 18:57
> To: Rules Users List
> Subject: Re: [rules-users] Salience
>
> Either you define a rule covering all "else" cases, which, in your
> case, could be
>
> rule "#catch-all"
> when
> $i : Item(  type != 1 && != 2  )
> then
> retract ($i)
> // do something...
> end
>
> or you do  rely on salience, which, in this case is not quite so "bad
> practice".
>
> It depends:  if the "catch all" is there to detect unexpected data,
> it's ok; if it is there just to cover several cases the programmer is
> too lazy to code in the ordinary way, then it might be considered "bad
> practice".
>
> -W
>
>
>
> On 19 January 2011 19:17, huionn <huionn at gmail.com> wrote:
> >
> > If I have a rule like below:
> >
> > rule "#1"
> > when
> > $i : Item(type == 1)
> > then
> > retract ($i)
> > // do something...
> > end
> >
> > rule "#2"
> > when
> > $i : Item(type == 2)
> > then
> > retract ($i)
> > // do something...
> > end
> >
> > // to handle other type of Item
> > rule "#catch-all"
> > salience -10
> > when
> > $i : Item()
> > then
> > retract ($i)
> > // do something...
> > end
> >
> > As it is known, reliance on salience is bad practice and its order is not
> > guaranteed (as shown in Sudoku example).
> >
> > My question is: what is the simple and good practice to emulate "else" (rule
> > "#catch-all") without reliance on salience? It seems ruleflow is not
> > applicable here as well.
> >
> >
> > Thanks and best regards.
> > --
> > View this message in context: http://drools-java-rules-
> engine.46999.n3.nabble.com/Salience-tp2289179p2289179.html
> > Sent from the Drools - User mailing list archive at Nabble.com.
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users


**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster at nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************




More information about the rules-users mailing list