[rules-users] parametrized rules

Wolfgang Laun wolfgang.laun at gmail.com
Mon Apr 2 12:22:51 EDT 2012


Or put a little logic in facts, e.g.

kSession.insert( new Season( 1, 1, 31, "Winter" ) )
// ... 15 more

rule matchSeason
when
    Season( $x: x, $y: y, $z:z, $s: s );
    $t: Thing( month == $x, day >= $y && <= $z )
then
    modify( $t ){ setSeason( $s ) }
end


On 02/04/2012, Michael Anstis <michael.anstis at gmail.com> wrote:
> Sure, look at using Templates.
>
> On 2 April 2012 15:18, Tim van Heugten <stimme at gmail.com> wrote:
>
>> Hi all,
>>
>> I'm new to Drools, and wonder how I can most cleanly write down rules for
>> the following.
>>
>> (For the sake of example) Say I have an object that needs to be processed
>> season-dependent. I basically need a rule like:
>> rule
>>     when
>>         Date( month == X, day >= Y, day <= Z)
>>         // Some date containing object
>>     then
>>         System.out.println("Season is "+R)
>>         // Store season in associated object
>> end
>>
>> And fill in X, Y, Z and R with:
>> X    Y    Z    R
>> 1    1    31    Winter
>> 2    1    29    Winter
>> 3    1    21    Winter
>> 3    22    31    Spring
>> 4    1    30    Spring
>> 5    1    31    Spring
>> 6    1    21    Spring
>> 6    22    30    Summer
>> 7    1    31    Summer
>> ...
>>
>>
>> Should I expand all this rules by hand, and define 16 rules in my rule
>> file? Or can I parametrize the rules and have this done automagically?
>>
>> Thanks a lot,
>>
>> Tim van Heugten
>>
>> _______________________________________________
>> 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