[rules-users] Weighted rules / scoring

Greg Barton greg_barton at yahoo.com
Mon Jun 8 21:40:26 EDT 2009


Don't forget that if you want other rules to react to the changed score you must call update() on the altered object:

rule "Myscoreincreaserule"
     dialect "mvel"
     when
         a : Applicant( name == "chris")
     then
         a.setScore( a.score + 2 );
         update( a );
end

--- On Mon, 6/8/09, Chris Strachan <chris.strac at googlemail.com> wrote:

> From: Chris Strachan <chris.strac at googlemail.com>
> Subject: Re: [rules-users] Weighted rules / scoring
> To: "Rules Users List" <rules-users at lists.jboss.org>
> Date: Monday, June 8, 2009, 1:06 PM
> 
> Hi,
> 
> Don't think I intended to create a new instance, just
> modify the one 
> matched in the rule.  The following seems to have got
> it working.
> 
> rule "Myscoreincreaserule"
>     dialect "mvel"
>     when
>         a : Applicant( name == "chris"
> )
>     then
>         a.setScore( a.score + 2 );
> end
> 
> Thanks for pointing me in the right direction.
> 
> Greg Barton wrote:
> > 1) Where is the variable "score" initialized? If it's
> not a global the rule wouldn't compile.
> >
> > 2) Is your intent to create a new Applicant instance,
> or modify the one matched in the rule?  (Or maybe you
> want to gather the score from the matched instance and put
> it (+2) into a new instance?
> >
> > --- On Sun, 6/7/09, Chris Strachan <chris.strac at googlemail.com>
> wrote:
> >
> >   
> >> From: Chris Strachan <chris.strac at googlemail.com>
> >> Subject: [rules-users] Weighted rules / scoring
> >> To: rules-users at lists.jboss.org
> >> Date: Sunday, June 7, 2009, 1:11 PM
> >> Hi,
> >>
> >>
> >>
> >> I want to be able to use drools / guvnor brms to
> store
> >> weighted rules
> >>
> >> (scoring), however I can't seem to find a way to
> do
> >> this.
> >>
> >>
> >>
> >> I attempted the following,
> >>
> >>
> >>
> >> rule "Myscoreincreaserule"
> >>
> >>         dialect
> "mvel"
> >>
> >>         when
> >>
> >>             
>    Applicant( name ==
> >> "chris" )
> >>
> >>         then
> >>
> >>             
>    Applicant fact0 = new Applicant();
> >>
> >>             
>    fact0.setScore( score + 2 );
> >>
> >>             
>    insert(fact0 );
> >>
> >> end
> >>
> >>
> >>
> >> drools didn't seem to like the way I did this.
> >>  Perhaps this isn't
> >>
> >> permitted, in effect I am trying to do - score =
> score +
> >> 2.
> >>
> >>
> >>
> >> Upon validation I get the following error.
> >>
> >>
> >>
> >>     
>    [Myscoreincreaserule] Unable to build
> >> expression for 'consequence': Failed
> >>
> >> to compile: 1 compilation error(s): - (1,3)
> unqualified
> >> type in strict mode
> >>
> >> for: age ' Applicant fact0 = new Applicant();
> >> fact0.setScore( score + 2 );
> >>
> >> insert(fact0 ); '
> >>
> >>
> >>
> >> Any ideas on how I should be approaching this?
> >>
> >>
> >>
> >> Thanks,
> >>
> >>
> >> -----Inline Attachment Follows-----
> >>
> >> _______________________________________________
> >> 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
> >   
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 


      




More information about the rules-users mailing list