On 9 March 2011 04:59, Simon Chen <span dir="ltr"><<a href="mailto:simonchennj@gmail.com" target="_blank">simonchennj@gmail.com</a>></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>
"no-loop true", 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 "no-loop true" in this case helps to make the<br>
result correct. But, do you see any scenarios where "no-loop" 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's necessary to avoid duplications of Reachable. You can't add a "not" CE to<br>
block this, but it'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 ) && 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>