Hi Esteban,<div>thank you for the response.</div><div>You are assuming i have a property named &#39;b&#39; that returns fact child &#39;B&#39;.</div><div>This is not so common in tree structures, also, in my sample i forgot to say that element &#39;B&#39; might not necessariliy be a direct child of &#39;A&#39;. Generally speking, i would like to refer to a descendant node of &#39;A&#39;, this is why i mentioned &#39;descendant-of&#39; in my sample.</div>
<div>Also, my sample was misleading because of the &#39;id&#39; attribute, it should have been like this, supposing to map the tag name with a &#39;name&#39; property:</div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); "><div class="im">
<div style="color: rgb(80, 0, 80); "><div><br></div><div>rule &quot;A requires B&quot;</div><div><span style="white-space: pre; ">        </span>when</div></div><div class="im"><div><span style="white-space: pre; ">                </span>$fact1: NodeFact(name == &quot;A&quot;, selected == true)</div>
</div><div><span style="white-space: pre; ">                </span>$fact2: NodeFact(name == &quot;B&quot;, selected == false, this DESCENDANT-OF $fact1 )</div><div class="im"><div style="color: rgb(80, 0, 80); "></div></div><div><span style="white-space: pre; ">        </span>then</div>
</div><div class="im"><div style="color: rgb(80, 0, 80); "><div><span style="white-space: pre; ">                </span>$fact2.setSelected(true);</div><div>end</div><div><br></div></div></div></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><div>
<span class="Apple-style-span" style="border-collapse: separate; font-family: arial; font-size: small; ">The rule could also be reversed like this, holding to the same concept:</span></div></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); "><div class="im">
<div style="color: rgb(80, 0, 80); "><div>rule &quot;A requires B&quot;</div><div><span style="white-space: pre; ">        </span>when</div></div><div><span style="white-space: pre; ">                </span>$fact2: NodeFact(name == &quot;B&quot;, selected == false )</div>
<div class="im"><div style="color: rgb(80, 0, 80); "></div></div><div><span style="white-space: pre; ">                </span>$fact1: NodeFact(name == &quot;A&quot;, selected == true, this ANCESTOR-OF $fact2)</div></div><div><span style="white-space: pre; ">        </span>then</div>
<div class="im"><div style="color: rgb(80, 0, 80); "><div><span style="white-space: pre; ">                </span>$fact2.setSelected(true);</div><div>end</div><div><br></div><div>In this case, if the tree is little &#39;deep&#39; (has few levels), it should be speedier, because it is supposed that the list of ancestors nodes  should be shorter than the list of the descendant nodes.</div>
<div>I&#39;m looking at a best practice to deal with tree structures in drools, this is actually my main concern.</div><div>Best regards </div></div></div></span></div><div><br></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(80, 0, 80); "><div class="im">
<div style="color: rgb(80, 0, 80); "><div><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: arial; font-size: small; ">2010/5/7 Esteban Aliverti <span dir="ltr">&lt;<a href="mailto:esteban.aliverti@gmail.com">esteban.aliverti@gmail.com</a>&gt;</span></span></div>
</div></div></span><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Ups sorry! I forgot to remove your part from the rule<div><br></div><div>It should be:<br>
<div><br></div><div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse"><div class="im"><div style="color:rgb(80, 0, 80)">

<div>rule &quot;A requires B&quot;</div><div><span style="white-space:pre">        </span>when</div></div><div><span style="white-space:pre">                </span>$fact1: NodeFact(id == &quot;A&quot;, selected == true, $b: b)</div></div><div>


<span style="white-space:pre">                </span>$fact2: NodeFact(this == $b, selected == false)</div><div class="im"><div style="color:rgb(80, 0, 80)"><div><span style="white-space:pre">        </span>then</div><div><span style="white-space:pre">                </span>$fact2.setSelected(true);</div>


<div>end</div><div><br></div><div>Best</div></div></div></span><div><div></div><div class="h5"><br><div class="gmail_quote">On Fri, May 7, 2010 at 2:14 PM, Esteban Aliverti <span dir="ltr">&lt;<a href="mailto:esteban.aliverti@gmail.com" target="_blank">esteban.aliverti@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hi,</div><div><br></div><div>Is this what you are looking for?</div><div><br></div><div><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse"><div>


<div>rule &quot;A requires B&quot;</div>
<div><span style="white-space:pre">        </span>when</div></div><div><span style="white-space:pre">                </span>$fact1: NodeFact(id == &quot;A&quot;, selected == true, $b: b)</div><div><span style="white-space:pre">                </span>$fact2: NodeFact(this == $b, selected == false,  this DESCENDANT-OF $fact1)</div>


<div>
<div><span style="white-space:pre">        </span>then</div><div><span style="white-space:pre">                </span>$fact2.setSelected(true);</div><div>end</div><div><br></div></div></span></div>Best,<br><br><div class="gmail_quote">2010/5/7 Giovanni Motta <span dir="ltr">&lt;<a href="mailto:mottagio@gmail.com" target="_blank">mottagio@gmail.com</a>&gt;</span><br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div>Hi all, i have a question concerning facts hierarchy, i&#39;m looking for some hint as i suppose the same problem could have been faced by someone on the list.
<div><br></div><div>I try to eplain with an example:</div><div><br></div><div>- Suppose to have a tree of facts, each object representing an UI widget.</div><div>   &lt;root&gt;</div><div>    &lt;A id=&quot;1&quot;&gt;</div>




<div>          &lt;B /&gt;</div><div>    &lt;/A&gt;</div><div><div>    &lt;A id=&quot;2&quot;&gt;</div><div>          &lt;B /&gt;</div><div>    &lt;/A&gt;</div><div>  &lt;/root&gt;</div><div><br></div><div>- The individual elements A(1), B, A(2), B are mapped to facts, that are inserted in a KnowledgeStatefulSession</div>




<div>- A rule exists that states that when an object A is selected, the B object is automatically selected</div><div>- An event occurs that causes selection of node A(1)</div><div><br></div><div>The expected result is, obviously, that only the B element that is descendant of A(1) must be automatically selected</div>




<div><br></div><div>I&#39;m trying a way to express the &#39;descendant&#39; relationship in LHS construct.</div><div>The rule will look like:</div><div><br></div><div><div>rule &quot;A requires B&quot;</div><div><span style="white-space:pre">        </span>when</div>




<div><span style="white-space:pre">                </span>$fact1: NodeFact(id == &quot;A&quot;, selected == true)</div><div><span style="white-space:pre">                </span>$fact2: NodeFact(id == &quot;B&quot;, selected == false,  this DESCENDANT-OF $fact1)</div>




<div><span style="white-space:pre">        </span>then</div><div><span style="white-space:pre">                </span>$fact2.setSelected(true);</div><div>end</div><div><br></div><div><br></div><div>
What is, in your opinion, the best way to handle this situation? What should replace the fake &quot;DESCENDANT-OF&quot; match?</div><div>Do i need to use a function that returns the list of descendant nodes of $fact1 and then match $fact2 against that? </div>




<div>Will this be fast when dealing with large trees?</div><div><br></div><div>Any suggestion will be appreciated, thank you.</div><div>Giovanni</div></div></div>
<br></div></div>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
<br></blockquote></div><br><br clear="all"><br>-- <br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><font color="#888888"><br>Esteban Aliverti<br>
</font></blockquote></div><br><br clear="all"><br></div></div>-- <br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><br>Esteban Aliverti<br>
</div></div>
<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>
<br></blockquote></div><br></div>