[rules-users] Help -- Conditional Logic in DRL
Greg Barton
greg_barton at yahoo.com
Tue Jun 16 01:57:57 EDT 2009
Note to drools devs: I didn't put the original poster up to this. :)
Globals should be considered immutable, so shouldn't be used in this way. You could do it with an object asserted in working memory, though.
Just as good, though, you can use this kind of pattern to replicate else logic:
rule "EverythingMatches"
when
Condition0
Condition1
Condition2
then
...
end
rule "ElseAtCondition2"
when
Condition0
Condition1
!Condition2
then
...
end
rule "ElseAtCondition1"
when
Condition0
!Condition1
then
...
end
rule "ElseAtCondition0"
when
!Condition0
then
...
end
--- On Mon, 6/15/09, Scott Reed <sreed at avacoda.com> wrote:
> From: Scott Reed <sreed at avacoda.com>
> Subject: Re: [rules-users] Help -- Conditional Logic in DRL
> To: "Rules Users List" <rules-users at lists.jboss.org>
> Date: Monday, June 15, 2009, 10:19 PM
> Looks like 5 rules with a global flag
> might work:
>
> global boolean flag = false;
>
> rule "name1"
> when
> (condition1 == true )
> (flag == false)
> then
> consequence1();
> flag = true;
> end
>
> ...
>
> rule "name5"
> when
> (condition5 == true )
> (flag == false)
> then
> consequence5();
> flag = true;
> end
>
> Does that work for you?
>
> Vishy [6/15/2009 11:06 PM] wrote:
> > Hi All,
> >
> > I am new to drools...and am trying to figure out as to
> how I can
> > represent the following logic in a DRL file.
> >
> > if (condition1) {
> >
> > if (condition2) {
> >
> > } else if (condition3) {
> >
> > } else if (condition 4) {
> >
> > } else if (condition 5) {
> >
> > }
> >
> > }
> >
> > In DSL, a typical rule is represented as follows:
> >
> > rule "name"
> >
> > when
> > condition is true
> > then
> > consequence
> >
> > end
> >
> > How can I represent the above mentioned if - else
> logic in DSL? Or is
> > it not possible?
> >
> > If it is not, can you please suggest any alternative?
> >
> > Thanks much!!
> > _______________________________________________
> > 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