The following rule is more or less what you are looking for:
(defrule ancestor-rule
(or (inheritsFrom ?y ?x)
(and (inheritsFrom ?z ?x) (ancestor ?z ?y) )
)
=>
(assert (ancestor ?x ?y) )
)
This rule captures the spirit of the Prolog rule and
can be used in a forward manner
but the rule will add all possible ancestors to the fact base.
For a small fact base, this may be acceptable.
However, as Ernest mentioned, adding backward chaining
to drive such a rule will allow you to determine very efficiently
whether or not "a" is an ancestor of "b"
(and this is how Prolog would solve the problem).
David Scuse
----- Original Message -----
From: "Ernest Friedman-Hill" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, February 27, 2007 6:01 PM
Subject: Re: JESS: equivalent rule of a prolog rule?
> On Feb 27, 2007, at 1:54 PM, fan yang wrote:
>
> >
> > The following Prolog rules will identify direct or indirect
> > inheritance:
> > ancestor (X, Y) :- inheritsFrom (Y, X).
> > ancestor (X, Y) :- inheritsFrom (Z, X), ancestor (Z, Y).
> >
> > I want to do the exact same thing in Jess, but I don't know how to do
> > it. For my understanding, first, Jess rule dosen't support parameter
> > in its rule definition, seceond ancestor rule wokrs in recursive
> > manner, from jess manual, i didn't find recursive support, would you
> > please help me through it.
> >
>
> Jess is primarily a forward-chaining system, with some support for a
> form of backward chaining. Prolog is a backward-chaining system. So
> the way that rules are written -- and even the definition of what a
> rule is -- is rather different.
>
> Rete-based forward chaining systems like Jess operate under the
> "closed world assumption", meaning that the implicit assumption is
> made that all true statements are represented by a "fact" in the
> working memory. Jess's backward chaining can be used to loosen this
> restriction in the sense that it can create new facts based solely on
> the logical requirements of existing rules. Look, for example, at the
> "factorial backward chaining" example in the manual. To implement
> something like the rules above, you'd have a rule to express the
> ancestor relationsip, and then a backward chaining rule to find
> intermediate steps and assert facts into working memory to represent
> them.
>
> ---------------------------------------------------------
> Ernest Friedman-Hill
> Advanced Software Research Phone: (925) 294-2154
> Sandia National Labs FAX: (925) 294-2234
> PO Box 969, MS 9012 [EMAIL PROTECTED]
> 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]
> --------------------------------------------------------------------
>
--------------------------------------------------------------------
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]
--------------------------------------------------------------------