<style type="text/css">-></style>
I hope the following provides the functionality you're looking for. Note that the word deftemplate has been modified to incorporate a memory slot that indicates that it has already been selected as a minimal-distance pair; this prevents these facts from participating in spurious future matches. (deftemplate word (slot page) (slot rowNumber) (slot type) (slot text) (slot control)) (assert (word (page 1) (rowNumber 1) (type ssn) (text "text1") (control FALSE)) (word (page 1) (rowNumber 2) (type ssn) (text "text2") (control FALSE)) (word (page 1) (rowNumber 3) (type ssn) (text "text3") (control FALSE)) (word (page 1) (rowNumber 9) (type ssn) (text "text4") (control FALSE)) (word (page 1) (rowNumber 10) (type ssn) (text "text5") (control FALSE)) ) (defrule find-lines-per-block-ssn ?word1 <- (word (page ?page) (rowNumber ?rowNumber1) (type ssn) (text ?text1) (control FALSE)) ?word2 <- (word (page ?page) (rowNumber ?rowNumber2&~?rowNumber1&:(< ?rowNumber1 ?rowNumber2)) (type ssn) (text ?text2) (control FALSE)) (not (word (page ?page) (rowNumber ?rowNumberVar&~rowNumber1&~rowNumber2&:(and (> ?rowNumberVar ?rowNumber1) (< ?rowNumberVar ?rowNumber2) (< (abs (- ?rowNumberVar ?rowNumber1)) (abs (- ?rowNumber2 ?rowNumber1))))))) => (modify ?word1 (control TRUE)) (modify ?word2 (control TRUE)) (printout t "Cluster: " ?rowNumber1 crlf) ) (run) Cluster: 9 Cluster: 2 2 Win Carus I would like find ?word1 and ?word2 such that the absolute value of ?rowNumber1 minus?rowNumber2 is the minimum number and ?word1 is not equal to ?word2 rowNumber are integers, 1, 2, 3.... I have verified that there is a single minimum. I have tried (defrule find-lines-per-block-ssn ?word1 ?word2 ?rowNumber1 ?rowNumber2)) (type ssn) (text ?text2) ) (not (word (page ?page) (rowNumber ?rowNumberVar&:( ) => ; do something ) This rule never fired. I tried (defrule find-lines-per-block-ssn ?word1 ?word2 (not (word (page ?page) (rowNumber ?rowNumberVar&:( ) => ; do someting ) This fired but ?word1 equals ?word2. Thanks Bob