<br>    David,<br><br>    This is an interesting use case, but I don&#39;t think you can build a complete explanation from the agenda listener. <br>    Let me clarify: you can do 80% of the explanation from there, based on the position of the fact handles in the tuple. The collection you get from event.getActivation().<div class="h5">
getFactHandles() will have the facts in the exact same &quot;offset&quot; order you have in your rule. For simple rules, it is &quot;straight forward&quot;:<br><br>when<br>    A()<br>    B()<br>    C()<br>then<br>end<br> <br>
    In the above example, A() will be offset 0, B() will be 1 and C() will be 2.<br><br>    The 20% you will not be able to explain with such solution are the cases where you have nested patterns, with the use of ORs (that create multiple logical branches), NOT/EXISTS/FORALL ( that don&#39;t generate a fact in the activating tuple), COLLECT/ACCUMULATE that will condense multiple conditions into one element, etc. <br>
<br>    My best advise for you is: if this is a non-critical part of your system, go ahead with the approach above, and you will be able to provide most of the explanations with a simple heuristic. But if this is critical for your use case, my suggestion would be for you to get your company to allow you to work with us for some time implementing this requirement as a proper drools feature. We can guide you through the drools internals and add the feature your company needs and your company donates the code for the project so that we can support it in the future. It is an open source project after all. <br>
 <br>    Need to check with Mark what he thinks about the feature, but it sounds interesting for me.<br><br>    []s<br>    Edson<br></div><br><br><div class="gmail_quote">2009/3/9 David Boaz <span dir="ltr">&lt;<a href="mailto:davidb@dbmotion.com">davidb@dbmotion.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
Thanks Mark,<br>
<br>
I tried to analyze (in the debugger) the RETE network, and to my<br>
understanding, it is not possible to map back from the RETE nodes to the<br>
rule pattern. in the example above the two Person patterns will share the<br>
same EntryPointNode and ObjectTypeNode, hence, there is no way to determine<br>
what was the original pattern.<br>
<br>
My use case, is to generate &#39;explanation&#39; objects. These object will log for<br>
each successful rule firing the identifiers of the facts that produced this<br>
consequence. Later on, we want to enable providing explanations as: &quot;we<br>
reached this conclusion because field (actual=2) &lt; 4&quot;. So, in the<br>
explanation process we want to substitute the rule patterns with actual<br>
facts.<br>
When the rule patterns are of the same object-type, there is a possibility<br>
to confuse and to assign the wrong fact to the pattern. Hence, I wanted to<br>
determine and log what was the &#39;causing&#39; pattern for each fact.<br>
<br>
I hope that my description is clear,<br>
BR, David<br>
<div><div></div><div class="h5"><br>
<br>
<br>
Mark Proctor wrote:<br>
&gt;<br>
&gt; Mark Proctor wrote:<br>
&gt;&gt; David Boaz wrote:<br>
&gt;&gt;&gt; Hi all,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Is it possible to determine the Pattern that ‘produced’ a given Fact?<br>
&gt;&gt;&gt; For<br>
&gt;&gt;&gt; example, assuming we have the following rule and event handler:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; rule r1<br>
&gt;&gt;&gt;     when         p1:Person(...)<br>
&gt;&gt;&gt;         p2:Person(...)<br>
&gt;&gt;&gt;     then<br>
&gt;&gt;&gt;     ...<br>
&gt;&gt;&gt; end<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; protected class MyAgendaEventHandler extends<br>
&gt;&gt;&gt;         DefaultAgendaEventListener {<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     @Override<br>
&gt;&gt;&gt;     public void<br>
&gt;&gt;&gt; afterActivationFired(org.drools.event.rule.AfterActivationFiredEvent<br>
&gt;&gt;&gt; event)<br>
&gt;&gt;&gt; {<br>
&gt;&gt;&gt;         String ruleName = event.getActivation().getRule().getName();<br>
&gt;&gt;&gt;         KnowledgeRuntime knowledgeRuntime = event.getKnowledgeRuntime();<br>
&gt;&gt;&gt;         for (FactHandle factHandle :<br>
&gt;&gt;&gt; event.getActivation().getFactHandles()) {<br>
&gt;&gt;&gt;             Object fact = knowledgeRuntime.getObject(factHandle);<br>
&gt;&gt;&gt;             Pattern pattern= ?;<br>
&gt;&gt;&gt;         }<br>
&gt;&gt;&gt;     }<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Is it possible to determine the Pattern that originate a Person<br>
&gt;&gt;&gt; object? If<br>
&gt;&gt;&gt; yes, how the pattern is identified?<br>
&gt;&gt;&gt;<br>
&gt;&gt; no<br>
&gt; We&#39;ll that&#39;s not exactly true, but it&#39;s not something an end user should<br>
&gt; be doing. But the basic jist is the Activation wraps the AgendaItem if<br>
&gt; you can get access to that it has a Tuple field, this references the<br>
&gt; chaines of tuples that make up the row of data. you can iterate that<br>
&gt; chain and each one has a handle field which you can match up with the<br>
&gt; facthandle you are searching for. Further more each tuple references the<br>
&gt; join node it was added via, which also has an index number, so you can<br>
&gt; deduce the pattern from there. However I seriously doubt this is what<br>
&gt; you want, and you probably need to think harder about your use case.<br>
&gt;<br>
&gt; Mark<br>
&gt;&gt;&gt; Thanks, David<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;&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>
</div></div><font color="#888888">--<br>
View this message in context: <a href="http://www.nabble.com/Events---Determining-the-Fact-Pattern-tp22397570p22413433.html" target="_blank">http://www.nabble.com/Events---Determining-the-Fact-Pattern-tp22397570p22413433.html</a><br>

</font><div class="im">Sent from the drools - user mailing list archive at Nabble.com.<br>
<br>
<br>
_______________________________________________<br>
</div><div><div></div><div class="h5">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><br clear="all"><br>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>