<div>Yes Edson, I tried with count and sum. Both seems to be working fine.</div>
<div> </div>
<div>But with the test case, the Criteria for query also needs to be inserted in addition to the query and data objects like shown below:</div>
<div> </div><font size="2">
<p align="left">Query query = </p></font><b><font color="#7f0055" size="2"><font color="#7f0055" size="2">new</font></font></b><font size="2"> Query(1);
<p align="left">query.add(</p></font><b><font color="#7f0055" size="2"><font color="#7f0055" size="2">new</font></font></b><font size="2"> Criteria(query, </font><font color="#2a00ff" size="2"><font color="#2a00ff" size="2">"c2"</font></font><font size="2">, </font><font color="#2a00ff" size="2"><font color="#2a00ff" size="2">"bas"</font></font><font size="2">));
<p align="left">ksession.insert(query);</p>
<p align="left"></p></font><b><font color="#7f0055" size="2"><font color="#7f0055" size="2">for</font></font></b><font size="2">(Criteria c : query) {
<p align="left">ksession.insert(c);</p>
<p>}</p>
<p></p></font>
<div> </div>
<div>Is it possible to avoid them.</div>
<div> </div>
<div>Thanks,</div>
<div>cabear</div>
<div><br><br></div>
<div class="gmail_quote">2009/11/8 Edson Tirelli <span dir="ltr"><<a href="mailto:ed.tirelli@gmail.com">ed.tirelli@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br> Why not use count() accumulate function? ;)
<div class="im"><br><br>from accumulate( Criteria( this memberOf d, this memberOf q ),<br></div> count(1) )<br><br> Edson
<div>
<div></div>
<div class="h5"><br><br>
<div class="gmail_quote">2009/11/8 Greg Barton <span dir="ltr"><<a href="mailto:greg_barton@yahoo.com" target="_blank">greg_barton@yahoo.com</a>></span><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">In this case the accumulate clause is maintaining a counter (total) that's incremented whenever a Criteria is detected that is contained in both the Data and Query object matched in the rule. So:<br>
<br># Find Criteria that are contained in both the Data and Query<br>
<div>from accumulate( Criteria( this memberOf d, this memberOf q ),<br></div># 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>
reverse( total --; ),<br># return the total when all known Criteria are matched<br> result( total ) )<br>
<div><br>--- On Sun, 11/8/09, Wishing Carebear <<a href="mailto:wishing.carebear@gmail.com" target="_blank">wishing.carebear@gmail.com</a>> wrote:<br><br>> From: Wishing Carebear <<a href="mailto:wishing.carebear@gmail.com" target="_blank">wishing.carebear@gmail.com</a>><br>
</div>> Subject: Re: [rules-users] some pointers for solution<br>> To: "Rules Users List" <<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>><br>> Date: Sunday, November 8, 2009, 11:39 AM<br>
<div>
<div></div>
<div>> 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>
> this memberOf q ),<br>> init( int total = 0; ),<br>> action( total ++; ),<br>> reverse( total --; ),<br>> result( total ) )<br>> <br>> <br>> Thanks,<br>> cabear<br>><br>><br>> 2009/11/8 Greg Barton <<a href="mailto:greg_barton@yahoo.com" target="_blank">greg_barton@yahoo.com</a>><br>
><br>> There are a couple of<br>> ways to do this. I'm sure there's a bit more clean<br>> way than the example I'm providing, but this should get<br>> you in the right direction. It's not 100% rules,<br>
> because it involves a bit of java collections trickery. (See<br>> attached project, collection_DroolsCriteriaMatch.tar.gz)<br>><br>><br>> The heart of it is a single rule:<br>><br>> rule "Match"<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>
> action( total ++; ),<br>> reverse( total --; ),<br>> result( total )<br>> )<br>> then<br>> System.out.println("Match: " + d + "<br>> and " + q) ;<br>> end<br>
><br>> The Data object holds data to be queried, Query objects are<br>> asserted to match the Data, and Criteria objects can be<br>> contained in either. (With the aforementioned collections<br>> trickery that if a Criteria is contained in a Query it can<br>
> be found in a Data object, but the reverse isn't true.<br>> See the Query.contains(Object) method for how that's<br>> implemented.)<br>><br>><br>> So the rule above basically says "There's a Data<br>
> object, and all of the Query objects Criteria are contained<br>> in the Data object."<br>><br>> There's an alternate way of doing this using eval and a<br>> bit more java fu. See the eval_DroolsCriteriaMatch.tar.gz<br>
> project attached. This one's probably not optimal,<br>> though, as it's basically a brute force check of all<br>> Data objects against the asserted Query.<br>><br>><br>> I tried for a while to get a solution working with<br>
> different criteria types from both Data and Query objects<br>> being asserted into working memory, but I couldn't get<br>> the accumulate syntax right. Anyone know of a way to do<br>> that? (I figure that would get a "pure rules"<br>
> solution.)<br>><br>><br>> --- On Sat, 11/7/09, Wishing Carebear <<a href="mailto:wishing.carebear@gmail.com" target="_blank">wishing.carebear@gmail.com</a>><br>> wrote:<br>><br>> > From: Wishing Carebear <<a href="mailto:wishing.carebear@gmail.com" target="_blank">wishing.carebear@gmail.com</a>><br>
><br>> > Subject: [rules-users] some pointers for solution<br>> > To: <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>> > Date: Saturday, November 7, 2009, 10:19 PM<br>
><br>><br>><br>> > Hello:<br>> > There are n selection criteria from s1 .. sn for each<br>> > item i1.. in. Each item can have a subset of criteria<br>> which<br>> > applies to them.<br>
> > <br>> > The end user, can choose a subset of criteria like c1<br>><br>> > and c5 and only the item that has c1 and c5 valid<br>> should be<br>> > returned. For example: if item i1 and i2 have<br>
> criterias<br>> > valid for c1, c2, c5, c6, c8 since the request is 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 this<br>
> > requirement.<br>> > <br>> > Thanks for your help and time,<br>> > cabear<br>> ><br>> > -----Inline Attachment Follows-----<br>><br>> ><br>> > _______________________________________________<br>
> > rules-users mailing list<br>> > <a href="mailto:rules-users@lists.jboss.org" target="_blank">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>> rules-users mailing list<br>> <a href="mailto:rules-users@lists.jboss.org" target="_blank">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>> -----Inline Attachment Follows-----<br>
><br>> _______________________________________________<br>> rules-users mailing list<br>> <a href="mailto:rules-users@lists.jboss.org" target="_blank">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>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
</div></div></blockquote></div><br><br clear="all"><br></div></div><font color="#888888">-- <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>
</font><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>