[rules-users] Intermediate conclusions using strings
David Cracauer
dcracauer at earthlink.net
Mon Aug 25 13:06:45 EDT 2008
We've encountered a similar situation where there were many paths to
the same conclusion, and we needed to track them. We found the best way
was to create a new Object that is created in the lhs and inserted.
The below pseudo code should illustrate what I'm talking about.
Hopefully it makes sense:
public class MembershipLevel{
private Person person;
private Date memberSince;
private Level level;
private Number revenue;
public MembershipLevel(Person person, Date memberSince, Level level,
Number revenue){
...
}
//getters and setters
//appropriate equals/hashCode
}
rule "gold member if revenue per month > 1000"
when ...
then
insert( new MemberShipLevel(person, Level.GOLD, revenue);
end
rule "gold member since 1999 gets a t-shirt"
when
m:MemberShipLevel( memberSince < '2000-01-01');
then
TShirtFactory.sendShirtTo(m.getPerson());
end
This allows you to have more than one person in the engine at once,
and you can track what caused the calculations.
On Aug 25, 2008, at 6:09 AM, David Boaz wrote:
>
> Hi all,
>
> I have an idea and I want to get the community feedback.
>
> Many times there are many ways to reach an intermediate conclusion.
> This
> conclusion can be used to derive higher level conclusions or actions.
> For example, assuming a credit application has several (or) options to
> conclude whether a parson is classified as gold member. Then, other
> rules
> need this information to determine the credit limit for that member.
> To
> note, the Person java class doesn't have a specialized attribute for
> the
> classification. The classification is only an internal means to
> simplify the
> application logic.
> To solve that problem, I thought to insert a string conclusion to
> the WM.
> Something like:
>
> rule "gold member if revenue per month > 1000"
> when ...
> then insert("gold member")
> end
>
> rule "gold member if total amount > 1000000"
> when ...
> then insert("gold member")
> end
> ...
> rule r100
> when String(value=="gold member")
> then...
> end
>
> * Is it an appropriate approach?
> * I know it ugly to use the same string literal in various rules.
> Can we
> avoid that?
> * Is there a known mechanism to handle these cases?
>
> Thanks, David
> --
> View this message in context: http://www.nabble.com/Intermediate-conclusions-using-strings-tp19141834p19141834.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
More information about the rules-users
mailing list