<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">&lt;<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>&gt;</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&#39;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 &quot;Match&quot;<br> when<br>   d : Data()<br>   q : Query( size &lt;= 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(&quot;Match: &quot; + d + &quot; and &quot; + q) ;<br>end<br><br></div>Try the other methods, though. (The eval &#39;hack&#39; I included before, and Wolfgang&#39;s method.)  All of these approaches should have different performance behavior, and I honestly don&#39;t know which one is fastest.<br>

<div class="im"><br>--- On Sun, 11/8/09, Wishing Carebear &lt;<a href="mailto:wishing.carebear@gmail.com">wishing.carebear@gmail.com</a>&gt; wrote:<br><br>&gt; From: Wishing Carebear &lt;<a href="mailto:wishing.carebear@gmail.com">wishing.carebear@gmail.com</a>&gt;<br>
&gt; Subject: Re: [rules-users] some pointers for solution<br>&gt; To: &quot;Rules Users List&quot; &lt;<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>&gt;<br></div>&gt; Date: Sunday, November 8, 2009, 8:02 PM<br>

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