From e9270445eaef612cf34fc247b45eae885a81be19 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Sun, 10 Sep 2006 17:04:44 +0000 Subject: [PATCH] r11125: updates --- debian/changelog | 4 ++-- sql-classes.lisp | 62 +++++++++++++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/debian/changelog b/debian/changelog index 57ff927..dce8a56 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,8 @@ -cl-umlisp (4.2.0-1) unstable; urgency=low +cl-umlisp (2006ac-1) unstable; urgency=low * Add support for UMLS 2006AC - -- Kevin M. Rosenberg Sun, 3 Sep 2006 23:38:27 -0600 + -- Kevin M. Rosenberg Sun, 10 Sep 2006 08:30:57 -0600 cl-umlisp (4.1.0-2) unstable; urgency=low diff --git a/sql-classes.lisp b/sql-classes.lisp index 2c8c93e..2831def 100644 --- a/sql-classes.lisp +++ b/sql-classes.lisp @@ -189,11 +189,15 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS" (ensure-cui-integer cui) (unless cui (return-from find-ucon-cui nil)) - (let ((tuple (car (mutex-sql-query "SELECT kcuilrl,str FROM MRCONSO WHERE CUI=~D AND KPFENG=1 AND SRL<=~D" - cui srl)))) + (let ((tuple (car (mutex-sql-query + (format nil + "SELECT kcuilrl,str FROM MRCONSO WHERE CUI=~D AND KPFENG=1~A" + cui (if srl (format nil " AND SRL<=~D" srl) "")))))) (unless tuple - (setq tuple (car (mutex-sql-query "SELECT kcuilrl,str FROM MRCONSO WHERE CUI=~D AND SRL<=~D" - cui srl)))) + (setq tuple (car (mutex-sql-query + (format nil + "SELECT kcuilrl,str FROM MRCONSO WHERE CUI=~D" + cui (if srl (format nil " AND SRL<=~D" srl) nil)))))) (unless tuple (return-from find-ucon-cui nil)) (make-instance 'ucon :cui cui :pfstr (second tuple) @@ -211,11 +215,11 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS" (ensure-cui-integer cui) (or (caar (mutex-sql-query - (format nil "SELECT str FROM MRCONSO WHERE CUI=~D AND KPFENG=1 AND SLR<=~D" - cui srl))) + (format nil "SELECT DISTINCT str FROM MRCONSO WHERE CUI=~D AND KPFENG=1~A LIMIT 1" + cui (if srl (format nil " AND SRL<=~D" srl) "")))) (caar (mutex-sql-query - (format nil "SELECT str FROM MRCONSO WHERE CUI=~D AND SLR<=~D" - cui srl))))) + (format nil "SELECT DISTINCT str FROM MRCONSO WHERE CUI=~D~A LIMIT 1" + cui (if srl (format nil " AND SRL<=~D" srl) "")))))) (defun find-ucon-lui (lui &key (srl *current-srl*)) "Find list of ucon for lui" @@ -226,11 +230,11 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS" :lrl (ensure-integer kcuilrl))) (unless lui (return-from find-ucon-lui nil)) - (let ((tuple (car (mutex-sql-query "SELECT cui,kcuilrl,str FROM MRCONSO WHERE LUI=~D AND KPFENG=1 AND SRL<=~D" - lui srl)))) + (let ((tuple (car (mutex-sql-query "SELECT cui,kcuilrl,str FROM MRCONSO WHERE LUI=~D AND KPFENG=1~A ORDER BY kcuilrl ASC LIMIT 1" + lui (if srl (format nil " AND SRL<=~D" srl) ""))))) (unless tuple - (setq tuple (car (mutex-sql-query "SELECT cui,kcuilrl,str FROM MRCONSO WHERE LUI=~D AND SRL<=~D" - lui srl)))) + (setq tuple (car (mutex-sql-query "SELECT cui,kcuilrl,str FROM MRCONSO WHERE LUI=~D~A ORDER BY kcuilrl ASC LIMIT 1" + lui (if srl (format nil " AND SRL<=~D" srl) ""))))) (unless tuple (return-from find-ucon-lui nil)) (make-instance 'ucon :cui (first tuple) :pfstr (third tuple) @@ -720,33 +724,43 @@ 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 - only-exact-if-match) + only-exact-if-match limit) (let ((uobjs '())) (dolist (word (delimited-string-to-list str #\space)) (setq uobjs (append uobjs (funcall obj-lookup-fun word :srl srl)))) (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)))) + (let ((len (length sorted))) + (cond + ((zerop len) + (return-from find-uobj-multiword nil)) + ((and only-exact-if-match (multiword-match str (pfstr (first sorted)))) + (first sorted)) + (limit + (if (and (plusp limit) (> len limit)) + (subseq sorted 0 limit) + limit)) + (t + sorted)))))) (defun find-ucon-multiword (str &key (srl *current-srl*) - (only-exact-if-match t)) + (only-exact-if-match t) + limit) (find-uobj-multiword str #'find-ucon-word #'sort-score-pfstr-str - #'cui srl only-exact-if-match)) + #'cui srl only-exact-if-match limit)) (defun find-uterm-multiword (str &key (srl *current-srl*) - (only-exact-if-match t)) + (only-exact-if-match t) + limit) (find-uobj-multiword str #'find-uterm-word #'sort-score-pfstr-str - #'lui srl only-exact-if-match)) + #'lui srl only-exact-if-match limit)) (defun find-ustr-multiword (str &key (srl *current-srl*) - (only-exact-if-match t)) + (only-exact-if-match t) + limit) (find-uobj-multiword str #'find-ustr-word #'sort-score-ustr-str - #'sui srl only-exact-if-match)) + #'sui srl only-exact-if-match limit)) (defun sort-score-pfstr-str (str uobjs) "Return list of sorted and scored ucons. Score by match of str to ucon-pfstr" -- 2.34.1