[rules-users] How to traverse a hierarchy?

Charles Binford Charles.Binford at Sun.COM
Tue Apr 14 16:50:04 EDT 2009


Yes, this front end part of the rules are basically a decision tree. 

I looked at the ruleflow stuff in the doc but was a bit scared of the
complexity that I thought I'd end up having.  This part of my rules are
build dynamically by my application based on input from the user (system
admin).  The admin runs a little utility that creates a set of
classification criteria and a set of associated actions for each
classification.   The classifications support the hierarchy I described
in my earlier post. My app parses the user's input (an xml file),
pulling out the classifications, their hierarchical relationship, and
their associated actions.  That info combined with some canned strings
creates a DSLR file which is then translated into normal drl syntax. 
All of the actions merely insert the appropriate objects into working
memory with the user specified parameters.  The real meat of my rules (a
separate drl file that is static) then operates on the newly inserted
objects.  I wasn't sure how to apply ruleflow to rules I built
dynamically.  The end user sets the number of rules and the size and
shape of the hierarchy (within some upper limits).

Charles Binford

Edson Tirelli wrote:
>
>    In Drools 4 I would use ruleflow to design a flow of groups of rules.
>
>    It sounds like you are implementing a decision tree?!
>
>    []s
>    Edson
>
>
>
> 2009/4/14 Charles Binford <Charles.Binford at sun.com
> <mailto:Charles.Binford at sun.com>>
>
>     Edson,  Thanks for your reply.  Unfortunately I failed to say I need
>     drools 4.0.7 because of its GA status.
>     Any suggestions for an approach with drools 4?
>
>     Charles Binford
>
>     Edson Tirelli wrote:
>     >
>     >    If I understood correctly, all you need to do (in Drools 5) is to
>     > use rule inheritance. Also, in case your "non-leaf" rules have
>     nothing
>     > to do in their consequences, you can mark them with attribute
>     "enabled
>     > false".
>     >
>     >
>     https://svn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/extend_rule_test.drl
>     >
>     >    So, have rule 1.2 extend rule 1. Have rule 1.2.1 extend rule 1.2
>     > and so on. Mark the ones that don't have consequence actions with
>     > enabled false just to avoiding creating useless activations. You
>     still
>     > need to prioritize rules with salience or whatever you are using
>     for that.
>     >
>     >    That should do the trick. Report back your findings please,
>     as this
>     > is a new feature in Drools 5.
>     >
>     >    Hope it helps,
>     >       Edson
>     >
>     > 2009/4/13 Charles Binford <Charles.Binford at sun.com
>     <mailto:Charles.Binford at sun.com>
>     > <mailto:Charles.Binford at sun.com <mailto:Charles.Binford at sun.com>>>
>     >
>     >     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.
>     >     Example:
>     >
>     >     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"
>     >     when
>     >        obj(level matches "1.2.*",.....)
>     >        ...
>     >     then
>     >        objSetLevel("1.2.1.*");
>     >        ....
>     >     end
>     >
>     >     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
>     >     rules-users at lists.jboss.org
>     <mailto:rules-users at lists.jboss.org>
>     <mailto:rules-users at lists.jboss.org
>     <mailto:rules-users at lists.jboss.org>>
>     >     https://lists.jboss.org/mailman/listinfo/rules-users
>     >
>     >
>     >
>     >
>     > --
>     >  Edson Tirelli
>     >  JBoss Drools Core Development
>     >  JBoss, a division of Red Hat @ www.jboss.com
>     <http://www.jboss.com> <http://www.jboss.com>
>     >
>     ------------------------------------------------------------------------
>     >
>     > _______________________________________________
>     > rules-users mailing list
>     > rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
>     > https://lists.jboss.org/mailman/listinfo/rules-users
>     >
>     _______________________________________________
>     rules-users mailing list
>     rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
>     https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
> -- 
>  Edson Tirelli
>  JBoss Drools Core Development
>  JBoss, a division of Red Hat @ www.jboss.com <http://www.jboss.com>
> ------------------------------------------------------------------------
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>   



More information about the rules-users mailing list