[rules-users] some pointers for solution

Wishing Carebear wishing.carebear at gmail.com
Wed Nov 11 16:38:08 EST 2009


Hi Greg:
Is it possible to use decision table to populate the Data object that
contains the criteria list information.

Thanks,
Ravi

2009/11/8 Greg Barton <greg_barton at yahoo.com>

> There are a couple of ways to do this.  I'm sure there's a bit more clean
> way than the example I'm providing, but this should get you in the right
> direction.  It's not 100% rules, because it involves a bit of java
> collections trickery. (See attached project,
> collection_DroolsCriteriaMatch.tar.gz)
>
> The heart of it is a single rule:
>
> rule "Match"
>  when
>    d : Data()
>    q : Query( size <= d.size )
>    Number( intValue == q.size )
>    from accumulate(
>      Criteria( this memberOf d, this memberOf q ),
>      init( int total = 0; ),
>      action( total ++; ),
>      reverse( total --; ),
>      result( total )
>    )
>  then
>    System.out.println("Match: " + d + " and " + q) ;
> end
>
> The Data object holds data to be queried, Query objects are asserted to
> match the Data, and Criteria objects can be contained in either. (With the
> aforementioned collections trickery that if a Criteria is contained in a
> Query it can be found in a Data object, but the reverse isn't true.  See the
> Query.contains(Object) method for how that's implemented.)
>
> So the rule above basically says "There's a Data object, and all of the
> Query objects Criteria are contained in the Data object."
>
> There's an alternate way of doing this using eval and a bit more java fu.
>  See the eval_DroolsCriteriaMatch.tar.gz project attached.  This one's
> probably not optimal, though, as it's basically a brute force check of all
> Data objects against the asserted Query.
>
> I tried for a while to get a solution working with different criteria types
> from both Data and Query objects being asserted into working memory, but I
> couldn't get the accumulate syntax right.  Anyone know of a way to do that?
> (I figure that would get a "pure rules" solution.)
>
> --- On Sat, 11/7/09, Wishing Carebear <wishing.carebear at gmail.com> wrote:
>
> > From: Wishing Carebear <wishing.carebear at gmail.com>
> > Subject: [rules-users] some pointers for solution
> > To: rules-users at lists.jboss.org
> > Date: Saturday, November 7, 2009, 10:19 PM
>  > Hello:
> > There are n selection criteria from s1 .. sn for each
> > item i1.. in. Each item can have a subset of criteria which
> > applies to them.
> >
> > The end user, can choose a subset of criteria like c1
> > and c5 and only the item that has c1 and c5 valid should be
> > returned. For example: if item i1 and i2 have criterias
> > valid for c1, c2, c5, c6, c8 since the request is only for
> > criteria c1 and c5, i1 and i2 must be returned.
> >
> >
> > Is it possible to write a rule using drools for this
> > requirement.
> >
> > Thanks for your help and time,
> > cabear
> >
> > -----Inline Attachment Follows-----
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20091111/1660bc6b/attachment.html 


More information about the rules-users mailing list