[rules-users] Events - Determining the Fact Pattern

Mark Proctor mproctor at codehaus.org
Sun Mar 8 14:39:08 EDT 2009


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
>
>





More information about the rules-users mailing list