'else' in rule

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

'else' in rule

snehils
Hi All,

I want to take action when the condition in WHEN fails. Something like as follows:

WHEN
        <Condition>
THEN
        <Action>
ELSE
        <Action when Condition fails>


Is it possible to have else part in rule? Or I have to make another rule for failed condition?
I am using Drools 5.1.0 version.
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] 'else' in rule

Mark Proctor
On 18/08/2011 10:26, snehils wrote:

> Hi All,
>
> I want to take action when the condition in WHEN fails. Something like as
> follows:
>
> WHEN
>          <Condition>
> THEN
>          <Action>
> /ELSE
>          <Action when Condition fails>/
for now you will need to do it as two rules. We are looking into adding
else, probably later this year.

Mark

>
> Is it possible to have else part in rule? Or I have to make another rule for
> failed condition?
> I am using Drools 5.1.0 version.
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/else-in-rule-tp3264337p3264337.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] 'else' in rule

ronalbury
Please consider the possibility of

When

Then

When

Then

Else
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] 'else' in rule

Mark Proctor
On 05/12/2011 18:43, ronalbury wrote:

> Please consider the possibility of
>
> When
>
> Then
>
> When
>
> Then
>
> Else
It's already specced up in "relational data flows" which allows a
tree-like data flow for your decision:
http://community.jboss.org/wiki/RelationalDataFlows

I hope that it, or a variation on it, is delivered in 2012.

Mark
> --
> View this message in context: http://drools.46999.n3.nabble.com/else-in-rule-tp3264337p3562187.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] 'else' in rule

laune
The request for "else" is not as simple as it may seem. (Has the
fundamental difference between a rule and an if statement impregnated
itself?)

Given rules
   when Car(color=Color.RED) then
   when Car(color=Color.BLUE) then
and assuming that we have an "else" linked to these rules,
how should this "else" rule fire?

(a) Fire once, when there are no RED or BLUE Car facts ano no other
Car facts at all.
(b) Fire once, when there are no RED or BLUE cars but when there is at
least one Car fact, with any other color.
(c) When there are no RED or BLUE cars, but fire once for each Car
that has any other color.
(d) Irrespective of the presence or absence of RED and BLUE Car facts,
once for each Car that has any other rule.

I am, of course, assuming that rules do not fire mutually exclusive;
hence an "else" could fire even when one of its associated "when"
rules should fire.

There is, of course, a thing called "decision tree", and it's
legitimate to expect that a "decision making system" should provide
this technique (just like "decision tables"). But I think it should
not be tacked onto rules (and you may not even need a Rete engine for
that) - the user confusion is bound to reach new levels.

-W







On 06/12/2011, Mark Proctor <[hidden email]> wrote:

> On 05/12/2011 18:43, ronalbury wrote:
>> Please consider the possibility of
>>
>> When
>>
>> Then
>>
>> When
>>
>> Then
>>
>> Else
> It's already specced up in "relational data flows" which allows a
> tree-like data flow for your decision:
> http://community.jboss.org/wiki/RelationalDataFlows
>
> I hope that it, or a variation on it, is delivered in 2012.
>
> Mark
>> --
>> View this message in context:
>> http://drools.46999.n3.nabble.com/else-in-rule-tp3264337p3562187.html
>> Sent from the Drools: User forum mailing list archive at Nabble.com.
>> _______________________________________________
>> rules-users mailing list
>> [hidden email]
>> https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] 'else' in rule

ronalbury
I agree that I jumped in on an effort to define a requirement in terms of a solution ... however, people generally understand else and otherwise, so there is some justification in saying you want something to work like them.

I don't care what the underlying mechanism is, but as it stands now we have to write a rule "When (condition-A)" and then another rule "When not (condition-A)" ... and I think that makes the rules more difficult to understand and to maintain.

Thanks
   Ron
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] 'else' in rule

JimK
My $.02
I'm early in my use of Drools and Rules and struggled at first with the lack of ELSE.  At first I would frequently feel "an ELSE would be prefect here".  After awhile I believe that NOT having Else is a good thing.   As I get better with writing rules I find that most of the times when I think I need an Else it usually means I should take a closer look at the rule.  

If I have a true Else situation for me I put the two rules one right after another. In these situations I think it is better to have to write the "ELSE" rule as effectively a NOT of the WHEN rule then having an ELSE fall through. Isn't that much extra coding and usually gives me pause to give it one more evaluation to see if this is a true ELSE or a new rule with similar criteria from the When.

Many times the ELSE covers too many possibilities that should be explicitly checked and for me at least tells me I might not have fully broken the requirements down.  As another posting indicates the complexity of implementing it I also wonder about the performance hit the logic to allow for an ELSE would add.

With my current understanding of business rules and drools I would vote against an ELSE.

Jim K.
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] 'else' in rule

Mark Proctor
On 06/12/2011 19:08, JimK wrote:

> My $.02
> I'm early in my use of Drools and Rules and struggled at first with the lack
> of ELSE.  At first I would frequently feel "an ELSE would be prefect here".
> After awhile I believe that NOT having Else is a good thing.   As I get
> better with writing rules I find that most of the times when I think I need
> an Else it usually means I should take a closer look at the rule.
>
> If I have a true Else situation for me I put the two rules one right after
> another. In these situations I think it is better to have to write the
> "ELSE" rule as effectively a NOT of the WHEN rule then having an ELSE fall
> through. Isn't that much extra coding and usually gives me pause to give it
> one more evaluation to see if this is a true ELSE or a new rule with similar
> criteria from the When.
>
> Many times the ELSE covers too many possibilities that should be explicitly
> checked and for me at least tells me I might not have fully broken the
> requirements down.  As another posting indicates the complexity of
> implementing it I also wonder about the performance hit the logic to allow
> for an ELSE would add.
>
> With my current understanding of business rules and drools I would vote
> against an ELSE.
What is currently in early propsoal stage is a sort of directional data
flow concept:
http://community.jboss.org/wiki/RelationalDataFlows

While there is no 'else' keyword you can control the direction of flow
from failure of a tuple to propagate, this allows you create tree like
data structures to handle the flow, which can solve "else" like situations.

For me the most interesting and useful construct there will be the
"case" statement, which I find I often need.  I'm looking to be able to
better handle signal processing type problems, that people might use
languages such as erlang for.

Mark

>
> Jim K.
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/else-in-rule-tp3264337p3565278.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] 'else' in rule

Spyros Sakellariou-2
In reply to this post by snehils
CONTENTS DELETED
The author has deleted this message.