I do this.

 

I use a custom function to perform my inserts like this: (I also have a property called rule in my data facts, that I store the rule name into so I can trace the logic tree that set the fact values).  This is also based on the assumption that your facts you are created are being inserted into working memory, and not a global array. (which I also do).

 

 

When

                Anything

Then

                createOrUpdateFact(drools, “someFactName”);

End

 

In JAVA, I have written the function:

 

public static void createOrUpdateFuct(RuleContext rule, Object fact)

{

                KnowledgeRuntime rt = rule.getKnowledgeRuntime();

                UUID id = null;

                Object value = null;

                If (fact instanceof MyGenericFactInterface)

                {

                                MyGenericFactInterface fi = (MyGenericFactInterface) fact;

                                Id = fi.getUniqueId();

                                value = fi.getValue();

                               

                                FactHandle handle = getFactHandle(rule, fact);

                                If (handle == null)

{

                                                rt.insert(fact);

                                                log.fine(“Insert fact: (“ + fact.toString() + “) from rule: “  + rule.getRule().getName() );

                                }

                                else

                                {

                                                rt.modify(handle, fact);

                                                log.fine(“Update fact: (“ + fact.toString() + “) from rule: “  + rule.getRule().getName() );

                                }

                }

}

 

private static FactHandle getFactHandle(RuleContext rule, Object fact)

{

                for (FactHandle fh : rule.getKnowledgeRuntime().getFactHandles())

                                if (fact.equals(rule.getKnowledgeRuntime().getObject(fh)))

                                                return fh;

                return null;

}

 

From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Mark Proctor
Sent: Friday, April 20, 2012 4:49 AM
To: rules-users@lists.jboss.org
Subject: Re: [rules-users] Explanation of a decision

 

On 20/04/2012 12:33, Maxim Kolchin wrote:

Hi,

I'm working on expert system, automating one of the stages of optical design.
Now, we're testing the system and we need a function, eÈplaining a decision of the system: which rules has been fired, why they has been fired and so on. And I'm looking for a way to implement this feature.

Has someone had an experience in implementing this kind of features? Or does someone know how it can be implemented?

Take a look at the audit log, that just uses listeners to create a trace of the execution.

Mark


Thank you,

Maxim Kolchin
Laboratory of Intellectual Systems,
National Research University ITMO,
http://en.ifmo.ru



_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users