Hi Esteban,<div>thank you for the response.</div><div>You are assuming i have a property named 'b' that returns fact child 'B'.</div><div>This is not so common in tree structures, also, in my sample i forgot to say that element 'B' might not necessariliy be a direct child of 'A'. Generally speking, i would like to refer to a descendant node of 'A', this is why i mentioned 'descendant-of' in my sample.</div>
<div>Also, my sample was misleading because of the 'id' attribute, it should have been like this, supposing to map the tag name with a 'name' 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 "A requires B"</div><div><span style="white-space: pre; ">        </span>when</div></div><div class="im"><div><span style="white-space: pre; ">                </span>$fact1: NodeFact(name == "A", selected == true)</div>
</div><div><span style="white-space: pre; ">                </span>$fact2: NodeFact(name == "B", 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 "A requires B"</div><div><span style="white-space: pre; ">        </span>when</div></div><div><span style="white-space: pre; ">                </span>$fact2: NodeFact(name == "B", 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 == "A", 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 'deep' (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'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"><<a href="mailto:esteban.aliverti@gmail.com">esteban.aliverti@gmail.com</a>></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 "A requires B"</div><div><span style="white-space:pre">        </span>when</div></div><div><span style="white-space:pre">                </span>$fact1: NodeFact(id == "A", 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"><<a href="mailto:esteban.aliverti@gmail.com" target="_blank">esteban.aliverti@gmail.com</a>></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 "A requires B"</div>
<div><span style="white-space:pre">        </span>when</div></div><div><span style="white-space:pre">                </span>$fact1: NodeFact(id == "A", 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"><<a href="mailto:mottagio@gmail.com" target="_blank">mottagio@gmail.com</a>></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'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> <root></div><div> <A id="1"></div>
<div> <B /></div><div> </A></div><div><div> <A id="2"></div><div> <B /></div><div> </A></div><div> </root></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'm trying a way to express the 'descendant' relationship in LHS construct.</div><div>The rule will look like:</div><div><br></div><div><div>rule "A requires B"</div><div><span style="white-space:pre">        </span>when</div>
<div><span style="white-space:pre">                </span>$fact1: NodeFact(id == "A", selected == true)</div><div><span style="white-space:pre">                </span>$fact2: NodeFact(id == "B", 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 "DESCENDANT-OF" 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>