It&#39;s getting closer now but still has one problem that it reports for a pattern match where there&#39;s an EventB with same index value in between.<div>The Testing events feed pattern that I use can be described as below:</div>
<div><br></div><div>EventA:0 &nbsp; EventB:1 &nbsp; EventA:0 &nbsp; EventB:1 &nbsp; EventA:1 &nbsp; EventB:0 &nbsp; EventA:0 &nbsp; here it reports for a pattern match where it shouldn&#39;t &nbsp;EventB:1</div><div><br></div><div>Best Regards,</div><div>Kevin Zhao<br>
<br><div class="gmail_quote">在 2010年10月26日 下午4:33,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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
If there may be two EventA with the same timestamp, additional<br>
constraints may be necessary, and<br>
after may have to be used with a start time of 0ms:<br>
<br>
&nbsp;$a1: EventA( $index : index )<br>
&nbsp;$a2: EventA( this != $a1 &amp;&amp; after[0ms] $a1, index == $index )<br>
&nbsp;$a3: EventA( this != $a1 &amp;&amp; != $a2 &amp;&amp; after[0ms] $a2, index == $index )<br>
<br>
-W<br>
<br>
<br>
2010/10/26 赵侃侃 &lt;<a href="mailto:kevin223@gmail.com">kevin223@gmail.com</a>&gt;:<br>
<div><div></div><div class="h5">&gt; Hello,<br>
&gt; Hello,<br>
&gt; I just tried this rule, but it doesn&#39;t seem to work as expected.<br>
&gt; What I have now is every time I have an EventA received then a pattern is<br>
&gt; reported matched no matter whether any of the other constrains is met.<br>
&gt; Any ideas?<br>
&gt; Best Regards,<br>
&gt; Kevin Zhao<br>
&gt;<br>
&gt; 2010/10/26 Michael Anstis &lt;<a href="mailto:michael.anstis@gmail.com">michael.anstis@gmail.com</a>&gt;<br>
&gt;&gt;<br>
&gt;&gt; You could try this too; if you don&#39;t want lots of new attributes for your<br>
&gt;&gt; model:-<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;three A&quot;<br>
&gt;&gt; when<br>
&gt;&gt; &nbsp; $a1: EventA( $index : index )<br>
&gt;&gt; &nbsp; $a2: EventA( index == $index )<br>
&gt;&gt; &nbsp; $a3: EventA( index == $index )<br>
&gt;&gt; &nbsp; not PatternConsumer( name == &#39;AAA&#39;, events contain $a1 || contais $a2 ||<br>
&gt;&gt; contains $a3)<br>
&gt;&gt; &nbsp; not EventB( this after[0ms] $a1 &amp;&amp; before[0ms] $a3, index == $index )<br>
&gt;&gt; then<br>
&gt;&gt; &nbsp; // ... match<br>
&gt;&gt; &nbsp; PatternConsumer pc = new PatternConsumer(&quot;AAA&quot;, $a1, $a2, $a3 );<br>
&gt;&gt; &nbsp; insert(pc);<br>
&gt;&gt; end<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; 2010/10/25 Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Giving those other rules a higher salience is one way, but I think<br>
&gt;&gt;&gt; it is better to add a boolean field &quot;usedForAAA&quot; to class EventA.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; rule &quot;three A&quot;<br>
&gt;&gt;&gt; when<br>
&gt;&gt;&gt; &nbsp; $a1: EventA( $index : index, usedForAAA == false )<br>
&gt;&gt;&gt; &nbsp; $a2: EventA( index == $index, usedForAAA == false )<br>
&gt;&gt;&gt; &nbsp; $a3: EventA( index == $index, usedForAAA == false )<br>
&gt;&gt;&gt; &nbsp; not EventB( this after[0ms] $a1 &amp;&amp; before[0ms] $a3, index == $index )<br>
&gt;&gt;&gt; then<br>
&gt;&gt;&gt; &nbsp; // ... match<br>
&gt;&gt;&gt; &nbsp; modify( $a1 ){ setUsedForAAA( true ) }<br>
&gt;&gt;&gt; &nbsp; modify( $a2 ){ setUsedForAAA( true ) }<br>
&gt;&gt;&gt; &nbsp; modify( $a3 ){ setUsedForAAA( true ) }<br>
&gt;&gt;&gt; end<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; -W<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; 2010/10/25 赵侃侃 &lt;<a href="mailto:kevin223@gmail.com">kevin223@gmail.com</a>&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Thanks Wolfgang,<br>
&gt;&gt;&gt;&gt; It now starts to make sense to me. However, is it possible that I don&#39;t<br>
&gt;&gt;&gt;&gt; retract those matched eventA? All those events might be used to evaluate<br>
&gt;&gt;&gt;&gt; against other rules.<br>
&gt;&gt;&gt;&gt; Thanks again,<br>
&gt;&gt;&gt;&gt; Kevin Zhao<br>
&gt;&gt;&gt;&gt; 2010/10/25 Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; I assume you are using Fusion, using a session clock so that temporal<br>
&gt;&gt;&gt;&gt;&gt; operators are available.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; rule &quot;three A&quot;<br>
&gt;&gt;&gt;&gt;&gt; when<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; $a1: EventA( $index : index )<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; $a2: EventA( index == $index )<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; $a3: EventA( index == $index )<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; not EventB( this after[0ms] $a1 &amp;&amp; before[0ms] $a3, index == $index )<br>
&gt;&gt;&gt;&gt;&gt; then<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; // ... match<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; retract( $a1 );<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; retract( $a2 );<br>
&gt;&gt;&gt;&gt;&gt; &nbsp; retract( $a3 );<br>
&gt;&gt;&gt;&gt;&gt; end<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; -W<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; 2010/10/25 赵侃侃 &lt;<a href="mailto:kevin223@gmail.com">kevin223@gmail.com</a>&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; Hello,<br>
&gt;&gt;&gt;&gt;&gt;&gt; I&#39;m still quite new to the drools stuffs just getting the examples<br>
&gt;&gt;&gt;&gt;&gt;&gt; running. I&#39;m sorry if my question is too basic.<br>
&gt;&gt;&gt;&gt;&gt;&gt; I have a system that will continuously to receive events sent from<br>
&gt;&gt;&gt;&gt;&gt;&gt; some other system. Basically I have two types of events, eventA and eventB.<br>
&gt;&gt;&gt;&gt;&gt;&gt; Both eventA and eventB have two properties, index and timestamp.<br>
&gt;&gt;&gt;&gt;&gt;&gt; What I want is to capture a pattern to meet the following conditions<br>
&gt;&gt;&gt;&gt;&gt;&gt; 1. every 3 consecutive eventsA without any eventB in between having a<br>
&gt;&gt;&gt;&gt;&gt;&gt; same index value ordering by their timestamp.<br>
&gt;&gt;&gt;&gt;&gt;&gt; 2. all events in a matched pattern will have the same value of<br>
&gt;&gt;&gt;&gt;&gt;&gt; property index.<br>
&gt;&gt;&gt;&gt;&gt;&gt; 3. if a pattern is matched, any of the events in this pattern should<br>
&gt;&gt;&gt;&gt;&gt;&gt; not be used again for a new matching.<br>
&gt;&gt;&gt;&gt;&gt;&gt; there are some examples below, the number after a colon stands for the<br>
&gt;&gt;&gt;&gt;&gt;&gt; value of its index number and assume those events are already ordered by<br>
&gt;&gt;&gt;&gt;&gt;&gt; their timestamp.<br>
&gt;&gt;&gt;&gt;&gt;&gt; eventB:2 &nbsp; &nbsp;eventA:1 &nbsp; &nbsp; eventA:1 &nbsp; &nbsp; eventA:1 &nbsp;eventB:3<br>
&gt;&gt;&gt;&gt;&gt;&gt; &nbsp;--------- one successful match, we have three eventA with same index value<br>
&gt;&gt;&gt;&gt;&gt;&gt; 1 in a row<br>
&gt;&gt;&gt;&gt;&gt;&gt; eventB:2 &nbsp; &nbsp;eventA:1 &nbsp; &nbsp; eventA:1 &nbsp; &nbsp; eventB:1 &nbsp;eventA:1<br>
&gt;&gt;&gt;&gt;&gt;&gt; &nbsp;--------- no match because there&#39;s an eventB in between<br>
&gt;&gt;&gt;&gt;&gt;&gt; eventB:2 &nbsp; &nbsp;eventA:1 &nbsp; &nbsp; eventA:1 &nbsp; &nbsp; eventB:2 &nbsp;eventA:1<br>
&gt;&gt;&gt;&gt;&gt;&gt; &nbsp;--------- one successful match because the in-between eventB has a<br>
&gt;&gt;&gt;&gt;&gt;&gt; different index value<br>
&gt;&gt;&gt;&gt;&gt;&gt; eventA:1 &nbsp; &nbsp;eventA:1 &nbsp; &nbsp; eventA:1 &nbsp; &nbsp; eventA:1 &nbsp;eventA:1<br>
&gt;&gt;&gt;&gt;&gt;&gt; &nbsp;--------- only one match, because once matched, the events can not be used<br>
&gt;&gt;&gt;&gt;&gt;&gt; for a second match again.<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; I just don&#39;t know how to write a rule like this. Is there anyone who<br>
&gt;&gt;&gt;&gt;&gt;&gt; can shed some lights on?<br>
&gt;&gt;&gt;&gt;&gt;&gt; Best Regards,<br>
&gt;&gt;&gt;&gt;&gt;&gt; Kevin<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt;&gt;&gt;&gt; rules-users mailing list<br>
&gt;&gt;&gt;&gt;&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt;&gt;&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;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt;&gt;&gt; rules-users mailing list<br>
&gt;&gt;&gt;&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt;&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;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt;&gt; rules-users mailing list<br>
&gt;&gt;&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&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;&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&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;&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;&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;<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>
<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>
</div></div></blockquote></div><br></div>