Hi Ernest,
Thank you for your reply; really appreciated. Please find my comments inline
and provide your suggestions.
On Wed, Jun 25, 2008 at 9:32 AM, Ernest Friedman-Hill <[EMAIL PROTECTED]>
wrote:
> On Jun 24, 2008, at 2:51 PM, 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?
>>
>
>
> Yes, in several different ways. First of all, you don't need to hard code
> values like "100" in the rules; you can supply these as data. For example, a
> rule might say
>
> if total > threshold then return list of users
>
> and then each client could supply their own value of "threshold". That way
> the rules are the same for everybody.
>
> Secondly, you can have multiple values of "threshold" in the same engine at
> the same time. You could have
>
> if processing client #1 and total for client #1 > threshold for client #1
> then...
>
> Finally, multiple instances of the rule engine can share a single loaded
> set of rules; this is called "peering" and it's new in Jess 7.1, which is
> about to go final.
Please make me clear on this because in this what I meant was 'total' will
be the supplied input to engine and that will vary in my application for
each client. Though as a rule I always want each client's total to be
compared to 100 to decide the rule execution. Thats why I kept 100 as hard
coded value while total as the value dynamically coming from the client.
Though 'peering' concept should solve my problems. I reckon a global
variable created with a peer has a scope 'peer', right?. Can you specify the
tentative date when 7.1 will be out? Because I am about to begin on a
project where I want to replace my application framework with JESS. And the
peering is the concept I need the most.
>
>
>
> 2. As per my understanding, the only way to control the flow of rules
>> execution is by creating different modules.
>>
>
> No, that's just one way.
>
> 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?
>>
>
>
> There's a concept of a "focus stack". The focus stack keeps track of the
> order in which modules will be activated. You can add and remove modules
> from the stack at any time. So you an easily express "when all the rules in
> this module have fired, proceed to module 2".
How to express "when all the rules in this module have fired, proceed to
module 2"? Following is what I am planning to do:
Condition: module_1 should always fire, if any(Note this 'any') rule in
module 2 fires module_3 should fire else module_4 should fire.
Approach:
def module_1
def rule_11
auto-focus
condition
=>
add users to global user list
def rule_12 condition
=>
add users to global user list
def module_2
def rule_21
auto-focus
condition
=>
focus module_3 (If I do this then it will skip rule_22 which I dont
want)
add users to global user list
def rule_22 condition
=>
add users to global user list
Also even if I make sure that if any rule in module_2 fires then fire
module_3, how can I make sure if module_2 doesn't fire then focus module_4
So currenlty I am thinking about an approach of having a global variable
?*module_2_fired* and a condition
if ?*module_2_fired* then focus module_3 else focus module_4
def module_3
def rule_31
condition
=>
add users to global user list
def rule_32 condition
=>
add users to global user list
def module_4
def rule_41
auto-focus
condition
=>
add users to global user list
def rule_42 condition
=>
add users to global user list
Can you rectify the focus logic in this context? Or any other suggestion
than using global variable?
>
>
>
> 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.
>>
>>
> There are other ways to do this besides retracting facts; for instance, you
> can do it by asserting a fact signaling that one of the rules has fired,
> then make all the rules in the set match the absence of that fact.
In the following example:
Only one of module_a and module_b should fire
def module_a
def rule_a1
auto-focus
total > 100 and region = north
=>
add users to global user list
def rule_32 name = "name" and region = north
=>
add users to global user list
def module_4
def rule_41
condition
=>
add users to global user list
def rule_42 condition
=>
add users to global user list
Since the conditions in my case are provided by user and not created by me,
I cannot change them. So even if I asert fact region after once fired, I
can't change rule_a2 to look for absence of fact region it has to be fired
with the same condion. Is there any way to do this? Will return in last rule
work?
>
>
>
>
>> Any help in above ragards would be really appreciable.
>> Thanks in advance,
>> - Deepak
>>
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Informatics & Decision Sciences, Sandia National Laboratories
> PO Box 969, MS 9012, Livermore, CA 94550
> http://www.jessrules.com
>
>
>
>
>
>
> --------------------------------------------------------------------
> 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]
> --------------------------------------------------------------------
>
>