(defun GenerateRuleMatchNB (ruleset avoid matcho global fmod) (if (> (xindex-n avoid) 0) (setf matcho (cross-index (table-copy (xindex-table matcho) (append (table-egs (xindex-table matcho)) (table-egs (xindex-table avoid))))))) (let ((counts (list)) (match (cross-index (table-copy (xindex-table matcho))))) (maphash #'(lambda (k v) (setf (gethash k (xindex-counts match)) (counted-n v))) (xindex-counts match)) ;Do I want this line? ;(maphash #'(lambda (k v) (if (not (eql (gethash k (xindex-counts match)) nil)) (setf (gethash k (xindex-counts match)) (- (gethash k (xindex-counts match)) (counted-n v))))) (xindex-counts avoid)) (maphash #'(lambda (k v) (if (/= (second k) (xindex-classi match)) (push (cons k (/ v (gethash (list (second k) (third k)) (xindex-uniques match)))) counts))) (xindex-counts match)) (setf counts (LimitChoices ruleset counts)) (setf counts (stable-sort counts '> :key #'(lambda (x) (cdr x)))) ;(print counts) (if (= (length counts) 0) (make-RDRule :fn #'(lambda (x) nil) :class 'Unknown :comment (list 'Bottom) :parent ruleset) (progn (setf counts (car (first counts))) (make-RDRule :fn (MakePredicate (second counts) (third counts)) :class (first counts) :comment counts :parent ruleset))))) (defun LimitChoices (ruleset counts) (if (and (not (null (RDRule-parent ruleset))) (not (eq ruleset (RDRule-true (RDRule-parent ruleset))))) (while (and (not (null ruleset)) (listp (RDRule-comment ruleset))) (if (listp (RDRule-comment ruleset)) (setf counts (remove-if #'(lambda (x) (and (equal (second (car x)) (second (RDRule-comment ruleset))) (equal (third (car x)) (third (RDRule-comment ruleset))))) counts))) (setf ruleset (RDRule-parent ruleset))) (let ((tcounts nil)) (mapcar #'(lambda (x) (let ((comment (car x)) (footer (rest x))) (print comment) (if (equal nil (assoc (list (second comment) (third comment)) tcounts :test #'equal)) (push (cons (list (second comment) (third comment)) footer) tcounts) (rplacd (assoc (list (second comment) (third comment)) tcounts :test #'equal) (cons (list (second comment) (third comment)) footer))))) counts) (print "---------------") (print tcounts) (let ((temp nil)) (mapcar #'(lambda (x) (let ((comment (car x)) (footer (rest x))) (print (format nil "~A=~A" comment (assoc (list (second comment) (third comment)) tcounts))) (if (equal footer (cdr (assoc (list (second comment) (third comment)) tcounts )));:test #'equal))) (push x temp)))) counts) (print temp) (setf tcounts nil) (mapcar #'(lambda (x) (let ((comment (car x)) (footer (rest x))) (if (or (not (equal (first comment) (first (RDRule-comment ruleset)))) t) (push x tcounts)))) temp) (setf counts tcounts)))) counts)