[EMAIL PROTECTED] writes:
>
>
> I think Mark Nahabedian wrote:
> >
> > (deffunction test-equiv (?type ?thing1 ?thing2)
> > (bind ?e (run-query equivs-of-type ?type))
> > (while (?e hasMoreElements)
> > (bind ?elt (call ?e nextElement))
> > ;; The document isn't clear about why this is needed
>
> (An aside: the Jess 6 manual is better. Note that Jess 5 will be
> officially obsolescent as of Monday, when 6.0 final will be released.)
Thanks. I upgraded to 6.0b3 and made the few necessary alterations to
my application (all in the Java glue code which makes the initial fact
assertions). The documentation is greatly improved.
I'm still having two problems however.
The first is that the test for set membership in my function
test-equiv (code below) is always failing. Various objects in my
application are represented in Jess as generated atoms. The problem
might be because the variable $?set in the test-equiv function seems
to be bound to a set of a set of atoms (note extra level of
parentheses), rather than to a set of atoms.
The second problem is that I'm getting an exception in a call to "get"
but I don't know where that call is. It doesn't appear to be in my
code.
======================================================================
==> f-137 (MAIN::opposites segment-side side-27 side-28)
==> f-138 (MAIN::cp-circular (crosspoint "C")
(segment "cord-1[3]")
(segment-direction in)
(circular-direction cd-25)
(face face-21))
==> f-139 (MAIN::segment-face (face face-21)
(edge "cord-1[3]")
(edge-side side-27))
==> f-140 (MAIN::__query-trigger-equivs-of-type segment-side)
<== f-140 (MAIN::__query-trigger-equivs-of-type segment-side)
***** side-27 side-12 <External-Address:jess.Token>
0 name MAIN::__query-trigger-equivs-of-type
name didn't match
1 name MAIN::equiv
got name
set = ((side-8 side-12 side-11 side-7 side-20 side-19 side-16 side-15))
FALSE FALSE
***** side-27 side-12 <External-Address:jess.Token>
0 name MAIN::__query-trigger-equivs-of-type
name didn't match
1 name MAIN::equiv
got name
set = ((side-27)) <<<<====== membership test failing here
FALSE FALSE
***** side-27 side-12 <External-Address:jess.Token>
0 name MAIN::__query-trigger-equivs-of-type
name didn't match
1 name MAIN::equiv
got name
set = ((side-28))
FALSE FALSE
returning false
Jess exception: Jess reported an error in routine ValueVector.get
while executing rule LHS (Node2)
while executing rule LHS (TECT)
while executing (assert (MAIN::opposites circular-direction ?circ1 ?circ2)
(MAIN::opposites segment-side ?side1 ?side2)
(MAIN::cp-circular (crosspoint ?cp)
(segment ?seg-a)
(segment-direction in)
(circular-direction ?circ1)
(face ?face1))
(MAIN::segment-face (face ?face1)
(edge ?seg-a)
(edge-side ?side1))
(MAIN::cp-circular (crosspoint ?cp)
(segment ?seg-c)
(segment-direction in)
(circular-direction ?circ2)
(face ?face1))
(MAIN::segment-face (face ?face1)
(edge ?seg-c)
(edge-side ?side2)))
while executing defrule MAIN::faces-and-segments-at-crosspoint.
Message: Bad index 1 in call to get() on this vector:
(MAIN::__query-trigger-equivs-of-type segment-side).
C:\Projects\Knots\java>
======================================================================
;;; -*- Mode:Lisp -*-
;;; Use sets to keep track of equivalence.
(deftemplate equiv
(slot type)
(multislot set))
(deffunction make-equiv (?type ?item)
;; Create an equivalence set of the specified type for the object.
;; These are merged together as the KB discoveres equivalences.
(assert (equiv (type ?type)
(set (create$ ?item)))))
(defrule equiv-equiv-merge
?fact1 <- (equiv (type ?type) (set $?set1))
?fact2 <- (equiv (type ?type) (set $?set2))
(test (not (eq ?fact1 ?fact2)))
(test (intersection$ $?set1 $?set2))
=>
(assert (equiv (type ?type)
(set (union$ $?set1 $?set2))))
(retract ?fact1)
(retract ?fact2))
(defquery equivs-of-type
"Returns an enumeration of equiv facts of the specified type."
(declare (variables ?type))
(equiv (type ?type) (set $?set)))
(deffunction test-equiv (?type ?thing1 ?thing2)
(bind ?e (run-query equivs-of-type ?type))
(while (?e hasNext) ; hasMoreElements
(bind ?token (call ?e next)) ; nextElement
(printout t crlf "***** " ?thing1 " "?thing2 " " ?token crlf)
(bind ?index 0)
(while (< ?index (call ?token size))
(bind ?fact (call ?token fact ?index))
(printout t crlf ?index " ")
(printout t " name " (call ?fact getName) crlf)
(if (eq (call ?fact getName) "MAIN::equiv")
then
(progn
(printout t " got name" crlf)
(bind $?set (fact-slot-value ?fact set))
(printout t "set = " $?set crlf)
(printout t (member$ ?thing1 $?set)
" " (member$ ?thing2 $?set) crlf)
(if (and (member$ ?thing1 $?set)
(member$ ?thing2 $?set))
then
(printouot t " equivalent" crlf)
(return ?fact)))
else
(printout t " name didn't match" crlf))
(bind ?index (+ ?index 1))))
(printout t " returning false" crlf)
(return FALSE))
(deffunction assert-equiv (?type ?thing1 ?thing2)
(assert (equiv (type ?type)
(set (create$ ?thing1 ?thing2)))))
;;; How do we do opposites?
; (opposites ?type ?op-thing1 ?op-thing2)
; (test (or (and (test-equiv ?type ?thing1 ?op-thing1)
; (test-equiv ?type ?thing2 ?op-thing2))
; (and (test-equiv ?type ?thing2 ?op-thing1)
; (test-equiv ?type ?thing1 ?op-thing2))))
(defrule cp-segment-direction-opposite-opposite-same
?fact1 <- (opposites ?type ?thing1 ?thing2)
?fact2 <- (opposites ?type ?thing2 ?thing3)
(test (not (eq ?fact1 ?fact2)))
=>
;; This assertion will trigger the equiv-equiv-merge rule which will
;; result in a single fact describing the equivalent things
(assert-equiv ?type ?thing1 ?thing3))
======================================================================
import jess.*;
import java.io.PrintWriter;
class JessGlue {
static private Rete rete;
static public void init_rete () {
try {
rete = new Rete();
System.out.println("made Rete");
Value v;
v = rete.executeCommand("(batch scriptlib.clp)");
System.out.println("Loaded scriptlib: " + v);
v = rete.executeCommand("(batch knot-perimeter.clp)");
System.out.println("Loaded knot-perimeter.clp: " + v);
}
catch (JessException e) {
System.err.println("Jess exception: " + e);
System.exit(0);
}
System.out.println("Jess rete initialized");
}
static public void assert_endpoint (KnotEndPoint ep) {
try {
Fact f = new Fact("end-point", rete);
f.setSlotValue("edge", new Value(ep.end_point_segment().name(),
RU.STRING));
f.setSlotValue("node", new Value(ep.name(), RU.STRING));
rete.assertFact(f);
}
catch (JessException e) {
System.err.println("Jess exception: " + e);
System.exit(0);
}
}
static public void assert_crosspoint (KnotCrosspoint cp) {
try {
Fact f = new Fact("crosspoint", rete);
KnotCrosspointLink link1 = cp.first_link();
KnotCrosspointLink link2 = cp.other_link(link1);
f.setSlotValue("crosspoint", new Value(cp.name(), RU.STRING));
f.setSlotValue("link1-in",
new Value(link1.in_segment().name(), RU.STRING));
f.setSlotValue("link1-out",
new Value(link1.out_segment().name(), RU.STRING));
f.setSlotValue("link2-in",
new Value(link2.in_segment().name(), RU.STRING));
f.setSlotValue("link2-out",
new Value(link2.out_segment().name(), RU.STRING));
rete.assertFact(f);
}
catch (JessException e) {
System.err.println("Jess exception: " + e);
System.exit(0);
}
}
static public void run () {
try {
rete.run();
}
catch (JessException e) {
System.err.println("Jess exception: " + e);
System.exit(0);
}
}
static public void debug_dump () {
// System.out.println(rete.ppFacts());
try {
rete.ppFacts(new PrintWriter(System.out));
}
catch (Exception e) {
System.err.println("Exception: " + e);
System.exit(0);
}
}
}
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------