If your problem is performance, don't worry. Conditions evaluation is shared, so in the second rule you won't re-evaluate the entire working memory (to know more:http://www.drdobbs.com/184405218).

If you're worried about not having to repeat the conditions on the second rule, I would create inferred facts when the first rule matches and use then in the second rule + the additional conditions.

Something like:

Rule1:

when

            customer:Customer(town=="London")

then

            insert new LondonCustomer( customer );

 

Rule2:

when

            london : LondonCustomer(customer.job=="TEACHER")

then

            System.out.println(london.customer.getLname() + " is a teacher");



2010/10/12 Dominik Hüttner <d.huettner@tiq-solutions.de>

Hello everyone,

I’ve got a question. I’m using drools-guvnor to execute some rule-scenarios. I have to solve the following problem: I have an amount of objects in my working memory and can’t remove objects from the working memory in the then-part of the rule. I want to combine two rules, the first rule selects some objects and the second rule checks only these selected objects for additional criteria. I have to use two rules, because I want to report the objects selected in the first rule, too. Now I have implemented this with two rules and in the second rule, the criterias of the first rule are copied to the second rule, my question is, is there a way to get rid of this redundandance?

I have tried this with a rule flow, but the problem is, this always works on the whole working memory, but I can’t remove the not used objects from working memory for performance reasons. Is there another way to solve this problem?

 

Here is an example for what I intend to do:

 

Rule1:

when

            customer:Customer(town=="London")

then

            System.out.println(customer.getLname() + " is inhabitant of London");

 

Rule2:

when

            customer:Customer(town=="London",job=="TEACHER")

then

            System.out.println(customer.getLname() + " is a teacher");

 

This example illustrates, with the first rule I want to get to know, how many customers are from London and in the second rule I want to know, how many of the London customers are teachers. I want to create a kind of statistics. I have quite a lot of conditions for the first rule, so I don’t want to have them redundantly.

 

Greetings, Dominik


_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users