[rules-users] Update behavior
Can someone help explain the following behavior? Rule "rule1" Agenda-group "apples" No-loop When Apple(color matches "red") Response(name1 ==null); $response : Response() Then $response.setName1("gala"); drools.setFocus("oranges"); End Rule "rule2" Agenda-group "oranges" No-loop When Orange(color matches "orange") Response(name2==null) $response:Response(); Then $response.setName2("sunkist"); update($response) drools.setFocus("banannas"); There is 1 Apple in working memory with color matches red and 1 Orange with color matches orange. And there is 1 Response in working memory. What we don't understand is that upon the update from Rule2, the activation from rule1 refires even though $response.name1 has seemingly been set to "gala" and should no longer match. If the above is written as: Rule "rule1" Agenda-group "apples" No-loop When Apple(color matches "red") $response:Response(name1 ==null); Then $response.setName1("gala"); drools.setFocus("oranges"); End Rule "rule2" Agenda-group "oranges" No-loop When Orange(color matches "orange") $response: Response(name2==null) Then $response.setName2("sunkist"); update($response) drools.setFocus("banannas"); Then rule1 activation is not refired. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Re: rules-users Digest, Vol 28, Issue 19
Ricardo, This method has recently been added into WorkflowProcessInstance, it is on trunk and will be in CR1. For M5, you could indeed use WorkflowProcessInstanceImpl ... Kris - Original Message - From: Ricardo Gil Alcañiz To: Rules Users List Sent: Monday, March 09, 2009 4:37 PM Subject: [rules-users] Re: rules-users Digest, Vol 28, Issue 19 Thanks for your fast response Kris and Michal! I tried to use your solution Kris, but I've found that 5.0.0 M5 WorkflowProcessInstance does not seems to provide getVariable method. I've found that method into WorkflowProcessInstanceImpl searching in svn trunk. I must work with that class or I missed something? Thanks again! Ricardo. -- Mensaje reenviado -- From: Kris Verlaenen To: Rules Users List Date: Sun, 8 Mar 2009 03:56:29 +0100 Subject: Re: [rules-users] Drools Flow, constraint parametrization Ricardo, If you need to access process variables and have only simple constraint expressions, I suggest you use code constraints (Java or MVEL dialect), as they have direct access to variables (and globals). If you want to use rule constraints anyway (because your constraints can become rather complex), there are a few options: - You cannot use globals to pass information used in your constraints, because globals are considered immutable with respect to rule conditions - You can put your data you want to access in your working memory. Rule constraints can then access this info just like any normal rule. - You access the variable value using the special "processInstance" rule constraint (I just added a new section in the documentation to explain): Rule constraints do not have direct access to variables defined inside the process. It is however possible to refer to the current process instance inside a rule constraint, by adding the process instance to the working memory and matching to the process instance inside your rule constraint. We have added special logic to make sure that a variable "processInstance" of type WorkflowProcessInstance will only match to the current process instance and not to other process instances in the working memory. Note that you are however responsible yourself to insert (and possibly update) the process instance into the session (for example using Java code or an (on-entry or on-exit or explicit) action in your process). The following exampleof a rule constraint will search for a person with the same name as the value stored in the variable "name" of the process: processInstance: WorkflowProcessInstance() Person( name == ( processInstance.getVariable("name") ) ) # add more constraints here ... Kris Quoting Ricardo Gil Alcañiz : > Hi, > > I'm not a new drools user but I started to test rule flows (5.0M5) > recently > and I'm stucked, so any clue will be welcomed :). I'm testing how to > share a > StatefulKnowledgeSession between N rule flow instances. I'm trying > to > parametrize each instance with process variables at start time but I > don't > know how to use them from rule constraints (in event waits, splits, > etc.). > I've read the documentation and I've found this text related to > constraints > "Both rule and code constraints have access to globals that are > defined for > the process and can reuse imports at the process level." I tried it > assigning (from an action) a variable value to a global variable but > it's > not working for me. ¿I'm missing something? > > Thanks in advance! > > Ricardo. > -- ___ 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] Re: rules-users Digest, Vol 28, Issue 19
Thanks for your fast response Kris and Michal! I tried to use your solution Kris, but I've found that 5.0.0 M5 WorkflowProcessInstance does not seems to provide getVariable method. I've found that method into WorkflowProcessInstanceImpl searching in svn trunk. I must work with that class or I missed something? Thanks again! Ricardo. > -- Mensaje reenviado -- > From: Kris Verlaenen > To: Rules Users List > Date: Sun, 8 Mar 2009 03:56:29 +0100 > Subject: Re: [rules-users] Drools Flow, constraint parametrization > Ricardo, > > If you need to access process variables and have only simple constraint > expressions, I suggest you use code constraints (Java or MVEL dialect), > as they have direct access to variables (and globals). > > If you want to use rule constraints anyway (because your constraints can > become rather complex), there are a few options: > > - You cannot use globals to pass information used in your constraints, > because globals are considered immutable with respect to rule conditions > > - You can put your data you want to access in your working memory. > Rule constraints can then access this info just like any normal rule. > > - You access the variable value using the special "processInstance" > rule constraint (I just added a new section in the documentation to > explain): > > Rule constraints do not have direct access to variables defined inside > the process. It is however possible to refer to the current process > instance inside a rule constraint, by adding the process instance to the > working memory and matching to the process instance inside your rule > constraint. We have added special logic to make sure that a variable > "processInstance" of type WorkflowProcessInstance will only match to the > current process instance and not to other process instances in the > working memory. Note that you are however responsible yourself to insert > (and possibly update) the process instance into the session (for example > using Java code or an (on-entry or on-exit or explicit) action in your > process). The following exampleof a rule constraint will search for a > person with the same name as the value stored in the variable "name" of > the process: > > processInstance: WorkflowProcessInstance() > Person( name == ( processInstance.getVariable("name") ) ) > # add more constraints here ... > > Kris > > Quoting Ricardo Gil Alcañiz : > > > Hi, > > > > I'm not a new drools user but I started to test rule flows (5.0M5) > > recently > > and I'm stucked, so any clue will be welcomed :). I'm testing how to > > share a > > StatefulKnowledgeSession between N rule flow instances. I'm trying > > to > > parametrize each instance with process variables at start time but I > > don't > > know how to use them from rule constraints (in event waits, splits, > > etc.). > > I've read the documentation and I've found this text related to > > constraints > > "Both rule and code constraints have access to globals that are > > defined for > > the process and can reuse imports at the process level." I tried it > > assigning (from an action) a variable value to a global variable but > > it's > > not working for me. ¿I'm missing something? > > > > Thanks in advance! > > > > Ricardo. > > > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Events - Determining the Fact Pattern
David, This is an interesting use case, but I don't think you can build a complete explanation from the agenda listener. Let me clarify: you can do 80% of the explanation from there, based on the position of the fact handles in the tuple. The collection you get from event.getActivation().getFactHandles() will have the facts in the exact same "offset" order you have in your rule. For simple rules, it is "straight forward": when A() B() C() then end In the above example, A() will be offset 0, B() will be 1 and C() will be 2. The 20% you will not be able to explain with such solution are the cases where you have nested patterns, with the use of ORs (that create multiple logical branches), NOT/EXISTS/FORALL ( that don't generate a fact in the activating tuple), COLLECT/ACCUMULATE that will condense multiple conditions into one element, etc. My best advise for you is: if this is a non-critical part of your system, go ahead with the approach above, and you will be able to provide most of the explanations with a simple heuristic. But if this is critical for your use case, my suggestion would be for you to get your company to allow you to work with us for some time implementing this requirement as a proper drools feature. We can guide you through the drools internals and add the feature your company needs and your company donates the code for the project so that we can support it in the future. It is an open source project after all. Need to check with Mark what he thinks about the feature, but it sounds interesting for me. []s Edson 2009/3/9 David Boaz > > Thanks Mark, > > I tried to analyze (in the debugger) the RETE network, and to my > understanding, it is not possible to map back from the RETE nodes to the > rule pattern. in the example above the two Person patterns will share the > same EntryPointNode and ObjectTypeNode, hence, there is no way to determine > what was the original pattern. > > My use case, is to generate 'explanation' objects. These object will log > for > each successful rule firing the identifiers of the facts that produced this > consequence. Later on, we want to enable providing explanations as: "we > reached this conclusion because field (actual=2) < 4". So, in the > explanation process we want to substitute the rule patterns with actual > facts. > When the rule patterns are of the same object-type, there is a possibility > to confuse and to assign the wrong fact to the pattern. Hence, I wanted to > determine and log what was the 'causing' pattern for each fact. > > I hope that my description is clear, > BR, David > > > > Mark Proctor wrote: > > > > Mark Proctor wrote: > >> David Boaz wrote: > >>> Hi all, > >>> > >>> Is it possible to determine the Pattern that ‘produced’ a given Fact? > >>> For > >>> example, assuming we have the following rule and event handler: > >>> > >>> rule r1 > >>> when p1:Person(...) > >>> p2:Person(...) > >>> then > >>> ... > >>> end > >>> > >>> protected class MyAgendaEventHandler extends > >>> DefaultAgendaEventListener { > >>> > >>> @Override > >>> public void > >>> afterActivationFired(org.drools.event.rule.AfterActivationFiredEvent > >>> event) > >>> { > >>> String ruleName = event.getActivation().getRule().getName(); > >>> KnowledgeRuntime knowledgeRuntime = > event.getKnowledgeRuntime(); > >>> for (FactHandle factHandle : > >>> event.getActivation().getFactHandles()) { > >>> Object fact = knowledgeRuntime.getObject(factHandle); > >>> Pattern pattern= ?; > >>> } > >>> } > >>> } > >>> > >>> Is it possible to determine the Pattern that originate a Person > >>> object? If > >>> yes, how the pattern is identified? > >>> > >> no > > We'll that's not exactly true, but it's not something an end user should > > be doing. But the basic jist is the Activation wraps the AgendaItem if > > you can get access to that it has a Tuple field, this references the > > chaines of tuples that make up the row of data. you can iterate that > > chain and each one has a handle field which you can match up with the > > facthandle you are searching for. Further more each tuple references the > > join node it was added via, which also has an index number, so you can > > deduce the pattern from there. However I seriously doubt this is what > > you want, and you probably need to think harder about your use case. > > > > Mark > >>> Thanks, David > >>> > >> > >> > >> ___ > >> 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 > > > > > > -- > View this message in context: > http://www.nabble.com/Events---Determining-the-Fact-Pattern-tp2
Re: [rules-users] Events - Determining the Fact Pattern
Thanks Mark, I tried to analyze (in the debugger) the RETE network, and to my understanding, it is not possible to map back from the RETE nodes to the rule pattern. in the example above the two Person patterns will share the same EntryPointNode and ObjectTypeNode, hence, there is no way to determine what was the original pattern. My use case, is to generate 'explanation' objects. These object will log for each successful rule firing the identifiers of the facts that produced this consequence. Later on, we want to enable providing explanations as: "we reached this conclusion because field (actual=2) < 4". So, in the explanation process we want to substitute the rule patterns with actual facts. When the rule patterns are of the same object-type, there is a possibility to confuse and to assign the wrong fact to the pattern. Hence, I wanted to determine and log what was the 'causing' pattern for each fact. I hope that my description is clear, BR, David Mark Proctor wrote: > > Mark Proctor wrote: >> David Boaz wrote: >>> Hi all, >>> >>> Is it possible to determine the Pattern that ‘produced’ a given Fact? >>> For >>> example, assuming we have the following rule and event handler: >>> >>> rule r1 >>> when p1:Person(...) >>> p2:Person(...) >>> then >>> ... >>> end >>> >>> protected class MyAgendaEventHandler extends >>> DefaultAgendaEventListener { >>> >>> @Override >>> public void >>> afterActivationFired(org.drools.event.rule.AfterActivationFiredEvent >>> event) >>> { >>> String ruleName = event.getActivation().getRule().getName(); >>> KnowledgeRuntime knowledgeRuntime = event.getKnowledgeRuntime(); >>> for (FactHandle factHandle : >>> event.getActivation().getFactHandles()) { >>> Object fact = knowledgeRuntime.getObject(factHandle); >>> Pattern pattern= ?; >>> } >>> } >>> } >>> >>> Is it possible to determine the Pattern that originate a Person >>> object? If >>> yes, how the pattern is identified? >>> >> no > We'll that's not exactly true, but it's not something an end user should > be doing. But the basic jist is the Activation wraps the AgendaItem if > you can get access to that it has a Tuple field, this references the > chaines of tuples that make up the row of data. you can iterate that > chain and each one has a handle field which you can match up with the > facthandle you are searching for. Further more each tuple references the > join node it was added via, which also has an index number, so you can > deduce the pattern from there. However I seriously doubt this is what > you want, and you probably need to think harder about your use case. > > Mark >>> Thanks, David >>> >> >> >> ___ >> 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 > > -- View this message in context: http://www.nabble.com/Events---Determining-the-Fact-Pattern-tp22397570p22413433.html Sent from the drools - user 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] NPE when using directory scanner and drl is incorrect. Possible bug! (Drools 4.0.7)
Hi, I think I found a bug. When I use rule agent with directory scanner, and the rule that is being scanned contains a bug, then I receive a NPE instead of error message: java.lang.NullPointerException at org.drools.agent.FileScanner.readPackage(FileScanner.java:102) at org.drools.agent.FileScanner.getChangeSet(FileScanner.java:79) at org.drools.agent.FileScanner.loadPackageChanges(FileScanner.java:57) at org.drools.agent.DirectoryScanner.loadPackageChanges(DirectoryScanner.java:43) at org.drools.agent.RuleAgent.checkForChanges(RuleAgent.java:330) at org.drools.agent.RuleAgent.refreshRuleBase(RuleAgent.java:298) at org.drools.agent.RuleAgent.configure(RuleAgent.java:284) at org.drools.agent.RuleAgent.init(RuleAgent.java:208) at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:176) at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:164) ... (further entries of stack trace contains my application's lines) When I looked into code I found that DirectoryScanner object, used by the agent uses FileScanner object to scan each file in a directory. And the file scanner does not have a listener set. That's why the NPE is thrown. It's difficult to find a bug in the rule. I didn't find it in JIRA. If anyone knows, that it was reported, then I won't duplicate, otherwise, I think it is worth to create a report. Best regards, -- Przemysław Różycki AMG.net, A Bull Group Company ul. Łąkowa 29 90-554 Łódź www.amg.net.pl ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Re: NPE when using directory scanner and drl is incorrect. Possible bug! (Drools 4.0.7)
Small correction. I've just found this: https://jira.jboss.org/jira/browse/JBRULES-1436 but it is has to be fixed in 4.0.5 and I'm still experiencing it in 4.0.7. Best regards, Przemysław Różycki Przemysław Różycki pisze: Hi, I think I found a bug. When I use rule agent with directory scanner, and the rule that is being scanned contains a bug, then I receive a NPE instead of error message: java.lang.NullPointerException at org.drools.agent.FileScanner.readPackage(FileScanner.java:102) at org.drools.agent.FileScanner.getChangeSet(FileScanner.java:79) at org.drools.agent.FileScanner.loadPackageChanges(FileScanner.java:57) at org.drools.agent.DirectoryScanner.loadPackageChanges(DirectoryScanner.java:43) at org.drools.agent.RuleAgent.checkForChanges(RuleAgent.java:330) at org.drools.agent.RuleAgent.refreshRuleBase(RuleAgent.java:298) at org.drools.agent.RuleAgent.configure(RuleAgent.java:284) at org.drools.agent.RuleAgent.init(RuleAgent.java:208) at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:176) at org.drools.agent.RuleAgent.newRuleAgent(RuleAgent.java:164) ... (further entries of stack trace contains my application's lines) When I looked into code I found that DirectoryScanner object, used by the agent uses FileScanner object to scan each file in a directory. And the file scanner does not have a listener set. That's why the NPE is thrown. It's difficult to find a bug in the rule. I didn't find it in JIRA. If anyone knows, that it was reported, then I won't duplicate, otherwise, I think it is worth to create a report. Best regards, ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] How to get rid of the imports
Hello, I am currently developing a project with intensive usage of Drools. Users should write their rules in DSL, but I want to not burden them with writing the right "import com.sample.my.own.Class;", because they shouldn't know anything about my classes. They should know only the DSL I provide them (they should be psychology teachers and so on, not the IT folk). One solution is to fully qualify every usage of the class in DSL, but this isn't a nice solution, because it will bloat the mapping. I could provide the the imports and globals file separately, merge them with some rules file and then load it into drools, but this would probably break the ability to debug the rules in Eclipse (well, I am even not sure how it is possible, but it works). Has anyone provided some solution coded in drools? I can't find it. Thanks for any reply. -- View this message in context: http://www.nabble.com/How-to-get-rid-of-the-imports-tp22404890p22404890.html Sent from the drools - user 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 to use drools4 brms package view to delete a rule,
hi I want to add a function that I can delete a rule from brms package viewer,how can I do that? another question when will drools5 ga become available? ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Creating fact instance programatically
Yes, If I put a non existent package and type, the method getFactType returns me null value, but if I put the correct package and type it throws that error. Thanks, NEStor 2009/3/8 Michal Bali > your factTypeName should consist of package name + type name, for example: > com.mycompany.Account > > > On Sun, Mar 8, 2009 at 7:02 PM, nestabur wrote: > >> >> Hi all, >> >> I'm trying to create a fact programatically like this: >> >> FactType myfact =package.getFactType(factTypeName); >> Object myPojo = myfact.newInstance(); >> >> An error occurs when calling the method getFactType, here my stackTrace: >> 36267-1236185246849-0:0:1:1 Exception while processing message: >> java.lang.StringIndexOutOfBoundsException: String index out of range: -1 >> java.lang.StringIndexOutOfBoundsException: String index out of range: -1 >>at java.lang.String.substring(String.java:1938) >>at java.lang.String.substring(String.java:1905) >>at org.drools.rule.Package.getFactType(Package.java:552) >> >> My drools version is 5.0.0.M5 >> >> Any suggestion? >> >> -- >> View this message in context: >> http://www.nabble.com/Creating-fact-instance-programatically-tp22334399p22334399.html >> Sent from the drools - user 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 mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users