[rules-users] Nested Rules

techy techluver007 at gmail.com
Wed Nov 5 20:24:21 EST 2008


Hello,
I have similar doubt. Please clarify.

I have r1,r2 in rfg1 and r3,r4 in rfg2. 
1. execute rg2 after rg1. this can be in rule flow. no issue.
2.I want to execute r2 for facts where r1 is true. how can I do this without
using semaphore fact or r1 conditions in r2 LHS in rule flow?
3.I want to execute rfg2 rules after rg1 for facts where r1 is true and r2
is false. same question of executing rfg2 rules without using semaphore fact
or r1,r2 condition?

In order to achieve above flow, I can only think following way with my
limited knowledge in drools. Maintain the state in the fact(using some flag 
as given below) for each rule execution and use it in other rules to
determine whether it can be executed or not for that fact.

Ex: I can have a fact in this structure for this scenario.
Fact{isR1executed,isR2Executed and other fields of facts}

 rule r1
 rule-flow-group rfg1
  when r1 condition is true
  then
    isR1executed = true;
     do something;
 

rule r2
rule-flow-group rfg1
  when isR1executed = true, r2 condition is true
  then
   isR2executed = true; 
  do something; 


  rule r3
 rule-flow-group rfg2
   when  isR1executed = true,isR2executed = false, r3 condition is true
   then 
     do something


  rule r4
 rule-flow-group rfg2
  when  isR1executed = true,isR2executed = false, r4 condition is true
   then 
     do something
 
 Even if I use split node between rfg1 and rfg2, I have to check r1 is true
and r2 is false there before going to  rfg2  flow.


Thanks




Anstis, Michael (M.) wrote:
> 
> Erm, Rule Flow springs immediately to mind.
>  
> Or you can use semaphore Facts yourself - but you're re-inventing the
> (Rule
> Flow) wheel.
>  
> rule "rule 1"
>     when
>         condition is true
>     then
>         insert(new SemaphoreFact());
>     end
>  
> rule "rule 2"
>     when
>         SemaphoreFact()
>         Some other conditions are true;
>     then
>         action
>     end
>  
> rule "rule 3"
>     when
>         Even more conditions
>     then
>         action
>     end
>  
> 
> 
>   _____  
> 
> From: rules-users-bounces at lists.jboss.org
> [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Vishal Deshmukh
> Sent: 22 May 2008 10:31
> To: rules-users at lists.jboss.org
> Subject: [rules-users] Nested Rules
> 
> 
> Hi
>  
> I  am using Drools 4.0.4 with Eclipse 3.2. I m much happy with the
> results.
> But now my application needs nested loops..
> Can i write nested rules like 
>  
> rule "rule 1 "         // if condition of rule 1 is true then only execute
> rule 2 other wise skip it
> when
>     condition is true
> then
>     execute rule2
>  
> rule "rule 2 "
> when
>     condition is true
> then
>     action
>  
> rule "rule 3"
> when 
>       condition is true
> then
>      action
>  
> Thanks and Rgards
>  
> Vishal
> 
> 
> 
> 
>  
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: http://www.nabble.com/Nested-Rules-tp17400813p20353543.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list