[rules-users] Inconsistent output when @PropertyReactive is used
Below is a test to demonstrate it, also add the @PropertyReactive property to MyClass() package com.sample; rule base when m : MyClass(data == null) then end rule 2 extends base when String() MyClass(value != test) from m then System.out.println(2 fired); end rule 1 extends base salience 1 when MyClass(value == null) from m then System.out.println(1 fired); insert(new String()); modify(m) { setValue(test) } end The test above should output 1 fired and 2 fired. Although we have set the value to test, rule 2 supposes to not fire, but it is in fact expected to fire due to the non-reactive property of CE from, and the result confirms this. But if we reorder the code in rule 1 to rule 1 extends base salience 1 when MyClass(value == null) from m then System.out.println(1 fired); modify(m) { setValue(test) } insert(new String()); end Then you get only 1 fired, as if CE from is reactive again. This only happens when you have the @PropertyReactive property added to MyClass() Version tested are 5.5.0.Final and 5.6.0.Final Could the Drools team review this? Thank you. -- View this message in context: http://drools.46999.n3.nabble.com/Inconsistent-output-when-PropertyReactive-is-used-tp4027709.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] Inconsistent output when @PropertyReactive is used
Mark Proctor wrote property reactive will not work with ‘from’. Mark Yes I am aware of that and I stated that on my post already. But this will not work with ‘from’ is not consistence, making the result unpredictable. -- View this message in context: http://drools.46999.n3.nabble.com/Inconsistent-output-when-PropertyReactive-is-used-tp4027709p4027712.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] Inconsistent output when @PropertyReactive is used
Thanks very much for the detailed explanation Mark Proctor and Davide Sottara! I really wouldn't have thought that the ordering of code matters here while they are logically equivalent. And to understand that is actually required to be at very low level... So to sum up, when you have @PropertyReactive 1. from conditions are not re-evaluated 2. unless it has another non from condition preceding it and that condition is re-evaluated (by insert or modify) and this is expected behaviour. -- View this message in context: http://drools.46999.n3.nabble.com/Inconsistent-output-when-PropertyReactive-is-used-tp4027709p4027715.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] Can When part of DRL contains simple logics?
laune wrote There is no magic wand. But for any expression evaluation on the LHS that occurs frequently, ask yourself whether the data is optimal. For instance: rather than testing repeatedly whether some date in a fact plus three days is greater than today, compare that date to a constant date computed once as today minus three days. -W I think we are better off if Drools can cache LHS values -- View this message in context: http://drools.46999.n3.nabble.com/Can-When-part-of-DRL-contains-simple-logics-tp4027677p4027690.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] forall is satisfied when there is nothing?
laune wrote On 08/01/2014, Davide Sottara lt; dsotty@ gt; wrote: Indeed it is true by convention, see also http://en.wikipedia.org/wiki/Universal_quantification The only other alternative is to deprecate quantifiers altogether ;) Ah, *by convention*, yes. One should exercise some care with vacuous truths, however. Uttering statements such as All the little green men in my room are from Mars may not brand you as a liar, but you could be called batty. ;-) -W Davide Guys, I am not sure whats the arguing point here. But from a programmer's and a Drools engine user's perspective, I would find forall(void) to return false more convenient. Say for example: forall(Cloth(dried)) then collect() Programmingwise, I dont want to execute collect() when the Cloth() collection is empty and do extra null checkings. Performancewise, I also dont want to call collect() when there is actually nothing to perform. In terms of semantics, I purposely want to check for isDried is true, it is easy to realize from the LHS that I only want to collect clothes when all of them are dried, rather than I want to collect also empty air. On the contrary, if I really want to do the RHS even though the LHS has nothing, I would have written: not( exists( Customer() ) ) then takeanap() and I will not write forall( Customer(status == gone) ) then takeanap() because the latter needs to do extra property visits and string comparisons and it is so indirect to express what I really want. I really dont care what the mathematical definition is unless you tell me Drools is a math. engine rather than a rule engine to express business requirements. That, I should update myself and take a step back to look at Drools again. Just my own opinion :P -- View this message in context: http://drools.46999.n3.nabble.com/forall-is-satisfied-when-there-is-nothing-tp4027553p4027593.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] forall is satisfied when there is nothing?
Davide Sottara wrote This is actually the way it is implemented internally, and no, I don't think that it would be appropriate to change it. Yes I agree, so may be we users actually do not need forall, but *every*, which just means forall and exists Now, look at it again: when every Cloth( dried ) then collect() See how pretty it is, simple beauty, fully expressive, just like a sentence :) as oppose to when forall Cloth ( dried ) AND exists Cloth() then collect() X( Nah, I guess people can live with that :P -- View this message in context: http://drools.46999.n3.nabble.com/forall-is-satisfied-when-there-is-nothing-tp4027553p4027598.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] forall is satisfied when there is nothing?
Hi, I am using the forall keyword on the LHS and it seems the condition is satisfied when there is nothing to match. e.g. forall (MyClass(value == test)) fires the rule when there is no MyClass() object in the working memory. My workaround is add exists (MyClass()). Also, same for not (exists (MyClass(value != test))), but I can understand this, as there is no MyClass() object, it doesn't exists and hence not gives true. But for forall, it doesnt sound right to me. I wonder if forall is actually implemented as not exists in the engine. Please clarify if this is by design or a bug. Build is 5.5.0.Final Thank you -- View this message in context: http://drools.46999.n3.nabble.com/forall-is-satisfied-when-there-is-nothing-tp4027553.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] Adding @PropertyReactive causes the other rules removed from the stack
Davide Sottara wrote Confirmed, works as expected in 5.6.CR1 Davide Thanks, but does that mean that it is bugged in 5.5.0 and is not going to be patched in 5.5.x? -- View this message in context: http://drools.46999.n3.nabble.com/Adding-PropertyReactive-causes-the-other-rules-removed-from-the-stack-tp4027374p4027428.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] Adding @PropertyReactive causes the other rules removed from the stack
Davide Sottara wrote The goal of @propertyReactive is exactly to prevent rules from refiring on a modify, based on what properties are constrained or @watched. This is irrelevant with respect to the order of the rules. This may or may not be a bug, we'd need to see the rules. Davide Example attached ReactiveTest.java package com.sample; import org.drools.KnowledgeBase; import org.drools.KnowledgeBaseFactory; import org.drools.builder.KnowledgeBuilder; import org.drools.builder.KnowledgeBuilderFactory; import org.drools.builder.ResourceType; import org.drools.io.ResourceFactory; import org.drools.logger.KnowledgeRuntimeLogger; import org.drools.logger.KnowledgeRuntimeLoggerFactory; import org.drools.runtime.StatefulKnowledgeSession; public class ReactiveTest { public static final void main(String[] args) { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newClassPathResource(Sample.drl), ResourceType.DRL); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); ksession.insert(new MyClass()); ksession.fireAllRules(); } } MyClass.java package com.sample; import org.drools.definition.type.PropertyReactive; @PropertyReactive public class MyClass { private String value; public String getValue() { return value; } public void setValue(String value) { this.value = value; } } Sample.drl package com.sample; rule 1 when MyClass(value == null) then System.out.println(Rule 1 fired); end rule 2 when m : MyClass(value == null) then modify(m) { setData(test) } end rule 3 when MyClass(value == null) then System.out.println(Rule 3 fired); end So you can see from the example, rule 1, rule 2 and rule 3 are all added to the stack ready to be fired. Rules are then fired starting from the bottom, where rule 3 fired and then rule 2 fired. But rule 1 is being removed from the stack after rule 2 has fired, which is a mystery to me. Try to remove modify(m) to just m.setData(test) in rule 2, all three rules fired. So I agree to your prevent rules from refiring, but this case is not even fired yet. -- View this message in context: http://drools.46999.n3.nabble.com/Adding-PropertyReactive-causes-the-other-rules-removed-from-the-stack-tp4027374p4027382.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] Adding @PropertyReactive causes the other rules removed from the stack
Of course, a workaround is to add @watch(value) to rule 1, but thats really weird. -- View this message in context: http://drools.46999.n3.nabble.com/Adding-PropertyReactive-causes-the-other-rules-removed-from-the-stack-tp4027374p4027383.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] Adding @PropertyReactive causes the other rules removed from the stack
So I have a few rules for example, the rules are fired from bottom to top and I reckon once a rule in between calls modify, the rules above it will not be fired, although they should be. This happens when I add @PropertyReactive to my class. Drools version is 5.5.0.Final. Please advise if this has been fixed in 5.5.1? Thank you -- View this message in context: http://drools.46999.n3.nabble.com/Adding-PropertyReactive-causes-the-other-rules-removed-from-the-stack-tp4027374.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] Any easy way to avoid inserting same id object into memory?
Thanks I made a search and it seems it is controlled by a config to switch between identity or equality. Since I can only write rules, I can't enjoy the advantage of that. I ended up writing a retract rule to retract the same (equal) object from memory with higher salience. So everytime some rules insert a new object, this rule will fire to remove the object if they have the same id. -- View this message in context: http://drools.46999.n3.nabble.com/Any-easy-way-to-avoid-inserting-same-id-object-into-memory-tp4027102p4027182.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] Any easy way to avoid inserting same id object into memory?
Hi, I have a rule that on its RHS, it creates new objects with random content and inserts them. How do you check if the object already exists in drools memory? I am thinking to use kcontext.getKnowledgeRuntime().getObjects() in the RHS to loop for all the objects and stop inserting if an object with same content exists. Is there any better way? May be like using query? Drools ver is 5.5.0.Final Thank you -- View this message in context: http://drools.46999.n3.nabble.com/Any-easy-way-to-avoid-inserting-same-id-object-into-memory-tp4027102.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] Binding mysteries
Hi, got a few questions about binding variables, hope someone can help out, thanks. 1. Does binding actually cache the result for the RHS? example: rule no binding when c : MyClass(member1 != member2) then c.somemethod(imp.getMember1()); end rule with binding when c : MyClass(m : member1, member1 != member2) then c.somemethod(m); end Does no binding call getMember1() twice while with binding calls getMember1() once and cache the result to m? Or are both the same? 2. Is the practice to bind before or after? example rule binding after when c : MyClass(member1 != member2, m : member1) then c.somemethod(m); end Is there any difference between with binding and binding after? 3. Is bind and use in the LHS any better? example rule binding and use when c : MyClass(m : member1, m != member2) then c.somemethod(m); end Is there any difference between with binding and binding and use? 4. Why binding with constraint is not recommended? example rule binding with constraint when c : MyClass(m : member1 != member2) then c.somemethod(m); end In the expert manual, Drools 5.5.0 section 4.8.3.3.5. Binding variables, it said // Not recommended Person( $age : age * 2 100 ) // Recommended (separates bindings and constraint expressions) Person( age * 2 100, $age : age ) Although I know $age : age * 2 100 is binding $age to age *ONLY*, while $age : (age * 2 100) is binding $age to the result of (age * 2 100). Is the recommendation only about this safety precaution? Thank you so much for answering. -- View this message in context: http://drools.46999.n3.nabble.com/Binding-mysteries-tp4026999.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] What is the side-effect of using the CE from?
Sorry forgot to mention this is 5.5.0.Final Could someone from the Drools team shed some light on topic? -- View this message in context: http://drools.46999.n3.nabble.com/What-is-the-side-effect-of-using-the-CE-from-tp4026368p4026414.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] What is the side-effect of using the CE from?
Hi, I remember seeing some best practice and since then it has been in my mind that the Drools team actually against the use of CE from. I do however find it really useful and use it alot (and in fact everywhere). Could the Drools team clear this up? For example, I found it useful because 1. When a fact is inserted into the working memory, from conditions are not evaluated. This is good because the fact may not be ready yet (e.g. need updating to fill in more stuff to complete it in some rules) and evaluating the fact too early may cause exceptions. Using from does not suffer from this issue. 2. Also, this is good because I dont get unnecessary calls to getters of that newly inserted fact for all the rules in the kbase with the class of that fact in the LHS because they may not be triggered at the end (e.g. filtered by agenda-groups, activation-groups). I put auditing codes on my getters to track usage and profiling, hence each call to getters is quite expensive for me (elapse time recording, database updating, etc.) 3. Once a preceding from condition fails, all the subsequent from conditions will not be evaluated. Again, this is good to save unnecessary member accesses to boost performance. I know what I dont get using from is same pattern node sharing (i.e. same condition pattern across rules is evaluated only once when from is not used), but it seems to me that the pros outweigh the cons. Thanks the Drools team for clarifying -- View this message in context: http://drools.46999.n3.nabble.com/What-is-the-side-effect-of-using-the-CE-from-tp4026368.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] Any way to make an AgendaEventListener always attach to any ksession from the same kbase?
Sorry I somehow thought you are one of the Drools team members (or a code contributor) because you are quite active on the forum. Oh and thanks for answering :) -- View this message in context: http://drools.46999.n3.nabble.com/Any-way-to-make-an-AgendaEventListener-always-attach-to-any-ksession-from-the-same-kbase-tp4025964p4026042.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] Any way to make an AgendaEventListener always attach to any ksession from the same kbase?
laune wrote No, there isn't, and there are good reasons not to add it. Thanks for letting me know. It would be great if you can also let us know the team's reasons behind this decision. -- View this message in context: http://drools.46999.n3.nabble.com/Any-way-to-make-an-AgendaEventListener-always-attach-to-any-ksession-from-the-same-kbase-tp4025964p4025988.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] Any way to make an AgendaEventListener always attach to any ksession from the same kbase?
Hi, I have been adding AgendaEventListener to any newly created ksession. Once the session disposed, will have to add again to the next ksession. Is there a way (like an option or config) to set the listener to the kbase, so that all the ksession coming from that kbase has this listener by default? Thank you -- View this message in context: http://drools.46999.n3.nabble.com/Any-way-to-make-an-AgendaEventListener-always-attach-to-any-ksession-from-the-same-kbase-tp4025964.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] What are Recursion Rules. Any example
Usually when you modify or insert inside the RHS then you open the door to recursion. e.g. rule loop when not Object() then System.out.println(Hi); insertlogical(new Object()); end -- View this message in context: http://drools.46999.n3.nabble.com/What-are-Recursion-Rules-Any-example-tp4025617p4025631.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] How do you explicitly uses a designated DSL file when parsing dslr?
Hi, I have added more than one DSL files into the KnowledgeBase (with conflicting definitions). It seems that even though I have stated expander A.dsl or expander B.dsl in my dslr it still uses the first dsl that I added into the KnowledgeBase then the second dsl to parse my dslr. Meaning that the definitions in A.dsl persisted when it comes to conflicting definitions. Is expander there for other purpose or there is simply no way to specific which dsl to use? Otherwise how do you specific any dsl for your dslr except to create a new KnowledgeBuilder each time the dslr is required and add only the dsl it needs by looking into the dslr file? I am using 5.5.0.Final, thank you! -- View this message in context: http://drools.46999.n3.nabble.com/How-do-you-explicitly-uses-a-designated-DSL-file-when-parsing-dslr-tp4025365.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] How do you explicitly uses a designated DSL file when parsing dslr?
Thanks Stephen, I am curious too and shorta testing it. But good to know its happening to you as well. -- View this message in context: http://drools.46999.n3.nabble.com/How-do-you-explicitly-uses-a-designated-DSL-file-when-parsing-dslr-tp4025365p4025377.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] Importing functionS from another drl in 5.5.0
Mark Proctor wrote Unfortunately not, and in 6.0 that won't be possible as there is stricter class loader isolation between drl namespace files (limitation of a dynamic system on the JVM). However functions are just static java methods, and those work fine too, when defined on a class in the parent class loader. Mark Thanks Mark. So in 6.0, we are not even able to use drl functions from another drl? I sort of require that because I will have rules that are added to the kbase in runtime with updated functions. Then what about this? If I create a java class with all the static functions wrapped in jar (instead of defining them in drl), would that be possible to dynamically load the jar into the current kbase first and then let those rules added in runtime to use functions from that jar by simply adding import function mydynamicjar.MyFunc.*; ? A simple code snippet on how to achieve that would be nice, thanks a lot! -- View this message in context: http://drools.46999.n3.nabble.com/Importing-functionS-from-another-drl-in-5-5-0-tp4025050p4025053.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] Importing functionS from another drl in 5.5.0
If you have defined functions in a drl, in order to use those functions in another drl of a different package, you will have to import each individual function, like package A; function void func1 () { System.out.println(Hello); } function void func2 () { System.out.println(There); } pacakge B; import function A.func1.func1; import function A.func2.func2; rule Test when then func1(); func2(); end Is there any way to do something like import function A.*; in Drools 5.5.0 to use all the functions defined in another drl? Thank you -- View this message in context: http://drools.46999.n3.nabble.com/Importing-functionS-from-another-drl-in-5-5-0-tp4025050.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] Replacing an old function in drl
Hi, I want to replace an outdated function defined in a drl file without touching that file, is this possible? (in 5.5.0) The java application part that loads the resources cannot be touched as well. It is configured to read all the drl files from a predefined folder, I am only allowed to add-in new drl files. Here are what I have tried: 1. Create a new drl file with the new function with same package name and same function name This works *only* if the new file is loaded after the old file. As I cannot change how the java application loads the resources, I cannot guarantee the new file is always loaded after the old one, so I tried the next method. 2. Create a new drl file with the new function with same function name. Add a rule with high salience and call drools.getKnowledgeRuntime().getKnowledgeBase().removeFunction(old_package, oldFunc); Function newFunc = ((org.drools.impl.KnowledgeBaseImpl)drools.getKnowledgeRuntime().getKnowledgeBase()).getRuleBase().getPackage(new_package).getFunctions().get(oldFunc); // a new implementation with the same name ((org.drools.impl.KnowledgeBaseImpl)drools.getKnowledgeRuntime().getKnowledgeBase()).getRuleBase().getPackage(old_package).addFunction(newFunc); But this didn't work. When the rules are fired, it complains about the old_package cannot find the function anymore. Could anyone from the Drools team provide some help on this? Thanks a lot! -- View this message in context: http://drools.46999.n3.nabble.com/Replacing-an-old-function-in-drl-tp4024956.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] Replacing an old function in drl
No worries. I found another solution: use newByteArrayResource to build the new function and load it into the current kb. But still, I would like to know the solution to method 2. Cheers, -- View this message in context: http://drools.46999.n3.nabble.com/Replacing-an-old-function-in-drl-tp4024956p4024957.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] Simpler API to access the Rule object in RHS?
Hi, right now I am using this ((org.drools.impl.KnowledgeBaseImpl)drools.getKnowledgeRuntime().getKnowledgeBase()).getRuleBase().getPackage(pk_name).getRule(rule_name) to access the actual org.drools.rule.Rule object (instead of the org.drools.definition.rule.Rule interface) Is there any shorter API somewhere in the library I can use to do the same? Thank you! -- View this message in context: http://drools.46999.n3.nabble.com/Simpler-API-to-access-the-Rule-object-in-RHS-tp4024921.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] Simpler API to access the Rule object in RHS?
Mark Proctor wrote If you look at the implementation for the interface, you'll see it can be cast. org.drools.rule.Rule is considered internal, so you can cast - but beware, it may change later. Mark Thanks for the tip Mark. Instead of ((org.drools.impl.KnowledgeBaseImpl)drools.getKnowledgeRuntime().getKnowledgeBase()).getRuleBase().getPackage(pk_name).getRule(rule_name) I can do ((org.drools.rule.Rule)drools.getKnowledgeRuntime().getKnowledgeBase().getRule(pk_name, rule_name)) Happy! -- View this message in context: http://drools.46999.n3.nabble.com/Simpler-API-to-access-the-Rule-object-in-RHS-tp4024921p4024951.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] What is -?
Mark Proctor wrote That should have been removed, it was an old drools 3 feature. @mario: can you make sure that's removed from the eclipse content assist. Mark Thanks Mark, may I know what it does and why it is being removed? -- View this message in context: http://drools.46999.n3.nabble.com/What-is-tp4024549p4024586.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] Is it possible to update KnowledgeBase inside a rule?
Say I want to change the loaded packages dynamically base on some Business logic, is it possible to update the KnowledgeBase in rule files (not in Java) like calling addKnowledgePackages() removeKnowledgePackage() etc.? If it is possible, how do you make it so that the current session is updated with the changes and re-fire for the new rules? Or, how do you make it so that the current session is not affected but the next session will be using the updated KnowledgeBase? Thank you P.S. I am using 5.5.0.Final -- View this message in context: http://drools.46999.n3.nabble.com/Is-it-possible-to-update-KnowledgeBase-inside-a-rule-tp4024578.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] What is -?
Thanks heap Mark, thats really informative! I wonder if anyone in your team could have a look on my other question http://drools.46999.n3.nabble.com/Is-it-possible-to-update-KnowledgeBase-inside-a-rule-td4024578.html Cheers! -- View this message in context: http://drools.46999.n3.nabble.com/What-is-tp4024549p4024597.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] What is -?
I dont have an example. I just see it when I get the content assist in Eclipse http://drools.46999.n3.nabble.com/file/n4024577/Untitled.jpg -- View this message in context: http://drools.46999.n3.nabble.com/What-is-tp4024549p4024577.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] What is -?
Hi, I may have missed it in the 5.5.0.Final Drools Expert User Guide, please point it out if its actually in the document. What is the use of - on the LHS? Thank you -- View this message in context: http://drools.46999.n3.nabble.com/What-is-tp4024549.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] Just found a way to stop fact insert time evaluation (tested in 5.5)
Originally I was asking for a method to stop LHS evaluation for a bunch of rules in some other agenda-groups which I am not intended to trigger. But it turned out that agenda-group filtering will only happen when you fire your rules. *ALL* rules in *ANY* agenda-groups are evaluated anyway when you are inserting fact. Then according to this post http://drools.46999.n3.nabble.com/Agenda-group-in-fact-insert-time-tp4023749p4023783.html, Wolfgang suggested to use an extra object to control the LHS evaluation by changing the value, e.g. Focus( value == one ). After many tests in 5.5.0.Final, this has no effect. Say if you have a rule: public static class MyClass { private Integer i; public MyClass(Integer i) { this.i = i; } public Integer getMyInteger() { System.out.println(getMyInteger is called for + i); return i; } } rule test agenda-group one when String ( toString == agenda-group one) MyClass ( myInteger == 10 ) then end when you call ksession.insert(new MyClass(10)); in your java code, no matter what the value of Focus() is, or even you dont have Focus() object inserted, getMyInteger() of MyClass is still called/evaluated to match with == 10. This is highly undesired when you actually only want to trigger rules in agenda-group two. And then finally I found that if you use the keyword from, it seems it is way smarter because *it will not be evaluated unless all the preceding conditions are matched!* Try the following example: rule try agenda-group one when not Object() from System.out.println(1) MyClass ( myInteger == 10 ) not Object() from System.out.println(2) MyClass ( myInteger == 9 ) not Object() from System.out.println(3) then end If you call ksession.insert(new MyClass(10)), you will only see the output 1, 2 but not 3 because MyClass ( myInteger == 9 ) does not match. This is really smart! Now we just need a dummy function to return us the object we want then we can use the agenda-group blocker to stop fact insert time evaluation as follow: function Object dummy(Object o) { return o; } rule smart agenda-group one when String ( toString == agenda-group one) m : MyClass() MyClass ( myInteger == 10 ) from dummy(m) then end rule blocker agenda-group one when then insert(new String(agenda-group one)); end There! No more unwanted evaluations during fact insert time! In fact, all the evaluations are pushed back to rule firing time and that can be *truly* filtered by agenda-group. Please let me know if I am doing stupid thing or if there is a big price or consequence to pay for when I use this technique? Thank you -- View this message in context: http://drools.46999.n3.nabble.com/Just-found-a-way-to-stop-fact-insert-time-evaluation-tested-in-5-5-tp4023967.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] Agenda-group in fact insert time
Ah, ok, thank you Wolfgang and Mark. So I will stick to the Focus blocker or contexts semaphores to short circuit my rules in different groups for the time being and wait for Mark's new lazy algorithm. Good work Droolers! -- View this message in context: http://drools.46999.n3.nabble.com/Agenda-group-in-fact-insert-time-tp4023749p4023788.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] Room to optimize or bug? Unnecessary calls to unused method
Hi, I am using 5.5.0.final on jdk7(64bit). To repeat the test, simply create a new Drools project in Eclipse. Tick the option to create a default Hello World project. Go to the DroolsTest.java file, edit main() to and edit getMessage() to Next, remove the two rules in Sample.drl, use this simple rule instead Then you can see the output Which means, getMessage() is called 4 times in this simple rule. I really wonder why. Is this a bug? Some non-optimized routine? An edge case? Now try this and the output is Just once. It seems all good. Because getMessage() is needed to call once to check with null, which is very fair to me. Now something really funny and the output An extra call to getMessage() at the end, total 5 times! TBH, I really only expect calling getMessage() once in all these tests. Please put it to my face and tell me my test is so flawed. -- View this message in context: http://drools.46999.n3.nabble.com/Room-to-optimize-or-bug-Unnecessary-calls-to-unused-method-tp4023790.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] Agenda-group in fact insert time
Thank you Wolfgang for your detailed reply. If you put the rules of a group into one (or more) drl files, you can compile them into separate .pkg files, which can then be used, individually or combined, into a KB. So maintaining rules in separate compiled resources is more preferable than using a single kbase to spawn separate sessions. Yet another idea might be to use an explicit Focus fact with an attribute that controls whether a rule should be evaluated or not. Using extends makes this just as terse as using the attribute, and changing the Focus is done by a simple modify. rule StatusOne when Focus( value == one ) then end rule xyz in group one extends StatusOne when ... the conditions for xyz in group one... then ... end Given that this can be easily extended to have rules that are in more than one group, this is even superior to agenda group. I really want to try this idea. Looks promising. When can we have this extends feature? -- View this message in context: http://drools.46999.n3.nabble.com/Agenda-group-in-fact-insert-time-tp4023749p4023777.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] Agenda-group in fact insert time
After a few testing, it seems that this rule extends rule feature is not exactly what I want. Say rule B extends A rule A will be evaluated. This is OK. when it comes to rule B, first, conditions in rule A will be evaluated again, then the conditions in rule B will be evaluated. That is not what I expected in this feature. May be it is only half baked? I would love to see this feature to be enchanted. Like if rule B extends A, rule C extends A then once rule A is evaluated, the result (to be executed or not) should be used when evaluating rule B and rule C. If rule A does not match the conditions, none of rule B nor rule C should be evaluated again. If rule A matches the conditions, when it comes to rule B or rule C, those conditions in rule A should not be evaluated again. Otherwise it is just like I repeated the conditions of rule A in rule B and rule C again. The only saving from this feature is in the code by typing less. -- View this message in context: http://drools.46999.n3.nabble.com/Agenda-group-in-fact-insert-time-tp4023749p4023779.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] Use of the binding variable
Sorry to ask here, but then what about :=? -- View this message in context: http://drools.46999.n3.nabble.com/Use-of-the-binding-variable-tp4023744p4023746.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] Agenda-group in fact insert time
Hi, I just noticed that even I have different agenda-groups, all groups are evaluated during fact inset time. In an extreme case, if I have 1000 rules in agenda-group A, and 1 rule in agenda-group B even though I just want to fire the 1 rule in agenda-group B by adding AgendaFilter in fireAllRules() all those 1000 rules in agenda-group A will be evaluated (i.e. methods in the when part are being called) even worst if I have complex logic in the when part for these 1000 rules, e.g. accumulate/from, not to mention eval Isn't that quite a performance impact? And forcing people to put their logic/checking/matching in the then part? How would you justify this? Or is there something I've missed that you can actually evaluate the rule in agenda-group B ONLY, when fact is being inserted? Thank you -- View this message in context: http://drools.46999.n3.nabble.com/Agenda-group-in-fact-insert-time-tp4023749.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] Use of the binding variable
Hi, it would be the same question: How would you use :=? Any use case? Situation? Good example? I know I can use := in functions as a return parameter to be used in the then part. But thats the only use case I can think of. Thank you -- View this message in context: http://drools.46999.n3.nabble.com/Use-of-the-binding-variable-tp4023744p4023751.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] Agenda-group in fact insert time
Thats ok, because if you dont call your function, you dont know if that rule should be fired or not. But I am concerning about agenda-group, where I know exactly one or more groups or rules will not be fired but they are still being evaluated. I ended up moving all the matching/checking to the then part for all my rules to speed things up. Now my when part is super clear -- View this message in context: http://drools.46999.n3.nabble.com/Agenda-group-in-fact-insert-time-tp4023749p4023754.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] Use of the binding variable
Sorry, I am not using Guvnor, didnt know you dont have := By the way, do your partner need to pay for a license fee to use Guvnor? My company is not using Guvnor because they say there is a license fee to use Guvnor -- View this message in context: http://drools.46999.n3.nabble.com/Use-of-the-binding-variable-tp4023744p4023755.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] Agenda-group in fact insert time
Thank you so much Wolfgang (is that your name? I saw that in some other posts. Cool )! Yes, now I know the benefit of this approach, now I am wondering why we are only left with one option? Could I propose a new and easy API that you can create a session from kbase with rules in a particular agenda-group(s)? Then start inserting fact to that session, so that rules in other agenda-groups will not be evaluated under this user's choice. Until then, do you think maintaining different kbases for each agenda-group (i.e. one agenda-group in one kbase) is a good idea? When rules in an agenda-group are needed to be fired, that kbase is used to create session(s). When rules across more than one agenda-groups are needed to be fired, those kbases can be added together to form a bigger kbase to create a session. This method is not perfect nor an ultimate solution. This is just a trade off for performance vs flexibility. By doing that, we for sure cannot write dynamic agenda-group focusing rules (those rules will not break down, just there will be no such group for that session) and which groups to fire must be planned beforehand. -- View this message in context: http://drools.46999.n3.nabble.com/Agenda-group-in-fact-insert-time-tp4023749p4023767.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] Use of the binding variable
Again, thank you so much Davide, you have helped me to solve another big problem again! The examples are very great, should have been added to the user manual. And yes, when I said I know := can be used in function to return parameter for the then part, I meant QUERY, not function. This would be the IN/OUT case. The only case that I know. Thank you for the crazy idea (in a good way) for the other three use cases! -- View this message in context: http://drools.46999.n3.nabble.com/Use-of-the-binding-variable-tp4023744p4023768.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] Use of the binding variable
And yes, thank you Michael for clarifying the licensing fee question. Not sure why my company said that. May be it is different when it comes to business -- View this message in context: http://drools.46999.n3.nabble.com/Use-of-the-binding-variable-tp4023744p4023769.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] Ways to list the globals
Thank you Davide, I too didn't aware that it was a StatelessKnowledgeSession. Because I was calling My global was set in sessionStateless, but I was firing sessionStateful instead and I could use my global there, just not listing it from getGlobals(). -- View this message in context: http://drools.46999.n3.nabble.com/Ways-to-list-the-globals-tp4023616p4023689.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] Ways to list the globals
Okay, took me a while to extract the code and just included the minimal. I know how to reproduce this bug (or something I have done wrong) now. Take a look at testing 2 and 3. Those are where I cannot list the global but the global is set in fact. Now we can continue trying to answer my question and stop guessing or pre-assuming you knew the reason already :P java source: Rule file: Output: -- View this message in context: http://drools.46999.n3.nabble.com/Ways-to-list-the-globals-tp4023616p4023660.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] Ways to list the globals
Hi, I am trying to list out the globals but I am confused, please help. I wrote this line in my drl file ((MapGlobalResolver)drools.getKnowledgeRuntime().getGlobals()).getGlobals() this gives me ONLY the globals that I have added in drl through drools.getWorkingMemory().setGlobal() this does not list out the globals that I have added in java before firing the rules. Then I tried this line in my drl file drools.getKnowledgeRuntime().getKnowledgeBase().getKnowledgePackages().getGlobalVariables() this gives me BOTH the globals that I have added in drl through drools.getWorkingMemory().setGlobal() AND the globals that I have added in java before firing the rules. My question is, to list the useable globals in the current rule, what is the correct method call? Thank you -- View this message in context: http://drools.46999.n3.nabble.com/Ways-to-list-the-globals-tp4023616.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] Ways to list the globals
Thank you so much for your quick reply! I am on 5.4. What I wanted to do is to list out the currently set globals (with values) that can be used in the current active rule. So it seems like I should not go for the getGlobalVariables() option. But then if I use ((MapGlobalResolver)drools.getKnowledgeRuntime().getGlobals()).getGlobals(), it does not list those I set in java using session.setGlobal(), where session is a StatefulKnowledgeSession before firing the rule. It ONLY list those I set in drl using drools.getWorkingMemory().setGlobal(). Thanks -- View this message in context: http://drools.46999.n3.nabble.com/Ways-to-list-the-globals-tp4023616p4023618.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