X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sql-classes.lisp;h=3af923d2b1e7c1def2e54282f4cf0c06411275de;hb=16330812b9a0fef2394d2a45889ab04bec5d3859;hp=bdaa025aa50a513ceccda298955565fceb78db6d;hpb=39a479e5f9a18b8e9211cac3e8391ee29e54c3ee;p=umlisp.git diff --git a/sql-classes.lisp b/sql-classes.lisp index bdaa025..3af923d 100644 --- a/sql-classes.lisp +++ b/sql-classes.lisp @@ -7,7 +7,7 @@ ;;;; Author: Kevin M. Rosenberg ;;;; Date Started: Apr 2000 ;;;; -;;;; $Id: sql-classes.lisp,v 1.87 2003/06/24 08:49:09 kevin Exp $ +;;;; $Id: sql-classes.lisp,v 1.88 2003/07/21 00:53:27 kevin Exp $ ;;;; ;;;; This file, part of UMLisp, is ;;;; Copyright (c) 2000-2003 by Kevin M. Rosenberg, M.D. @@ -595,20 +595,34 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS" ;;; Multiword lookup and score functions -(defun find-uobj-multiword (str obj-lookup-fun sort-fun key srl) +(defun find-uobj-multiword (str obj-lookup-fun sort-fun key srl + only-exact-if-match) (let ((uobjs '())) (dolist (word (delimited-string-to-list str #\space)) (setq uobjs (append uobjs (funcall obj-lookup-fun word :srl srl)))) - (funcall sort-fun str (delete-duplicates uobjs :test #'= :key key)))) + (let ((sorted + (funcall sort-fun str + (delete-duplicates uobjs :test #'= :key key)))) + (if (and (plusp (length sorted)) + only-exact-if-match + (multiword-match str (pfstr (first sorted)))) + (first sorted) + sorted)))) -(defun find-ucon-multiword (str &key (srl *current-srl*)) - (find-uobj-multiword str #'find-ucon-word #'sort-score-pfstr-str #'cui srl)) - -(defun find-uterm-multiword (str &key (srl *current-srl*)) - (find-uobj-multiword str #'find-uterm-word #'sort-score-pfstr-str #'lui srl)) - -(defun find-ustr-multiword (str &key (srl *current-srl*)) - (find-uobj-multiword str #'find-ustr-word #'sort-score-ustr-str #'sui srl)) +(defun find-ucon-multiword (str &key (srl *current-srl*) + (only-exact-if-match t)) + (find-uobj-multiword str #'find-ucon-word #'sort-score-pfstr-str + #'cui srl only-exact-if-match)) + +(defun find-uterm-multiword (str &key (srl *current-srl*) + (only-exact-if-match t)) + (find-uobj-multiword str #'find-uterm-word #'sort-score-pfstr-str + #'lui srl only-exact-if-match)) + +(defun find-ustr-multiword (str &key (srl *current-srl*) + (only-exact-if-match t)) + (find-uobj-multiword str #'find-ustr-word #'sort-score-ustr-str + #'sui srl only-exact-if-match)) (defun sort-score-pfstr-str (str uobjs) "Return list of sorted and scored ucons. Score by match of str to ucon-pfstr" @@ -626,39 +640,6 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS" scored)) (mapcar #'car (sort scored #'> :key #'cadr)))) -(defun score-multiword-match (s1 s2) - "Score a match between two strings with s1 being reference string" - (let* ((word-list-1 (delimited-string-to-list s1 #\space)) - (word-list-2 (delimited-string-to-list s2 #\space)) - (n1 (length word-list-1)) - (n2 (length word-list-2)) - (unmatched n1) - (score 0) - (nlong 0) - (nshort 0) - short-list long-list) - (declare (fixnum n1 n2 nshort nlong score unmatched)) - (if (> n1 n2) - (progn - (setq nlong n1) - (setq nshort n2) - (setq long-list word-list-1) - (setq short-list word-list-2)) - (progn - (setq nlong n2) - (setq nshort n1) - (setq long-list word-list-2) - (setq short-list word-list-1))) - (decf score (- nlong nshort)) ;; reduce score for extra words - (dotimes (iword nshort) - (declare (fixnum iword)) - (kmrcl:aif (position (nth iword short-list) long-list :test #'string-equal) - (progn - (incf score (- 10 (abs (- kmrcl::it iword)))) - (decf unmatched)))) - (decf score (* 2 unmatched)) - score)) - ;;; LEX SQL functions