There's a method "Rete.getThisActivation()" that you can call while a
rule is firing; it gives you a jess.Activation object, which in turn
gives you the Defrule object and the jess.Token (i.e., the list of
facts the rule fired on.) So from the right hand side of a rule, you
can get all the information you need, and you can record this
information however you wish.
For example, you could use the "defadvice" function to add advice
before the "assert" function, so that whenever a fact was asserted,
information about the current activation was stored in a Map or List.
One word of caution: the Activation will contain links to the actual
working memory elements, and these may change over time, so don't
store the facts themselves as your explanation record: copy them, or
convert them to a readable string form.
On Sep 10, 2008, at 5:24 AM, Broekstra, Jeen wrote:
Hi all,
I am trying to develop a program where based on a set of facts and
rules
a user gets presented with a certain conclusion (I reckon that holds
for
almost any Jess program ;)), but also with the reasoning path that led
to that conclusion. Essentially, I need to implement a
"why"-functionality.
Now, I am aware of Jess's logical clause that allows you to trace
dependencies between facts. However, I need something slightly more
sophisticated than that: I need to be able to reproduce the actual
rule(s) that led to a conclusion.
To clarify, a simple example:
(assert(duck (name donald)))
(assert(uncleOf donald huey))
(assert(uncleOf donald louie))
(assert(uncleOf donald dewey))
(defrule nephews
"if some duck is an uncle of someone else, that someone else is
his nephew"
(duck(name ?X)))
(uncleOf ?X ?Y)))
=>
(assert(nephewOf ?Y ?X))
The user is interested in the conclusion: ("huey is a nephew of
donald")
but also in the explanation of that conclusion:
"huey is a nephew of donald" because
1. donald is a duck (fact)
2. donald is a uncle of huey (fact)
3. if some duck is an uncle of someone else, that someone else is
his nephew (rule)
(in this simple example point 3 seems a bit redundant, but in the
actual
application the rules are more complex and thus less directly
'obvious'
in the set of premise facts alone)
I can use the logical clause to reproduce the facts in the explanation
(points 1 and 2), but it's that last part of the explanation (point 3)
that has me stumped.
Does anyone have any tips on how to achieve this? Any pointers will be
highly appreciated.
Best regards,
Jeen
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users
[EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
.
--------------------------------------------------------------------
---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------