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