X-Git-Url: http://git.kpe.io/?p=umlisp.git;a=blobdiff_plain;f=sql-classes.lisp;h=20ef37eafe82939234e727cfa8441c18f3edfa97;hp=594103fcd95c0d9a7b3303f5119b1f3512854136;hb=57c4b059639968903aec88e65103a7263cb97535;hpb=67ee261d341603e293f6b0314d5cd12522fa04c6 diff --git a/sql-classes.lisp b/sql-classes.lisp index 594103f..20ef37e 100644 --- a/sql-classes.lisp +++ b/sql-classes.lisp @@ -35,7 +35,7 @@ "")) (%%lrl (format nil " AND ~:@(~A~)<=" lrl)) (%%where (when where-name - (format nil " where ~:@(~A~)~A" where-name + (format nil " WHERE ~:@(~A~)~A" where-name (if like " like " "")))) (%filter (gensym "FILTER-")) (%single (gensym "SINGLE-")) @@ -55,7 +55,7 @@ (number (concatenate 'string "='" (write-to-string ,where-value) "'")) (null - " is null") + " IS NULL") (t (format nil ,(if like "'%~A%'" "='~A'") ,where-value))))) (if ,%filter (concatenate 'string @@ -78,22 +78,22 @@ (when single (setq limit 1)) (concatenate 'string - (format nil "select ~A~{~:@(~A~)~^,~} from ~:@(~A~)" - (if distinct "distinct " "") fields table) - (if where-name (format nil " where ~:@(~A~)" where-name) "") + (format nil "SELECT ~A~{~:@(~A~)~^,~} FROM ~:@(~A~)" + (if distinct "DISTINCT " "") fields table) + (if where-name (format nil " WHERE ~:@(~A~)" where-name) "") (if where-name (format nil (typecase where-value (number "='~D'") - (null " is null") + (null " IS NULL") (t - (if like " like '%~A%""='~A'"))) + (if like " LINK '%~A%""='~A'"))) where-value) "") (if filter (concatenate 'string " AND " filter) nil) - (if srl (format nil " and ~:@(~A~)<=~D" lrl srl) "") - (if order (format nil " order by ~{~:@(~A~) ~(~A~)~^,~}" order) "") - (if limit (format nil " limit ~D" limit) ""))) + (if srl (format nil " AND ~:@(~A~)<=~D" lrl srl) "") + (if order (format nil " ORDER BY ~{~:@(~A~) ~(~A~)~^,~}" order) "") + (if limit (format nil " LIMIT ~D" limit) ""))) (defmacro umlisp-query (table fields srl where-name where-value @@ -224,25 +224,27 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS" (setq ,eui (parse-eui ,eui)) ,eui)) -(defun find-ucon-cui (cui &key (srl *current-srl*)) +(defun make-ucon-cui (cui) + (ensure-cui-integer cui) + (when cui + (make-instance 'ucon :cui cui))) + +(defun find-ucon-cui (cui &key (srl *current-srl*) without-pfstr) "Find ucon for a cui" (ensure-cui-integer cui) (unless cui (return-from find-ucon-cui nil)) - (or - (collect-umlisp-query (mrconso (kcuilrl str) srl cui cui :single t :filter "KPFENG=1") - (make-instance 'ucon :cui cui :pfstr str - :lrl kcuilrl)) - (collect-umlisp-query (mrconso (kcuilrl str) srl cui cui :single t) - (make-instance 'ucon :cui cui :pfstr str - :lrl kcuilrl)))) - -(defun find-ucon-cui-sans-pfstr (cui &key (srl *current-srl*)) - "Find ucon for a cui" - (ensure-cui-integer cui) - (collect-umlisp-query (mrconso (kcuilrl) srl cui cui :single t) - (make-instance 'ucon :cui cui :lrl (ensure-integer kcuilrl) - :pfstr nil))) + (if without-pfstr + (collect-umlisp-query (mrconso (kcuilrl) srl cui cui :single t) + (make-instance 'ucon :cui cui :lrl (ensure-integer kcuilrl) + :pfstr nil))) + (or + (collect-umlisp-query (mrconso (kcuilrl str) srl cui cui :single t :filter "KPFENG=1") + (make-instance 'ucon :cui cui :pfstr str + :lrl kcuilrl)) + (collect-umlisp-query (mrconso (kcuilrl str) srl cui cui :single t) + (make-instance 'ucon :cui cui :pfstr str + :lrl kcuilrl)))) (defun find-pfstr-cui (cui &key (srl *current-srl*)) "Find preferred string for a cui" @@ -253,7 +255,13 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS" str) (collect-umlisp-query (mrconso (str) srl cui cui :distinct t :single t) - str))) + str))) + +(defun find-lrl-cui (cui &key (srl *current-srl*)) + "Find LRL for a cui" + (ensure-cui-integer cui) + (collect-umlisp-query (mrconso (kcuilrl) srl cui cui :distinct t :single t) + (ensure-integer kcuilrl))) (defun find-ucon-lui (lui &key (srl *current-srl*)) "Find list of ucon for lui" @@ -380,15 +388,19 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS" :distinct t) (make-instance 'usty :tui (ensure-integer tui) :sty sty))) -(defun find-urel-cui (cui &key (srl *current-srl*)) +(defun find-urel-cui (cui &key (srl *current-srl*) filter without-pfstr2) "Return a list of urel for cui" (ensure-cui-integer cui) (collect-umlisp-query (mrrel (aui1 rel stype1 cui2 aui2 stype2 rela rui srui sab sl rg dir suppress cvf) - srl cui1 cui :lrl "KSRL") - (make-instance 'urel :cui1 cui :aui1 (ensure-integer aui1) :stype1 stype1 :rel rel - :cui2 (ensure-integer cui2) :aui2 (ensure-integer aui2) :stype2 stype2 - :rui (ensure-integer rui) :srui srui :rela rela :sab sab :sl sl :rg rg :dir dir - :suppress suppress :cvf cvf :pfstr2 (find-pfstr-cui cui2)))) + srl cui1 cui :lrl "KSRL" :filter filter) + (let ((rel + (make-instance 'urel :cui1 cui :aui1 (ensure-integer aui1) :stype1 stype1 :rel rel + :cui2 (ensure-integer cui2) :aui2 (ensure-integer aui2) :stype2 stype2 + :rui (ensure-integer rui) :srui srui :rela rela :sab sab :sl sl :rg rg :dir dir + :suppress suppress :cvf cvf))) + (unless without-pfstr2 + (setf (slot-value rel 'pfstr2) (find-pfstr-cui cui2))) + rel))) (defun find-urel-rui (rui &key (srl *current-srl*)) "Return the urel for a rui" @@ -604,7 +616,7 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS" (ensure-cui-integer cui) (ensure-lui-integer lui) (ensure-sui-integer sui) - (let ((ls "select CODE,ATN,SAB,ATV from MRSAT where ")) + (let ((ls "SELECT CODE,ATN,SAB,ATV FROM MRSAT WHERE ")) (cond (sui (string-append ls "KCUISUI='" (integer-string (make-cuisui cui sui) 14)