X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sql-classes.lisp;h=2fc138bbe8aa6dcfcfe896e9b59905128dd69d97;hb=5a80d916816131a1d56a60790cd1e4b5e9c88810;hp=920ee8df4c4111fa9737b54ab5128903b3afab35;hpb=f513e7b50135115f3c56b840c2cb0d1c9c8ffa82;p=umlisp.git diff --git a/sql-classes.lisp b/sql-classes.lisp index 920ee8d..2fc138b 100644 --- a/sql-classes.lisp +++ b/sql-classes.lisp @@ -1,8 +1,24 @@ -;;; $Id: sql-classes.lisp,v 1.2 2002/10/09 00:34:47 kevin Exp $ - +;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: umlisp -*- +;;;; ************************************************************************* +;;;; FILE IDENTIFICATION +;;;; +;;;; Name: sql-classes.lisp +;;;; Purpose: Routines for reading UMLS objects from SQL database +;;;; Programmer: Kevin M. Rosenberg +;;;; Date Started: Apr 2000 +;;;; +;;;; $Id: sql-classes.lisp,v 1.4 2002/10/14 09:25:20 kevin Exp $ +;;;; +;;;; This file, part of UMLisp, is +;;;; Copyright (c) 2000-2002 by Kevin M. Rosenberg, M.D. +;;;; +;;;; UMLisp users are granted the rights to distribute and use this software +;;;; as governed by the terms of the GNU General Public License. +;;;; ************************************************************************* + (in-package :umlisp) +(declaim (optimize (speed 3) (safety 1) (compilation-speed 0) (debug 3))) -(declaim (optimize (speed 3) (safety 1))) (defvar *current-srl* nil) (defun current-srl () @@ -53,10 +69,10 @@ ;;; Lookup functions for uterms,ustr in ucons (defun find-uterm-in-ucon (ucon lui) - (find lui (s#term ucon) :key #'uterm-lui :test 'equal)) + (find lui (s#term ucon) :key #'lui :test 'equal)) (defun find-ustr-in-uterm (uterm sui) - (find sui (s#str uterm) :key #'ustr-sui :test 'equal)) + (find sui (s#str uterm) :key #'sui :test 'equal)) (defun find-ustr-in-ucon (ucon sui) (let ((found-ustr nil)) @@ -239,7 +255,7 @@ (defun find-ucon-rel-cui2 (cui2 &key (srl *current-srl*)) (mapcar - #'(lambda (cui) (find-ucon-cui cui :key srl)) + #'(lambda (cui) (find-ucon-cui cui :srl srl)) (remove-duplicates (mapcar #'cui1 (find-urel-cui2 cui2 :srl srl))))) (defun find-ucoc-cui (cui &key (srl *current-srl*)) @@ -284,7 +300,7 @@ (defun find-ucon-coc-cui2 (cui2 &key (srl *current-srl*)) "List of ucon with co-occurance cui2" (mapcar - #'(lambda (cui) (find-ucon-cui cui :key srl)) + #'(lambda (cui) (find-ucon-cui cui :srl srl)) (remove-duplicates (mapcar #'cui1 (find-ucoc-cui2 cui2 :srl srl))))) (defun find-ulo-cui (cui &key (srl *current-srl*)) @@ -545,18 +561,6 @@ (push (find-usty-tui (nth 0 tuple)) ustys)) (nreverse ustys))) -(defun find-usty_freq-all () - (let ((usty_freqs '())) - (dolist (tuple (mutex-sql-query "select distinct TUI from MRSTY")) - (let* ((tui (car tuple)) - (freq (ensure-integer - (caar (mutex-sql-query - (format nil "select count(*) from MRSTY where TUI=~a" tui)))))) - (push (make-instance 'usty_freq :usty (find-usty-tui tui) :freq freq) usty_freqs))) - (sort usty_freqs #'> :key #'usty_freq-freq))) - - - (defun find-cui-max () (let ((cui (caar (mutex-sql-query "select max(CUI) from MRCON")))) @@ -638,19 +642,6 @@ (setq ucons (append ucons (find-ucon-word word :srl srl)))) (sort-score-ucon-str str (delete-duplicates ucons :test #'eql :key #'cui)))) -(defun find-ucon-normalized-multiword (str &key (srl *current-srl*)) - "Return sorted list of ucon's that match a multiword string" - (let* ((words (delimited-string-to-list str #\space)) - (ucons '()) - (nwords '())) - (dolist (word words) - (let ((nws (lvg:process-terms word))) - (dolist (nword nws) - (push nword nwords)))) - (dolist (word nwords) - (setq ucons (append ucons (find-ucon-word word :srl srl)))) - (sort-score-ucon-str str (delete-duplicates ucons :test #'eql :key #'cui)))) - (defun find-ustr-multiword (str &key (srl *current-srl*)) "Return sorted list of ustr's that match a multiword string" (let* ((words (delimited-string-to-list str #\space)) @@ -658,35 +649,6 @@ (dolist (word words) (setq ustrs (append ustrs (find-ustr-word word :srl srl)))) (sort-score-ustr-str str (delete-duplicates ustrs :test #'eql :key #'cui)))) - -(defun find-ustr-normalized-multiword (str &key (srl *current-srl*)) - "Return sorted list of ustr's that match a multiword string" - (let* ((words (delimited-string-to-list str #\space)) - (ustrs '()) - (nwords '())) - (dolist (word words) - (let ((nws (lvg:process-terms word))) - (dolist (nword nws) - (push nword nwords)))) - (dolist (word nwords) - (setq ustrs (append ustrs (find-ustr-word word :srl srl)))) - (sort-score-ustr-str str (delete-duplicates ustrs :test #'eql :key #'ustr-cui)))) - -(defun a (str) - (find-normalized-matches-for-str str #'find-ustr-normalized-word #'ustr-sui)) - -(defun find-normalized-matches-for-str (str lookup-func key-func) - "Return list of objects that normalize match for words in string, -eliminate duplicates." - (let ((objs '()) - (nwords '())) - (dolist (word (delimited-string-to-list str #\space)) - (dolist (nword (lvg:process-terms word)) - (unless (member nword nwords :test #'string-equal) - (push nword nwords)))) - (dolist (nw nwords) - (setq objs (append objs (funcall lookup-func nw)))) - (delete-duplicates objs :key key-func :test #'eql))) (defun sort-score-ucon-str (str ucons) "Return list of sorted and scored ucons. Score by match of str to ucon-pfstr"