Re: [rules-users] Local Variable
On 09/10/2012, joy wrote: > Hi > > If am declaring a map as global variable. global java.util.Map map > In the "then" part of rule 1 am putting a key n value into map > Is it possible to get the value using the key from the "then" part of rule > 2? Not necessarily so: only if rule 1 fires before rule 2, which may or may not happen. > > Do i want to update,insert like any thing on global variable? > or > How is it possible for rule engine to identify the changes in global > variable tht shud be reflected on other rule! This is answered in the documentation, section 4.5.2., global. -W > > > Regards > joy > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Local-Variable-tp4020144p4020173.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Local Variable
Hi If am declaring a map as global variable. global java.util.Map map In the "then" part of rule 1 am putting a key n value into map Is it possible to get the value using the key from the "then" part of rule 2? Do i want to update,insert like any thing on global variable? or How is it possible for rule engine to identify the changes in global variable tht shud be reflected on other rule! Regards joy -- View this message in context: http://drools.46999.n3.nabble.com/Local-Variable-tp4020144p4020173.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Local Variable
Just to add another option: A variable to set in one and to use in another consequence can also be a static field in some Java class, with (or without - huh!) setter and getter. However, no matter which technique one chooses, setting such a variable in rule A and using its value in rule B creates two dependencies: - the temporal dependency that rule A must execute before rule B - the logical dependency that an execution of rule A with some specific set of facts must "match" the execution of rule B; in other words, one needs to make sure that there is no confusion among multiple executions of rule A and rule B. Only a dynamically created object, inserted logically or not, has a chance to handle these dependencies, with fields in addition to the "value" to be passed on identifying the context, i.e., one or more facts participating in the firing of A. Anything else is playing with fire. -W On 05/10/2012, Davide Sottara wrote: > The concepts of "local" and "accessible to another rule" are a little bit > conflicting :) > This said, as others have already pointed out, there are many ways to > achieve this result, including: > > - globals > - chaining : rule A inserts a fact and "pushes" it (also) into rule B, > which > reacts to its insertion > - facts : both rule A and B see a fact in the WM and match/modify it > - queries : rule A inserts a fact and rule later B pulls it from the WM > > If you could provide some more details about what you're trying to do, we > may be able to recommend the best approach. One thing for sure: the RHS of > different rules live in different scopes, so there is no way > to make a LOCAL variable (i.e. declared locally in a RHS) visible to other > rules' RHSs. > > Best > Davide > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Local-Variable-tp4020144p4020156.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Local Variable
The concepts of "local" and "accessible to another rule" are a little bit conflicting :) This said, as others have already pointed out, there are many ways to achieve this result, including: - globals - chaining : rule A inserts a fact and "pushes" it (also) into rule B, which reacts to its insertion - facts : both rule A and B see a fact in the WM and match/modify it - queries : rule A inserts a fact and rule later B pulls it from the WM If you could provide some more details about what you're trying to do, we may be able to recommend the best approach. One thing for sure: the RHS of different rules live in different scopes, so there is no way to make a LOCAL variable (i.e. declared locally in a RHS) visible to other rules' RHSs. Best Davide -- View this message in context: http://drools.46999.n3.nabble.com/Local-Variable-tp4020144p4020156.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Local Variable
You will be able to set or get a property on an instance of the declared fact. On Oct 5, 2012 6:03 PM, "Devan Van Reenen" wrote: > Not sure if this will help. But perhaps you can have a declared fact that > contains a property/ varIable that you worry about and that you cab use in > your rules. Not sure if this is best practice though. > On Oct 5, 2012 1:48 PM, "joy" wrote: > >> Hi >> >> i need local variables in drl file. >> it should hold integer/double value. >> Setting an integer value to a local variable in some rule and getting that >> integer value in some other rule >> >> when >> #some condition01 >> then >> local variable=200 >> end >> >> when >>#some condition02 >> then >>local variable =300 >> end >> >> when >> #some condition03 >> then >> emp.salary=localvariable+2000 >> end >> >> Anyone plz help me to resolve this. >> >> Thank you >> Joy >> >> >> >> >> -- >> View this message in context: >> http://drools.46999.n3.nabble.com/Local-Variable-tp4020144.html >> Sent from the Drools: User forum mailing list archive at Nabble.com. >> ___ >> rules-users mailing list >> rules-users@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/rules-users >> > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Local Variable
Not sure if this will help. But perhaps you can have a declared fact that contains a property/ varIable that you worry about and that you cab use in your rules. Not sure if this is best practice though. On Oct 5, 2012 1:48 PM, "joy" wrote: > Hi > > i need local variables in drl file. > it should hold integer/double value. > Setting an integer value to a local variable in some rule and getting that > integer value in some other rule > > when > #some condition01 > then > local variable=200 > end > > when >#some condition02 > then >local variable =300 > end > > when > #some condition03 > then > emp.salary=localvariable+2000 > end > > Anyone plz help me to resolve this. > > Thank you > Joy > > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Local-Variable-tp4020144.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Local Variable
Another approach would be to use a transient Fact for the "local variable":- rule "1" when #some condition01 then insertLogical( new MyFact(200) ); end rule "2" when #some condition02 then insertLogical( new MyFact(300) ); end rule "3" when #some condition03 MyFact( $v : value ) then emp.salary=$v+2000 end Of course if Rule "1" and Rule "2" both inserted an instance of MyFact Rule "3" would activate twice. This can be safe-guarded against by checking for the non-existence of MyFact:- rule "1" when #some condition01 not MyFact() then insertLogical( new MyFact(200) ); end rule "2" when #some condition02 not MyFact() then insertLogical( new MyFact(300) ); end rule "3" when #some condition03 MyFact( $v : value ) then emp.salary=$v+2000 end If however you then needed this to work on, for example different employees, you'd need to associated MyFact to the employee:- rule "1" when $e : Employee( position == "grunt" ) not MyFact( employee == $e ) then insertLogical( new MyFact(200, $e) ); end rule "2" when $e : Employee( position == "manager" ) not MyFact( employee == $e ) then insertLogical( new MyFact(300) ); end rule "3" when $e : Employee( position == "grunt" ) MyFact( $v : value, employee == $e ) then modify($e) { setSalary( $v+2000) } end On 5 October 2012 12:46, joy wrote: > Hi > > i need local variables in drl file. > it should hold integer/double value. > Setting an integer value to a local variable in some rule and getting that > integer value in some other rule > > when > #some condition01 > then > local variable=200 > end > > when >#some condition02 > then >local variable =300 > end > > when > #some condition03 > then > emp.salary=localvariable+2000 > end > > Anyone plz help me to resolve this. > > Thank you > Joy > > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Local-Variable-tp4020144.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Local Variable
HI "Globals are not inserted into the Working Memory, and therefore a global should never be used to establish conditions in rules except when it has a constant immutable value. The engine cannot be notified about value changes of globals and does not track their changes" It is what mentioned in documentation about "globals"!!! Is there any detailed documentation or examples where "globals" were used in such a context mention above Thank you Joy -- View this message in context: http://drools.46999.n3.nabble.com/Local-Variable-tp4020144p4020149.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Local Variable
Did you read the documentation about 'globals'? Best Regards, Esteban Aliverti - Blog @ http://ilesteban.wordpress.com On Fri, Oct 5, 2012 at 1:46 PM, joy wrote: > Hi > > i need local variables in drl file. > it should hold integer/double value. > Setting an integer value to a local variable in some rule and getting that > integer value in some other rule > > when > #some condition01 > then > local variable=200 > end > > when >#some condition02 > then >local variable =300 > end > > when > #some condition03 > then > emp.salary=localvariable+2000 > end > > Anyone plz help me to resolve this. > > Thank you > Joy > > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Local-Variable-tp4020144.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Local Variable
Hi i need local variables in drl file. it should hold integer/double value. Setting an integer value to a local variable in some rule and getting that integer value in some other rule when #some condition01 then local variable=200 end when #some condition02 then local variable =300 end when #some condition03 then emp.salary=localvariable+2000 end Anyone plz help me to resolve this. Thank you Joy -- View this message in context: http://drools.46999.n3.nabble.com/Local-Variable-tp4020144.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users