[rules-users] Events - Determining the Fact Pattern

David Boaz davidb at dbmotion.com
Mon Mar 9 10:58:45 EDT 2009


Thanks Mark,

I tried to analyze (in the debugger) the RETE network, and to my
understanding, it is not possible to map back from the RETE nodes to the
rule pattern. in the example above the two Person patterns will share the
same EntryPointNode and ObjectTypeNode, hence, there is no way to determine
what was the original pattern.

My use case, is to generate 'explanation' objects. These object will log for
each successful rule firing the identifiers of the facts that produced this
consequence. Later on, we want to enable providing explanations as: "we
reached this conclusion because field (actual=2) < 4". So, in the
explanation process we want to substitute the rule patterns with actual
facts.
When the rule patterns are of the same object-type, there is a possibility
to confuse and to assign the wrong fact to the pattern. Hence, I wanted to
determine and log what was the 'causing' pattern for each fact.

I hope that my description is clear, 
BR, David



Mark Proctor wrote:
> 
> Mark Proctor wrote:
>> David Boaz wrote:
>>> Hi all,
>>>
>>> Is it possible to determine the Pattern that ‘produced’ a given Fact? 
>>> For
>>> example, assuming we have the following rule and event handler:
>>>
>>> rule r1
>>>     when         p1:Person(...)
>>>         p2:Person(...)
>>>     then
>>>     ...
>>> end
>>>
>>> protected class MyAgendaEventHandler extends
>>>         DefaultAgendaEventListener {
>>>
>>>     @Override
>>>     public void
>>> afterActivationFired(org.drools.event.rule.AfterActivationFiredEvent 
>>> event)
>>> {
>>>         String ruleName = event.getActivation().getRule().getName();
>>>         KnowledgeRuntime knowledgeRuntime = event.getKnowledgeRuntime();
>>>         for (FactHandle factHandle : 
>>> event.getActivation().getFactHandles()) {
>>>             Object fact = knowledgeRuntime.getObject(factHandle);
>>>             Pattern pattern= ?;
>>>         }
>>>     }
>>> }
>>>
>>> Is it possible to determine the Pattern that originate a Person 
>>> object? If
>>> yes, how the pattern is identified?
>>>   
>> no
> We'll that's not exactly true, but it's not something an end user should 
> be doing. But the basic jist is the Activation wraps the AgendaItem if 
> you can get access to that it has a Tuple field, this references the 
> chaines of tuples that make up the row of data. you can iterate that 
> chain and each one has a handle field which you can match up with the 
> facthandle you are searching for. Further more each tuple references the 
> join node it was added via, which also has an index number, so you can 
> deduce the pattern from there. However I seriously doubt this is what 
> you want, and you probably need to think harder about your use case.
> 
> Mark
>>> Thanks, David
>>>   
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
> 
> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: http://www.nabble.com/Events---Determining-the-Fact-Pattern-tp22397570p22413433.html
Sent from the drools - user mailing list archive at Nabble.com.





More information about the rules-users mailing list