From: Kevin M. Rosenberg Date: Mon, 8 Jan 2007 15:50:47 +0000 (+0000) Subject: r11485: more use of vff X-Git-Tag: v2006ac.2~11 X-Git-Url: http://git.kpe.io/?p=umlisp.git;a=commitdiff_plain;h=b783ec60a3ebef45ea824b9fd8945167f4de2d52 r11485: more use of vff --- diff --git a/parse-rrf.lisp b/parse-rrf.lisp index e5536a9..ef56f85 100644 --- a/parse-rrf.lisp +++ b/parse-rrf.lisp @@ -38,6 +38,25 @@ used in the United States. We create a new scale (SRLUS) where SRL to SRLUS mapp ((= srl 3) 4) (t srl))) +(defvar *vff-position-hash* (make-hash-table :size 100 :test 'eq)) + +(defmacro vff (filename fieldname record) + (let ((pos (gensym "POS-")) + (found (gensym "FOUND-")) + (key (kmrcl:ensure-keyword (concatenate 'string filename "^" fieldname)))) + `(locally (declare (optimize (speed 3) (safety 0))) + (multiple-value-bind (,pos ,found) (gethash ,key *vff-position-hash*) + (declare (ignore ,found)) + (if ,pos + (locally (declare (type (integer 0 100000) ,pos)) + (nth ,pos ,record)) + (let ((,pos (position-field-file ,filename ,fieldname))) + (unless ,pos + (error "Did not find fieldname ~A in filename ~A." ,fieldname ,filename)) + (locally (declare (type (integer 0 100000) ,pos)) + (setf (gethash ,key *vff-position-hash*) ,pos) + (nth ,pos ,record)))))))) + (let ((pfstr-hash nil) ;; Preferred concept strings by CUI (cui-lrl-hash nil) ;; LRL by CUI (lui-lrl-hash nil) ;; LRL by LUI @@ -88,30 +107,31 @@ used in the United States. We create a new scale (SRLUS) where SRL to SRLUS mapp (declare (fixnum counter) (ignorable counter)) (with-umls-file (line "MRCONSO.RRF") - (let* ((cui (parse-ui (nth 0 line))) - (lui (parse-ui (nth 3 line))) - (sui (parse-ui (nth 5 line))) - (sab (nth 11 line)) - (srl (parse-integer (nth 15 line))) - (srlus (srl-to-srlus srl))) + (let* ((cui (parse-ui (vff "MRCONSO.RRF" "CUI" line))) + (lui (parse-ui (vff "MRCONSO.RRF" "LUI" line))) + (sui (parse-ui (vff "MRCONSO.RRF" "SUI" line))) + (sab (vff "MRCONSO.RRF" "SAB" line)) + (srl (parse-integer (vff "MRCONSO.RRF" "SRL" line))) + (srlus (srl-to-srlus srl)) + (cuisui (make-cuisui cui sui))) #+sbcl (when (= 0 (mod (incf counter) 100000)) (sb-ext:gc :full t)) ;; pfstr deprecated by KPFENG field in MRCONSO #+nil (unless (gethash cui pfstr-hash) ;; if haven't stored pfstr for cui - (when (and (string-equal (nth 1 line) "ENG") ; LAT - (string-equal (nth 2 line) "P") ; ts - (string-equal (nth 4 line) "PF")) ; stt - (setf (gethash cui pfstr-hash) (nth 14 line)))) + (when (and (string-equal (vff "MRCONSO.RRF" "LAT" line) "ENG") + (string-equal (vff "MRCONSO.RRF" "TS" line) "P") + (string-equal (vff "MRCONSO.RRF" "STT" line) "PF")) + (setf (gethash cui pfstr-hash) (vff "MRCONSO.RRF" "STR" line)))) (set-lrl-hash cui srl cui-lrl-hash) (set-lrl-hash lui srl lui-lrl-hash) (set-lrl-hash sui srl sui-lrl-hash) - (set-lrl-hash (make-cuisui cui sui) srl cuisui-lrl-hash) + (set-lrl-hash cuisui srl cuisui-lrl-hash) (set-lrl-hash cui srlus cui-lrlus-hash) (set-lrl-hash lui srlus lui-lrlus-hash) (set-lrl-hash sui srlus sui-lrlus-hash) - (set-lrl-hash (make-cuisui cui sui) srlus cuisui-lrlus-hash) + (set-lrl-hash cuisui srlus cuisui-lrlus-hash) (multiple-value-bind (val found) (gethash sab sab-srl-hash) (declare (ignore val)) (unless found @@ -188,35 +208,15 @@ used in the United States. We create a new scale (SRLUS) where SRL to SRLUS mapp '(("KCON" "SELECT CUI,STR FROM MRCONSO WHERE STT='PF' AND TS='P' AND ISPREF='Y' AND LAT='ENG'")) "Custom tables to create") -(defvar *vff-position-hash* (make-hash-table :size 100 :test 'eq)) - - -(defmacro vff (filename fieldname record) - (let ((pos (gensym "POS-")) - (found (gensym "FOUND-")) - (key (kmrcl:ensure-keyword (concatenate 'string filename "^" fieldname)))) - `(locally (declare (optimize (speed 3) (safety 0))) - (multiple-value-bind (,pos ,found) (gethash ,key *vff-position-hash*) - (declare (ignore ,found)) - (if ,pos - (locally (declare (type (integer 0 100000) ,pos)) - (nth ,pos ,record)) - (let ((,pos (position-field-file ,filename ,fieldname))) - (unless ,pos - (error "Did not find fieldname ~A in filename ~A." ,fieldname ,filename)) - (locally (declare (type (integer 0 100000) ,pos)) - (setf (gethash ,key *vff-position-hash*) ,pos) - (nth ,pos ,record)))))))) - (defparameter +custom-cols+ '(#+nil ("MRCONSO.RRF" "KPFSTR" "TEXT" (slot-value (find-ucol "STR" "MRCONSO.RRF") 'max) - (lambda (x) (pfstr-hash (parse-ui (nth 0 x))))) + (lambda (x) (pfstr-hash (parse-ui (vff "MRCONSO.RRF" "CUI" x))))) ;; Set to 1 if term is prefered term for english ("MRCONSO.RRF" "KPFENG" "TINYINT" 0 - (lambda (x) (if (and (string-equal (nth 1 x) "ENG") ; LAT - (string-equal (nth 2 x) "P") ; ts - (string-equal (nth 4 x) "PF")) ; stt + (lambda (x) (if (and (string-equal (vff "MRCONSO.RRF" "LAT" x) "ENG") + (string-equal (vff "MRCONSO.RRF" "TS" x) "P") + (string-equal (vff "MRCONSO.RRF" "STT" x) "PF")) "1" "0"))) ("MRCONSO.RRF" "KCUISUI" "BIGINT" 0 @@ -314,8 +314,8 @@ used in the United States. We create a new scale (SRLUS) where SRL to SRLUS mapp (parse-ui (vff "MRXNS_ENG.RRF" "CUI" x)) (parse-ui (vff "MRXNS_ENG.RRF" "SUI" x))))))) - #+nil ("MRREL.RRF" "KPFSTR2" "TEXT" 1024 (lambda (x) (pfstr-hash (parse-ui (nth 4 x))))) - #+nil ("MRCOC.RRF" "KPFSTR2" "TEXT" 1024 (lambda (x) (pfstr-hash (parse-ui (nth 2 x))))) + #+nil ("MRREL.RRF" "KPFSTR2" "TEXT" 1024 (lambda (x) (pfstr-hash (parse-ui (vff "MRREL.RRF" "CUI2" x))))) + #+nil ("MRCOC.RRF" "KPFSTR2" "TEXT" 1024 (lambda (x) (pfstr-hash (parse-ui (vff "MRCOC.RRF" "CUI2" x))))) ("MRSAT.RRF" "KCUILUI" "BIGINT" 0 (lambda (x) (write-to-string (make-cuilui