Find distinct udef
[umlisp.git] / sql-classes.lisp
index 8031ace4553584dfdf6f2e3411881cdae0f41bd8..df23c492e224aae5812ddd15314655f4642534a1 100644 (file)
@@ -285,7 +285,8 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
 (defun find-uconso-sui (sui &key sab (srl *current-srl*))
   "Find uconso for a sui. If set SAB, the without-pfstr is on by default"
   (ensure-sui-integer sui)
-  (unless (and sui (stringp sab))
+;;  (unless (and sui (stringp sab))
+  (unless sui
     (return-from find-uconso-sui nil))
 
   (collect-umlisp-query (mrconso (cui lat ts lui stt sui ispref aui saui scui sdui sab tty code str
@@ -410,7 +411,8 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
 (defun find-udef-cui (cui &key (srl *current-srl*))
   "Return a list of udefs for cui"
   (ensure-cui-integer cui)
-  (collect-umlisp-query (mrdef (sab def suppress) srl cui cui :lrl "KSRL")
+  (collect-umlisp-query (mrdef (sab def suppress) srl cui cui :lrl "KSRL"
+                               :distinct t)
     (make-instance 'udef :sab sab :def def :suppress suppress)))
 
 (defun find-udoc-key (key)
@@ -555,7 +557,7 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
   (ensure-cui-integer cui)
   (ensure-lui-integer lui)
   (collect-umlisp-query (mrconso (sui stt str suppress ksuilrl) srl kcuilui
-                                 (make-cuilui cui lui) :lrl ksuilrl)
+                                 (make-cuilui cui lui) :lrl ksuilrl :distinct t)
                 (make-instance 'ustr :sui (ensure-integer sui) :cui cui :lui lui
                    :cuisui (make-cuisui cui sui) :stt stt :str str :suppress suppress
                    :lrl (ensure-integer ksuilrl))))
@@ -563,7 +565,7 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
 (defun find-ustr-cuisui (cuisui &key (srl *current-srl*))
   "Return the single ustr for cuisui"
   (collect-umlisp-query (mrconso (cui lui sui stt str suppress ksuilrl) srl kcuisui
-                                 cuisui :lrl lsuilrl :single t)
+                                 cuisui :lrl ksuilrl :single t)
     (make-instance 'ustr :sui sui :cui cui :cuisui cuisui
                    :lui (ensure-integer lui) :stt stt :str str :suppress suppress
                    :lrl (ensure-integer ksuilrl))))
@@ -578,7 +580,7 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
   "Return the list of ustr for sui"
   (ensure-sui-integer sui)
   (collect-umlisp-query (mrconso (cui lui stt str suppress ksuilrl) srl sui sui
-                            :lrl ksuilrl)
+                            :lrl ksuilrl :distinct t)
     (make-instance 'ustr :sui sui :cui cui :stt stt :str str
                    :cuisui (make-cuisui (ensure-integer cui) sui)
                    :suppress suppress
@@ -626,20 +628,20 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
 
 (defun find-uso-cui (cui &key (srl *current-srl*) (english-only nil) limit)
   (ensure-cui-integer cui)
-  (collect-umlisp-query (mrconso (aui sab code srl tty saui sdui scui lat str sui)
+  (collect-umlisp-query (mrconso (aui sab code srl tty saui sdui scui lat str sui ts)
                                  srl cui cui :lrl srl :limit limit
                                  :filter (when english-only "LAT='ENG'"))
      (make-instance 'uso :aui aui :sab sab :code code :srl srl :tty tty
                     :cui cui :sui sui :saui saui :sdui sdui :scui scui
-                    :lat lat :str str)))
+                    :lat lat :str str :ts ts)))
 
 (defun find-uso-aui (aui &key (srl *current-srl*))
   (ensure-sui-integer aui)
   (collect-umlisp-query (mrconso (sab cui sui code srl tty saui sdui scui lat
-                                      str) srl aui aui :lrl srl :single t)
+                                      str ts) srl aui aui :lrl srl :single t)
     (make-instance 'uso :aui aui :cui cui :sab sab :code code :srl srl :tty tty
                    :sui sui :saui saui :sdui sdui :scui scui :lat lat
-                   :str str)))
+                   :str str :ts ts)))
 
 (defun find-uhier-cui (cui &key (srl *current-srl*))
   (ensure-cui-integer cui)
@@ -911,8 +913,8 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
                                 only-exact-if-match limit &key extra-lookup-args)
   (let ((uobjs '()))
     (dolist (word (delimited-string-to-list str #\space))
-      (setq uobjs (append uobjs
-                          (kmrcl:flatten (apply obj-lookup-fun word :srl srl extra-lookup-args)))))
+      (setq uobjs (nconc uobjs
+                         (kmrcl:flatten (apply obj-lookup-fun word :srl srl extra-lookup-args)))))
     (let ((sorted
            (funcall sort-fun str
                     (delete-duplicates uobjs :test #'= :key key))))
@@ -1157,4 +1159,3 @@ is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
 (defun find-ustats-srl (srl)
   (collect-umlisp-query (ustats (name count) nil srl srl :order (name asc))
                            (make-instance 'ustats :name name :hits (ensure-integer count))))
-