On 9 March 2011 04:59, Simon Chen <span dir="ltr">&lt;<a href="mailto:simonchennj@gmail.com" target="_blank">simonchennj@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Hi Wolfgang,<br>
<br>
First, your rules work...<br>
<br>
But for the second rule, I replaced the first Reachable() in the when<br>
clause to Link(), and the result is still correct. Only if I remove<br>
&quot;no-loop true&quot;, the issue I had appeared.<br></blockquote><div><br>My statement about avoiding a mix of given and derived facts was<br>definitely exaggerating matters. But the representation of Link vs.<br>Reachable merits some consideration.<br>
 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
So, I understand how &quot;no-loop true&quot; in this case helps to make the<br>
result correct. But, do you see any scenarios where &quot;no-loop&quot; can<br>
cause incorrect results? For example, not enough number of recursions?<br></blockquote><div><br>No-loop is almost never satisfactory.<br><br>It&#39;s necessary to avoid duplications of Reachable. You can&#39;t add a &quot;not&quot; CE to<br>
block this, but it&#39;s possible to configure against the insertion of equal facts.<br>For this, equals() and hashCode() must be implemented properly, and the <br>AssertBehaviorOption.EQUALITY must be set.<br><br>I have found this to work quite well:<br>
<br>public class Reachable {<br>  private String src;<br>  private String tgt;<br>  //...<br>    public boolean equals(Object obj) {<br>    if (this == obj) return true;<br>    if( ! (obj instanceof Reachable)) return false;<br>
    Reachable other = (Reachable) obj;<br>    return other.src.equals( src ) &amp;&amp;  other.tgt.equals( tgt );<br>  }<br>}<br><br>public class Link extends Reachable {<br>  public Link( String src, String tgt ){<br>    super(src, tgt);<br>
  }<br>}<br><br>Notice that this subclassing avoids the creation of Reachable for each Link. And I still think that computing the closure should be done by using Reachable only. Note the absence of no-loop!<br><br>rule deriveReachReach<br>
when<br>    Reachable( $src: src, $mid: tgt )<br>    Reachable( src == $mid, $tgt: tgt != $src )<br>then<br>    insertLogical( new Reachable( $src, $tgt ));<br>end<br><br><br>  kbConfig.setOption( AssertBehaviorOption.EQUALITY );   // identical and equal not inserted<br>
  kBase = KnowledgeBaseFactory.newKnowledgeBase( kbConfig );<br><br>Cheers<br>-W<br><br><br><br><br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
Thanks.<br>
-Simon<br>
<br></blockquote></div><br>