<div>Thanks Greg. I really appreciate your help.</div>
<div> </div>
<div>Will try it and update you.</div>
<div> </div>
<div>Regards,</div>
<div>cabear<br><br></div>
<div class="gmail_quote">2009/11/8 Greg Barton <span dir="ltr"><<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>></span><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Yep. See attached project. It actually simplifies the java a bit, as now there doesn't need to be any trickery in the contains method for Query. The rule now uses a from clause to get the Criteria directly from the Query:<br>
<div class="im"><br>rule "Match"<br> when<br> d : Data()<br> q : Query( size <= d.size )<br></div> $total : Number( intValue == q.size )<br> from accumulate( Criteria( this memberOf d ) from q, count(1) )<br>
<div class="im"> then<br> System.out.println("Match: " + d + " and " + q) ;<br>end<br><br></div>Try the other methods, though. (The eval 'hack' I included before, and Wolfgang's method.) All of these approaches should have different performance behavior, and I honestly don't know which one is fastest.<br>
<div class="im"><br>--- On Sun, 11/8/09, Wishing Carebear <<a href="mailto:wishing.carebear@gmail.com">wishing.carebear@gmail.com</a>> wrote:<br><br>> From: Wishing Carebear <<a href="mailto:wishing.carebear@gmail.com">wishing.carebear@gmail.com</a>><br>
> Subject: Re: [rules-users] some pointers for solution<br>> To: "Rules Users List" <<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>><br></div>> Date: Sunday, November 8, 2009, 8:02 PM<br>
<div class="im">> Yes Edson, I tried with count and sum.<br>> Both seems to be working fine.<br>> <br>> But with the test case, the Criteria for query also<br>> needs to be inserted in addition to the query and data<br>
> objects like shown below:<br>> <br>> Query query = new Query(1);<br>> query.add(new<br>> Criteria(query, "c2", "bas"));<br>> ksession.insert(query);<br>> for(Criteria c :<br>> query) {<br>
> ksession.insert(c);<br>> }<br>> <br>> <br>> Is it possible to avoid them.<br>> <br></div>> Thanks,<br>> cabear<br>><br>><br>><br>
<div>
<div></div>
<div class="h5">> 2009/11/8 Edson Tirelli <<a href="mailto:ed.tirelli@gmail.com">ed.tirelli@gmail.com</a>><br>><br>><br>> Why not use count() accumulate function? ;)<br>><br>><br>> from accumulate( Criteria( this memberOf d, this memberOf q<br>
> ),<br>> <br>> count(1) )<br>><br>> Edson<br>><br>><br>><br>><br>><br>> 2009/11/8 Greg Barton <<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>><br>
><br>> In this case<br>> the accumulate clause is maintaining a counter (total)<br>> that's incremented whenever a Criteria is detected that<br>> is contained in both the Data and Query object matched in<br>
> the rule. So:<br>><br>><br>> # Find Criteria that are contained in both the Data and<br>> Query<br>><br>> from accumulate( Criteria( this memberOf d, this<br>> memberOf q ),<br>> # Initialize the counter to 0<br>
> init( int total = 0; ),<br>> # Increment when the above condition is matched<br>> action( total ++; ),<br>> # Decrement if a matched Criteria now fails to match<br>><br>> reverse( total --; ),<br>> # return the total when all known Criteria are matched<br>
> result( total ) )<br>><br>><br>> --- On Sun, 11/8/09, Wishing Carebear <<a href="mailto:wishing.carebear@gmail.com">wishing.carebear@gmail.com</a>><br>> wrote:<br>><br>> > From: Wishing Carebear <<a href="mailto:wishing.carebear@gmail.com">wishing.carebear@gmail.com</a>><br>
><br>> > Subject: Re: [rules-users] some pointers for<br>> solution<br>> > To: "Rules Users List" <<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>><br>> > Date: Sunday, November 8, 2009, 11:39 AM<br>
><br>><br>><br>><br>> > Hi Greg:<br>> > I'm trying to understand your first<br>> > solution.<br>> > <br>> > Ran the project and it works fine. If possible could<br>> > you explain me little bit on :<br>
> ><br>> > from accumulate( Criteria( this memberOf d,<br>><br>> > this memberOf q ),<br>> > init( int total = 0; ),<br>> > action( total ++; ),<br>> > reverse( total --; ),<br>> > result( total ) )<br>
> > <br>> > <br></div></div>> > Thanks,<br>> > cabear<br>> ><br>> ><br>
<div>
<div></div>
<div class="h5">> > 2009/11/8 Greg Barton <<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>><br>><br>> ><br>> > There are a couple of<br>> > ways to do this. I'm sure there's a bit more<br>
> clean<br>> > way than the example I'm providing, but this<br>> should get<br>> > you in the right direction. It's not 100%<br>> rules,<br>><br>> > because it involves a bit of java collections<br>
> trickery. (See<br>> > attached project,<br>> collection_DroolsCriteriaMatch.tar.gz)<br>> ><br>> ><br>> > The heart of it is a single rule:<br>> ><br>> > rule "Match"<br>
><br>> > when<br>> > d : Data()<br>> > q : Query( size <= d.size )<br>> > Number( intValue == q.size )<br>> > from accumulate(<br>> > Criteria( this memberOf d, this memberOf q ),<br>
> ><br>> > init( int total = 0; ),<br>><br>> > action( total ++; ),<br>> > reverse( total --; ),<br>> > result( total )<br>> > )<br>> > then<br>> > System.out.println("Match: " + d +<br>
> "<br>> > and " + q) ;<br>> > end<br>><br>> ><br>> > The Data object holds data to be queried, Query<br>> objects are<br>> > asserted to match the Data, and Criteria objects can<br>
> be<br>> > contained in either. (With the aforementioned<br>> collections<br>> > trickery that if a Criteria is contained in a Query it<br>> can<br>><br>> > be found in a Data object, but the reverse isn't<br>
> true.<br>> > See the Query.contains(Object) method for how<br>> that's<br>> > implemented.)<br>> ><br>> ><br>> > So the rule above basically says "There's a<br>> Data<br>
><br>> > object, and all of the Query objects Criteria are<br>> contained<br>> > in the Data object."<br>> ><br>> > There's an alternate way of doing this using eval<br>> and a<br>
> > bit more java fu. See the<br>> eval_DroolsCriteriaMatch.tar.gz<br>><br>> > project attached. This one's probably not<br>> optimal,<br>> > though, as it's basically a brute force check of<br>
> all<br>> > Data objects against the asserted Query.<br>> ><br>> ><br>> > I tried for a while to get a solution working with<br>><br>> > different criteria types from both Data and Query<br>
> objects<br>> > being asserted into working memory, but I couldn't<br>> get<br>> > the accumulate syntax right. Anyone know of a way to<br>> do<br>> > that? (I figure that would get a "pure<br>
> rules"<br>><br>> > solution.)<br>> ><br>> ><br>> > --- On Sat, 11/7/09, Wishing Carebear <<a href="mailto:wishing.carebear@gmail.com">wishing.carebear@gmail.com</a>><br>> > wrote:<br>
> ><br>> > > From: Wishing Carebear <<a href="mailto:wishing.carebear@gmail.com">wishing.carebear@gmail.com</a>><br>><br>> ><br>> > > Subject: [rules-users] some pointers for<br>> solution<br>
> > > To: <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>> > > Date: Saturday, November 7, 2009, 10:19 PM<br>><br>> ><br>> ><br>> ><br></div></div>
<div class="im">> > > Hello:<br>> > > There are n selection criteria from s1 .. sn for<br>> each<br>> > > item i1.. in. Each item can have a subset of<br>> criteria<br>> > which<br>
> > > applies to them.<br>><br>> > > <br>> > > The end user, can choose a subset of criteria<br>> like c1<br>> ><br>> > > and c5 and only the item that has c1 and c5<br>> valid<br>
> > should be<br>> > > returned. For example: if item i1 and i2 have<br>><br>> > criterias<br>> > > valid for c1, c2, c5, c6, c8 since the request is<br>> only<br>> > for<br>> > > criteria c1 and c5, i1 and i2 must be returned.<br>
> ><br>> > ><br>> > > <br>> > > Is it possible to write a rule using drools for<br>> this<br>><br>> > > requirement.<br>> > > <br>> > > Thanks for your help and time,<br>
> > > cabear<br>> > ><br></div>> > > -----Inline Attachment Follows-----<br>
<div class="im">> ><br>> > ><br>> > > _______________________________________________<br>><br>> > > rules-users mailing list<br>> > > <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
> > > <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>><br>> ><br>> > ><br>> ><br>> ><br>> > <br>
> > _______________________________________________<br>> > rules-users mailing list<br>> > <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>><br>> > <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
> ><br>> ><br>> ><br>> ><br>> ><br></div>> > -----Inline Attachment Follows-----<br>
<div class="im">><br>> ><br>> > _______________________________________________<br>> > rules-users mailing list<br>> > <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
> > <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>><br>> ><br>><br>><br>><br>><br>> _______________________________________________<br>
> rules-users mailing list<br>> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
><br>><br>><br>><br></div>
<div class="im">> --<br>> Edson Tirelli<br>> JBoss Drools Core Development<br>> JBoss by Red Hat @ <a href="http://www.jboss.com/" target="_blank">www.jboss.com</a><br>><br>><br>> _______________________________________________<br>
</div>
<div class="im">> rules-users mailing list<br>> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
><br>><br>><br>><br>><br></div>> -----Inline Attachment Follows-----<br>
<div>
<div></div>
<div class="h5">><br>> _______________________________________________<br>> rules-users mailing list<br>> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
><br><br><br> </div></div><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>