Fair point :)<br><br>I took &quot;collection&quot; to mean some letters rather than &quot;Collection&quot;.<br><br><div class="gmail_quote">2010/12/18 Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Looks somewhat different to me; originally there&#39;s a fact containing a Collection of letters, not individual Letter() facts, each with its own character. Therefore, you don&#39;t have the fact for the initial pattern.<br>

-W<br><br><div class="gmail_quote">2010/12/18 Michael Anstis <span dir="ltr">&lt;<a href="mailto:michael.anstis@gmail.com" target="_blank">michael.anstis@gmail.com</a>&gt;</span><div><div></div><div class="h5"><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Am I missing something or can&#39;t this be achieved purely &quot;in rule&quot;:-<br><br><span style="font-family: courier new,monospace;">rule &quot;Letter counter&quot;</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">salience -100</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">when</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    Letter( $c: character )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    not LetterCount( character == $c )</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    List( $s : size &gt; 1 ) </span><span style="font-family: courier new,monospace;">from collect( Letter( character == $c ) )</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">then</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    LetterCount lc = new LetterCount();</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    lc.setCharacter($c);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    lc.setDuplications($s);</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    insert(lc);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">end</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">rule &quot;Totals&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    salience 0</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">when</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    LetterCount($c : character, $s : duplications);</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">then</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    System.out.println(&quot;Letter &quot; + $c + &quot; has &quot; + $s + &quot; duplications&quot;</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">end</span><br style="font-family: courier new,monospace;"><br><div class="gmail_quote">2010/12/18 Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</span><div>

<div></div><div><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">createCardinality must return a Collection. I think the simplest way of<br>solving your problem is to write a simple class LetterCounter implementing<br>


the counting and a DRL function extracting the collection of Tuples from the LetterCounter:<br>
<br>public class LetterCounter extends HashMap&lt;Character,Integer&gt; {<br>    public static  Set&lt;Map.Entry&lt;Character,Integer&gt;&gt; counterSet( Collection&lt;Character&gt; l ){<br>        return new LetterCounter( l ).entrySet();<br>



    }<br>    public LetterCounter( Collection&lt;Character&gt; chars ){<br>        super();<br>        for( Character c: chars ){<br>            Integer count = get( c );<br>            put( c, count == null ? 1 : count + 1 );<br>



        }<br>    }<br>}<br><br>rule &quot;count&quot;<br>when<br>    $t: Something( $l: collectionOfLetters )<br>    Map.Entry(  $key: key, $val: value &gt; 1 ) from LetterCounter.counterSet( $l )<br>then<br>    System.out.println( &quot;letter &quot; + $key + &quot;: &quot; + $val );<br>



end<br><font color="#888888"><br>-W</font><div><div></div><div><br><br><div class="gmail_quote">On 18 December 2010 12:16, AleBu <span dir="ltr">&lt;<a href="mailto:aleboo@gmail.com" target="_blank">aleboo@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi,<br>
I am new to Drools and do some experiments on it, and encountered on a<br>
problem which can&#39;t solve for a last few days, so maybe someone can explain<br>
what I am doing wrong?<br>
I will probably explain my problem with example. Lets say we have a<br>
collection of letters like &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;a&#39;, &#39;d&#39;, &#39;e&#39;, &#39;c&#39;. And I want to<br>
report all letters that are duplicated, but only once providing a number of<br>
duplication. In other words, for each letter which is duplicated I need to<br>
do a report by saying &#39;Letter X is duplicated N times.<br>
My idea was to create cardinality collection for letters which is a<br>
collection of POJOs Tuple where first is letter and second is cound (first<br>
and second are properties). I created a function for it createCardinality(<br>
Collection letters ) which returns such cardinality info and tried something<br>
like:<br>
when<br>
        Something( $letters: collectionOfLetters )<br>
        Tuple( $letter: first, $count: second &gt; 1 ) from collect( Tuple() from<br>
createCardinality( $letters ) )<br>
then<br>
        System.out.println( &quot;Letter &quot;+letter+&quot; is duplicated &quot;+$count+&quot;<br>
times&quot; )<br>
<br>
But I am reported (at least it looks like this) about the problems with my<br>
function createCardinality(). Maybe I misunderstood something about usage of<br>
FROM?<br>
<font color="#888888">--<br>
View this message in context: <a href="http://drools-java-rules-engine.46999.n3.nabble.com/How-to-use-a-result-of-custom-defined-function-in-WHEN-part-tp2110515p2110515.html" target="_blank">http://drools-java-rules-engine.46999.n3.nabble.com/How-to-use-a-result-of-custom-defined-function-in-WHEN-part-tp2110515p2110515.html</a><br>




Sent from the Drools - User mailing list archive at Nabble.com.<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>
</font></blockquote></div><br>
</div></div><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></blockquote></div></div></div><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></blockquote></div></div></div><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></blockquote></div><br>