<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3314" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=851483614-21012009><FONT face=Arial
color=#0000ff size=2>I wonder whether a custom accumulate function could be used
to move your logic out of the object model?</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
<DIV><SPAN class=851483614-21012009></SPAN><FONT face=Arial><FONT
color=#0000ff><FONT size=2>N<SPAN class=851483614-21012009>ot that accumulate
was (probably) meant for this sort of function but the "init" method could
create the empty set and "accumulate" perform your iteration
below?</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=851483614-21012009></SPAN></FONT></FONT></FONT> </DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN
class=851483614-21012009>Just the musing of an idle
mind.</SPAN></FONT></FONT></FONT></DIV>
<DIV><BR></DIV>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] <B>On Behalf Of </B>David
Sinclair<BR><B>Sent:</B> 21 January 2009 14:28<BR><B>To:</B> Rules Users
List<BR><B>Subject:</B> Re: [rules-users] Reasoning over
hierarchies.<BR></FONT><BR></DIV>
<DIV></DIV>You could have something along the lines<BR><BR>class Person
{<BR> Person parent;<BR><BR>
Collection getAncestors()
{<BR>
Collection<Person> ancestors = new
HashSet<Person>();<BR>
<BR> Person
currentAncestor =
parent;<BR><BR>
while(currentAncestor != null)
{<BR>
ancestors.add(currentAncestor);<BR>
currentAncestor =
currentAncestor.getParent();<BR>
}<BR> }<BR>}<BR><BR>query isAncestor(String a, String
b)<BR> p: Person(name = a)<BR> c: Person(name = b,
ancestors contains p)<BR>end<BR><BR>that should do it<BR><BR>dave<BR><BR>
<DIV class=gmail_quote>On Wed, Jan 21, 2009 at 8:54 AM, Faron Dutton <SPAN
dir=ltr><<A
href="mailto:fgdutton@gmail.com">fgdutton@gmail.com</A>></SPAN> wrote:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">I
know this has probably been asked before but I cannot find any mention
of<BR>it. How does one reason over a transitive (recursive) relation in
Drools?<BR><BR>-----------------------------------------------------------<BR><BR>The
classic example from Prolog:<BR><BR>-- The relation parent(P,C) says that P
is a parent of C.<BR>parent(P,C).<BR><BR>-- The predicate ancestor(A,B)
implies that A is an ancestor<BR>-- of B if A is a parent of B or A is a
parent of C and C<BR>-- is an ancestor of B.<BR>ancestor(A,B) :-
parent(A,B).<BR>ancestor(A,B) :- parent(A,C), ancestor(C,B).<BR><BR>-- The
query ancestor(bob,frank) asks if bob is an ancestor<BR>-- of frank.<BR>?-
ancestor(bob,frank).<BR><BR>-----------------------------------------------------------<BR><BR>In
Drools, I can find the parent using<BR><BR>query isParent(String a, String
b)<BR> p: Person(name = a)<BR> c: Person(name = b,
parent = p)<BR>end<BR><BR>likewise, I can find the grandparent
using<BR><BR>query isGrandparent(String a, String b)<BR> g:
Person(name = a)<BR> p: Person(parent = g)<BR> c:
Person(name = b, parent = p)<BR>end<BR><BR>I am unable to formulate the
query
isAncestor.<BR><BR>_______________________________________________<BR>rules-users
mailing list<BR><A
href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</A><BR><A
href="https://lists.jboss.org/mailman/listinfo/rules-users"
target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR></BLOCKQUOTE></DIV><BR></BLOCKQUOTE></BODY></HTML>