r3016: *** empty log message ***
[umlisp.git] / sql-classes.lisp
index 920ee8df4c4111fa9737b54ab5128903b3afab35..2fc138bbe8aa6dcfcfe896e9b59905128dd69d97 100644 (file)
@@ -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 ()
 ;;; 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))
 
 (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*))
 (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*))
       (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"))))
       (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))
     (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"