Deepak Pol wrote:
Now following are some questions I have: 1. Since the rules defined are being applied to any data, I want the rules to be created once and shared by different sessions for different data. For eg there can be a rule which says if total > 100 then return list of users u1, u2 and u3. Now for different organizations total can be different and each organization can run rules engine with its own data but the rules themselves are same so I want to share them across different organizations. Each organization will have its own session and data and the same rules in the memory are executed with this data. What I found in Jess docs was, you need to initialize the rule engine by using new Rete(); and add the rule language file (*.clp) and the data to the working memory. But like in above example, if I want to add the data for some other organization but for the same rules then I need to create another instance of Rete and provide the rule language file to it in which case I end up having one file in working memory for each organization. Is there any way to avoid this and share the file for different data or for different sessions?
You could write the rules so that they use the data that depends on the organization via defglobal variables or as slots of some Parameter fact(s). This means that you have one file, say, rules.clp that can be used in each session/Rete. The setup of the defglobals or the Parameter fact(s) would require one additional .clp file for each organization.
2. As per my understanding, the only way to control the flow of rules execution is by creating different modules. If I have a condition like if Module_1 fires (i.e at least one rule from module is fired) the focus module_2 else focus module_3. This conditions can get even more complex. And also note that all rules from module_1 should get fired so I can't have focus statement in action part of any rule of module_1 since it will immediately focus to new module and other rules from module_1 would be skipped. Currenly I am planning to do it by having a global variable for each such condition. For eg if any rule from module_1 is fired then make this variable true and use it for further control. But as the conditions become more and more complex and provided that I want to create the language through some apis against using an existing one; I am not sure how much feasible this would be. Any suggestions on this?
The paradigm of "controlling the execution flow" is somewhat contradictionary to the principle of rule firing. I'd suggest that you reconsider the requirement you have formulated here. Do the rules of module_2 really depend on some modification made by module_1? In this case, consider the solution I propose for your 3rd question, and generalize it so that the "todo" value enables or disables various rule sets (which would not even be in different modules). Or is it just so that the outputs from rule firing should appear in some order? Then, just collect them in some "Bag" fact or slot and output them at the end.
3. I want to have some modules (which would be set of rules) which are exclusive i.e. only one of them should fire even if others also match. I can do this with auto-focus for the first rule in each module but how to avoid others from firing. I tried halt but didn't work. Retracting the facts as soon as they fire is not a feasible option since the same fact might be used in some other rule in the same module which I still want to fire.
The standard solution to this scenario is to add a "todo" slot to your fact(s), initialize it with TRUE (deftemplate Foo (slot a)... (slot todo (type SYMBOL)(default TRUE))) and modify it to FALSE as soon as it is processed by some rule: (defrule Bar ?f <- (Foo (a ?a)...(todo TRUE)) => ... (modify ?f (todo FALSE)) ) HTH Wolfgang
Any help in above ragards would be really appreciable. Thanks in advance, - Deepak
-------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------
