Jess is capable of reflection on rules and other objects. But reflection
delivers formal/structural information but no semantic insights.
Are you prepared to add meta-facts that would, for instance, define the
meaning of (uncleOf a b)? If so, it would be possible to produce the
reasoning
by investigating the Activation object, from within an JessEvent handler.
This gives you the Rule object and the actual facts that participate.
handle( JessEvent event ){
Activation act = (Activation)event.getObject();
Defrule rule = act.getRule();
Token token = act.getToken();
for( int i = 0; i < token.size(); i++ ){
Fact f = token.fact( i );
...
}
If you map the rule name to the set of "interesting" fact/slot pairs you
could
produce a suitable piece of text.
kr
Wolfgang
On Wed, Sep 10, 2008 at 11:24 AM, Broekstra, Jeen <[EMAIL PROTECTED]>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]
> --------------------------------------------------------------------
>
>