Let me propose a somewhat different approach which avoids changing your objects.
Define a new class Marker that combines a "mark" with the Object to be classified:
   private String mark;
   private final Object object;
   public Marker( Object o ){ this.object = o; mark = ""; }
   // getter for object
   // getter & setter for mark
For every new Object, create and insert a marker object. This could be done by the (Java) code inserting the new objet, or by a rule that fires on an unmarked and unclassified Object. (This depends somewhat upon the ultimate fate of the Object facts. If they are left in WM, it might be preferable to used the first technique.)
Rules would be written as
   rule r1.2.4
       $m : Marker( mark == "1.2", $object : object )
       Object( this == $object,... )
       $m.setMark( "1.2.4" );
       update( $m );
Leaf rules would have to retract the marker (and dispose of the Object fact).
A low salience rule should be provided to match left-over Marker objects so you can catch Objects that aren't matched by any rule.

On 4/13/09, Charles Binford <Charles.Binford@sun.com> wrote:
All,  I'm trying to figure out a better way to solve this problem.  I
have a batch of objects that I want matched against a hierarchy of
rules.  I check the rules in order, and as soon as I find a match I'm
done for that level of the hierarchy.  In other words, If the object
matches a rule, we'll check the rules children, but not the siblings.

rule 1
rule 1.1
rule 1.2
   rule 1.2.1
   rule 1.2.2
rule 1.3
rule 2

If an object matches rule 1, check for a match at level "1.*", but rule
2 will never be checked.  If an object matches 1, 1.2, and 1.2.1, we're
done as 1.2.1 has no children.

My current implementation with drools works, but is very inefficient.  I
have a "level" string in the objects and whenever I find a match I
update the level of the object and force an object update.  Each rule
tests that the level string is correct, e.g. rule 1.2.1 works as follows:
rule "1.2.1"
   obj(level matches "1.2.*",.....)

I'm also using saliance to keep the evaluation order like I want it.

Changing the contents of the object and doing the update is not good for
drools performance as I understand it so I'm looking for a better way.
The hierarchy and the order of the matching is key to my application so
I'm not wanting to redesign that part of things.

I tried using activation-groups.  That worked great as long as I only
had a single object to run through the hierarchy, but given the way the
rest of the system is design I need to load up 10-100 objects before
each call to fireallrules() for performance purposes.

Any suggestions are appreciated.

Charles Binford

rules-users mailing list