1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: umlisp -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: sql-classes.lisp
6 ;;;; Purpose: Routines for reading UMLS objects from SQL database
7 ;;;; Author: Kevin M. Rosenberg
8 ;;;; Date Started: Apr 2000
10 ;;;; $Id: sql-classes.lisp,v 1.25 2003/05/03 19:35:31 kevin Exp $
12 ;;;; This file, part of UMLisp, is
13 ;;;; Copyright (c) 2000-2002 by Kevin M. Rosenberg, M.D.
15 ;;;; UMLisp users are granted the rights to distribute and use this software
16 ;;;; as governed by the terms of the GNU General Public License.
17 ;;;; *************************************************************************
20 (declaim (optimize (compilation-speed 0) (debug 3)))
23 (defvar *current-srl* nil)
26 (defun current-srl! (srl)
27 (setq *current-srl* srl))
30 (defmacro with-umlisp-query ((table fields srl where-name where-value
31 &key (lrlname "KCUILRL") distinct single
34 (let ((query (gensym)))
35 `(unless (and ,where-name (not ,where-value))
36 (let ((,query (umlisp-query ,table (quote ,fields) ,srl ,where-name ,where-value
37 :lrlname ,lrlname :single ,single :distinct ,distinct
38 :order ,order :like ,like)))
40 (let ((tuple (car ,query)))
42 (destructuring-bind ,fields tuple
45 for tuple in ,query collect
46 (destructuring-bind ,fields tuple
49 (defun umlisp-query (table fields srl where-name where-value
50 &key (lrlname "KCUILRL") single distinct order like)
51 "Query the UMLisp database. Return a list of umlisp objects whose name
52 is OBJNAME from TABLE where WHERE-NAME field = WHERE-VALUE with FIELDS"
53 (when (or (not where-name) where-value)
55 (query-string table fields srl where-name where-value
56 :lrlname lrlname :single single :distinct distinct :order order :like like))))
59 (defun query-string (table fields &optional srl where-name where-value
60 &key (lrlname "KCUILRL") single distinct order like)
63 (format nil "select ~A~{~:@(~A~)~^,~} from ~:@(~A~)"
64 (if distinct "distinct " "") fields table)
67 (if (stringp where-value)
69 " where ~A like '%~A%'"
72 where-name where-value)
74 (if srl (format nil " and ~:@(~A~) <= ~D" lrlname srl) "")
75 (if order (format nil " order by ~{~:@(~A~) ~(~A~)~^,~}" order) "")
76 (if single " limit 1" "")))
78 (defun find-ucon-cui (cui &key (srl *current-srl*))
80 (with-umlisp-query ('mrcon (kpfstr kcuilrl) srl 'cui (parse-cui cui) :single t)
81 (make-instance 'ucon :cui (parse-cui cui)
83 :lrl (ensure-integer kcuilrl))))
85 (defun find-ucon-cui-old (cui &key (srl *current-srl*))
87 (when (stringp cui) (setq cui (parse-cui cui)))
89 (let ((ls (format nil "select KPFSTR,KCUILRL from MRCON where CUI=~d" cui)))
91 (string-append ls (format nil " and KCUILRL <= ~d" srl)))
92 (string-append ls " limit 1")
93 (awhen (car (mutex-sql-query ls))
94 (destructuring-bind (kpfstr kcuilrl)
95 (make-instance 'ucon :cui cui :pfstr kpfstr
96 :lrl (ensure-integer kcuilrl)))))))
98 (defun find-ucon-cui-sans-pfstr (cui &key (srl *current-srl*))
100 (with-umlisp-query ('mrcon (kcuilrl) srl 'cui (parse-cui cui) :single t)
101 (make-instance 'ucon :cui (parse-cui cui)
102 :lrl (ensure-integer kcuilrl)
105 (defun find-pfstr-cui (cui &key (srl *current-srl*))
106 "Find preferred string for a cui"
107 (with-umlisp-query ('mrcon (kpfstr) srl 'cui (parse-cui cui) :single t)
110 (defun find-ucon-lui (lui &key (srl *current-srl*))
111 "Find list of ucon for lui"
112 (with-umlisp-query ('mrcon (cui kpfstr kcuilrl) srl 'lui (parse-lui lui) :distinct t)
113 (make-instance 'ucon :cui (ensure-integer cui)
115 :lrl (ensure-integer kcuilrl))))
117 (defun find-ucon-sui (sui &key (srl *current-srl*))
118 "Find list of ucon for sui"
119 (with-umlisp-query ('mrcon (cui kpfstr kcuilrl) srl 'sui (parse-sui sui) :distinct t)
120 (make-instance 'ucon :cui (ensure-integer cui)
122 :lrl (ensure-integer kcuilrl))))
124 (defun find-ucon-cuisui (cui sui &key (srl *current-srl*))
125 "Find ucon for cui/sui"
127 (with-umlisp-query ('mrcon (cui kpfstr kcuilrl) srl 'kcuisui
128 (make-cuisui (parse-cui cui) (parse-sui sui)))
129 (make-instance 'ucon :cui (ensure-integer cui)
131 :lrl (ensure-integer kcuilrl)))))
133 (defun find-ucon-str (str &key (srl *current-srl*))
134 "Find ucon that are exact match for str"
135 (with-umlisp-query ('mrcon (cui kpfstr kcuilrl) srl 'str str :distinct t)
136 (make-instance 'ucon :cui (ensure-integer cui) :pfstr kpfstr
137 :lrl (ensure-integer kcuilrl))))
139 (defun find-ucon-all (&key (srl *current-srl*))
140 "Return list of all ucon's"
141 (with-sql-connection (db)
144 #'(lambda (cui pfstr cuilrl)
145 (make-instance 'ucon :cui (ensure-integer cui)
147 :lrl (ensure-integer cuilrl)))
148 (query-string 'mrcon '(cui kpfstr kcuilrl) srl nil nil
149 :order '(cui asc) :distinct t)
152 (defun map-ucon-all (fn &key (srl *current-srl*))
153 "Map a function over all ucon's"
154 (with-sql-connection (db)
157 #'(lambda (cui pfstr cuilrl)
159 (make-instance 'ucon :cui (ensure-integer cui)
161 :lrl (ensure-integer cuilrl))))
162 (query-string 'mrcon '(cui kpfstr kcuilrl) srl nil nil :order '(cui asc) :distinct t)
166 (defun find-udef-cui (cui &key (srl *current-srl*))
167 "Return a list of udefs for cui"
168 (with-umlisp-query ('mrdef (sab def) srl 'cui (parse-cui cui) :lrlname "KSRL")
169 (make-instance 'udef :sab sab :def def)))
171 (defun find-usty-cui (cui &key (srl *current-srl*))
172 "Return a list of usty for cui"
173 (with-umlisp-query ('mrsty (tui sty) srl 'cui (parse-cui cui) :lrlname "KLRL")
174 (make-instance 'usty :tui (ensure-integer tui) :sty sty)))
176 (defun find-usty-word (word &key (srl *current-srl*))
177 "Return a list of usty that match word"
178 (with-umlisp-query ('mrsty (tui sty) srl 'sty word :lrlname 'klrl :like t :distinct t)
179 (make-instance 'usty :tui (ensure-integer tui) :sty sty)))
181 (defun find-urel-cui (cui &key (srl *current-srl*))
182 "Return a list of urel for cui"
183 (with-umlisp-query ('mrrel (rel cui2 rela sab sl mg kpfstr2) srl 'cui1 (parse-cui cui) :lrlname "KSRL")
184 (make-instance 'urel :cui1 (parse-cui cui) :rel rel :cui2 (ensure-integer cui2) :rela rela
185 :sab sab :sl sl :mg mg :pfstr2 kpfstr2)))
187 (defun find-urel-cui2 (cui2 &key (srl *current-srl*))
188 "Return a list of urel for cui2"
189 (with-umlisp-query ('mrrel (rel cui1 rela sab sl mg kpfstr2) srl 'cui2 (parse-cui cui2) :lrlname "KSRL")
190 (make-instance 'urel :cui2 (parse-cui cui2) :rel rel :cui1 (ensure-integer cui1) :rela rela
191 :sab sab :sl sl :mg mg :pfstr2 kpfstr2)))
193 (defun find-ucon-rel-cui2 (cui2 &key (srl *current-srl*))
195 #'(lambda (cui) (find-ucon-cui cui :srl srl))
196 (remove-duplicates (mapcar #'cui1 (find-urel-cui2 cui2 :srl srl)))))
198 (defun find-ucoc-cui (cui &key (srl *current-srl*))
199 "Return a list of ucoc for cui"
200 (with-umlisp-query ('mrcoc (cui2 soc cot cof coa kpfstr2) srl 'cui1 (parse-cui cui)
201 :lrlname "KSRL" :order '(cof asc))
202 (setq cui2 (ensure-integer cui2))
203 (when (zerop cui2) (setq cui2 nil))
204 (make-instance 'ucoc :cui1 (parse-cui cui) :cui2 (ensure-integer cui2) :soc soc :cot cot
205 :cof (ensure-integer cof) :coa coa :pfstr2 kpfstr2)))
207 (defun find-ucoc-cui2 (cui2 &key (srl *current-srl*))
208 "Return a list of ucoc for cui2"
209 (with-umlisp-query ('mrcoc (cui1 soc cot cof coa kpfstr2) srl 'cui2 (parse-cui cui2)
210 :lrlname "KSRL" :order '(cof asc))
211 (setq cui2 (ensure-integer cui2))
212 (when (zerop cui2) (setq cui2 nil))
213 (make-instance 'ucoc :cui1 (ensure-integer cui1) :cui2 (parse-cui cui2) :soc soc :cot cot
214 :cof (ensure-integer cof) :coa coa :pfstr2 kpfstr2)))
216 (defun find-ucon-coc-cui2 (cui2 &key (srl *current-srl*))
217 "List of ucon with co-occurance cui2"
219 #'(lambda (cui) (find-ucon-cui cui :srl srl))
220 (remove-duplicates (mapcar #'cui1 (find-ucoc-cui2 cui2 :srl srl)))))
222 (defun find-ulo-cui (cui &key (srl *current-srl*))
223 "Return a list of ulo for cui"
224 (with-umlisp-query ('mrlo (isn fr un sui sna soui) srl 'cui (parse-cui cui) :lrlname "KLRL")
225 (make-instance 'ulo :isn isn :fr (ensure-integer fr) :un un :sui (ensure-integer sui) :sna sna
228 (defgeneric suistr (lo))
229 (defmethod suistr ((lo ulo))
230 "Return the string for a ulo object"
231 (find-string-sui (sui lo)))
233 (defun find-uatx-cui (cui &key (srl *current-srl*))
234 "Return a list of uatx for cui"
235 (with-umlisp-query ('mratx (sab rel atx) srl 'cui (parse-cui cui) :lrlname 'ksrl)
236 (make-instance 'uatx :sab sab :rel rel :atx atx)))
239 (defun find-uterm-cui (cui &key (srl *current-srl*))
240 "Return a list of uterm for cui"
241 (with-umlisp-query ('mrcon (lui lat ts kluilrl) srl 'cui (parse-cui cui) :lrlname 'kluilrl
243 (make-instance 'uterm :lui (ensure-integer lui) :cui (parse-cui cui)
244 :lat lat :ts ts :lrl (ensure-integer kluilrl))))
246 (defun find-uterm-lui (lui &key (srl *current-srl*))
247 "Return a list of uterm for lui"
248 (with-umlisp-query ('mrcon (cui lat ts kluilrl) srl 'lui (parse-lui lui)
249 :lrlname 'kluilrl :distinct t)
250 (make-instance 'uterm :cui (ensure-integer cui) :lui (parse-lui lui)
251 :lat lat :ts ts :lrl (ensure-integer kluilrl))))
253 (defun find-uterm-cuilui (cui lui &key (srl *current-srl*))
254 "Return single uterm for cui/lui"
255 (with-umlisp-query ('mrcon (lat ts kluilrl) srl 'kcuilui
256 (make-cuilui (parse-cui cui) (parse-lui lui))
257 :lrlname 'kluilrl :single t)
258 (make-instance 'uterm :cui cui :lui lui :lat lat :ts ts :lrl (ensure-integer kluilrl))))
260 (defun find-ustr-cuilui (cui lui &key (srl *current-srl*))
261 "Return a list of ustr for cui/lui"
262 (with-umlisp-query ('mrcon (sui stt str lrl) srl 'kcuilui (make-cuilui cui lui) :lrlname 'lrl)
263 (make-instance 'ustr :sui (ensure-integer sui) :cui cui :lui lui
264 :cuisui (make-cuisui cui sui) :stt stt :str str
265 :lrl (ensure-integer lrl))))
267 (defun find-ustr-cuisui (cui sui &key (srl *current-srl*))
268 "Return the single ustr for cuisui"
269 (with-umlisp-query ('mrcon (lui stt str lrl) srl 'kcuisui (make-cuisui cui sui) :lrlname 'lrl :single t)
270 (make-instance 'ustr :sui sui :cui cui :cuisui (make-cuisui cui sui)
271 :lui (ensure-integer lui) :stt stt :str str :lrl (ensure-integer lrl))))
273 (defun find-ustr-sui (sui &key (srl *current-srl*))
274 "Return the list of ustr for sui"
275 (with-umlisp-query ('mrcon (cui lui stt str lrl) srl 'sui (parse-sui sui) :lrlname 'lrl)
276 (make-instance 'ustr :sui sui :cui cui :stt stt :str str
277 :cuisui (make-cuisui (ensure-integer cui) (parse-sui sui))
278 :lui (ensure-integer lui)
279 :lrl (ensure-integer lrl))))
281 (defun find-ustr-sab (sab &key (srl *current-srl*))
282 "Return the list of ustr for sab"
283 (with-umlisp-query ('mrso (kcuisui) srl 'sab sab :lrlname 'srl)
284 (let ((cuisui (ensure-integer kcuisui)))
285 (apply #'find-ustr-cuisui
287 (multiple-value-list (decompose-cuisui cuisui)) (list :srl srl))))))
289 (defun find-ustr-all (&key (srl *current-srl*))
290 "Return list of all ustr's"
291 (with-sql-connection (db)
294 #'(lambda (cui lui sui stt lrl pfstr)
295 (setq cui (ensure-integer cui))
296 (setq lui (ensure-integer lui))
297 (setq sui (ensure-integer sui))
298 (setq lrl (ensure-integer lrl))
299 (make-instance 'ustr :cui cui
302 :cuisui (make-cuisui cui sui)
306 (query-string 'mrcon '(cui lui sui stt lrl kpfstr) srl nil nil :lrlname 'lrl :distinct t
310 (defun find-string-sui (sui &key (srl *current-srl*))
311 "Return the string associated with sui"
312 (with-umlisp-query ('mrcon (str) srl 'sui sui :lrlname 'lrl :single t)
315 (defun find-uso-cuisui (cui sui &key (srl *current-srl*))
316 (with-umlisp-query ('mrso (sab code srl tty) srl 'kcuisui (make-cuisui cui sui) :lrlname 'srl)
317 (make-instance 'uso :sab sab :code code :srl srl :tty tty)))
319 (defun find-ucxt-cuisui (cui sui &key (srl *current-srl*))
320 (with-umlisp-query ('mrcxt (sab code cxn cxl rnk cxs cui2 hcd rela xc) srl 'kcuisui
321 (make-cuisui cui sui) :lrlname 'ksrl)
322 (make-instance 'ucxt :sab sab :code code
323 :cxn (ensure-integer cxn)
324 :cxl cxl :cxs cxs :hcd hcd :rela rela :xc xc
325 :rnk (ensure-integer rnk)
326 :cui2 (ensure-integer cui2))))
328 (defun find-usat-ui (cui &optional (lui nil) (sui nil) &key (srl *current-srl*))
329 (let ((ls (format nil "select CODE,ATN,SAB,ATV from MRSAT where ")))
331 (sui (string-append ls (format nil "KCUISUI=~d" (make-cuisui cui sui))))
332 (lui (string-append ls (format nil "KCUILUI=~d and sui=0" (make-cuilui cui lui))))
333 (t (string-append ls (format nil "cui=~d and lui=0 and sui=0" cui))))
335 (string-append ls (format nil " and KSRL <= ~d" srl)))
337 (dolist (tuple (mutex-sql-query ls))
338 (destructuring-bind (code atn sab atv) tuple
339 (push (make-instance 'usat :code code :atn atn :sab sab :atv atv)
344 (defun find-usty-tui (tui)
346 (with-umlisp-query ('mrsty (sty) nil 'tui (parse-tui tui) :single t)
347 (make-instance 'usty :tui (parse-tui tui) :sty sty)))
349 (defun find-usty-sty (sty)
350 "Find usty for a sty"
351 (with-umlisp-query ('mrsty (tui) nil 'sty sty :single t)
352 (make-instance 'usty :tui (ensure-integer tui) :sty sty)))
354 (defun find-usty-all ()
355 "Return list of usty's for all semantic types"
356 (with-umlisp-query ('mrsty (tui) nil nil nil :distinct t)
357 (find-usty-tui tui)))
359 (defun find-usab-all ()
360 "Find usab for a key"
361 (with-umlisp-query ('mrsab (vcui rcui vsab rsab son sf sver mstart mend imeta rmeta slc scc srl tfr cfr cxty ttyl atnl lat cenc curver sabin) nil nil nil)
362 (make-instance 'usab :vcui (ensure-integer vcui)
363 :rcui (ensure-integer rcui)
364 :vsab vsab :rsab rsab :son son :sf sf :sver sver :mstart mstart
365 :mend mend :imeta imeta :rmeta rmeta :slc slc :scc scc
366 :srl (ensure-integer srl)
367 :tfr (ensure-integer tfr) :cfr (ensure-integer cfr)
368 :cxty cxty :ttyl ttyl :atnl atnl :lat lat :cenc cenc
369 :curver curver :sabin sabin)))
371 (defun find-usab-by-key (key-name key)
372 "Find usab for a key"
373 (with-umlisp-query ('mrsab (vcui rcui vsab rsab son sf sver mstart mend imeta rmeta slc scc srl tfr cfr cxty ttyl atnl lat cenc curver sabin) nil key-name key :single t)
374 (make-instance 'usab :vcui (ensure-integer vcui)
375 :rcui (ensure-integer rcui)
376 :vsab vsab :rsab rsab :son son :sf sf :sver sver :mstart mstart
377 :mend mend :imeta imeta :rmeta rmeta :slc slc :scc scc
378 :srl (ensure-integer srl)
379 :tfr (ensure-integer tfr) :cfr (ensure-integer cfr)
380 :cxty cxty :ttyl ttyl :atnl atnl :lat lat :cenc cenc
381 :curver curver :sabin sabin)))
383 (defun find-usab-rsab (rsab)
385 (find-usab-by-key "RSAB" rsab))
387 (defun find-usab-vsab (vsab)
389 (find-usab-by-key "VSAB" vsab))
391 (defun find-cui-max ()
392 (ensure-integer (caar (mutex-sql-query "select max(CUI) from MRCON"))))
394 ;;;; Cross table find functions
396 (defun find-ucon-tui (tui &key (srl *current-srl*))
397 "Find list of ucon for tui"
398 (with-umlisp-query ('mrsty (cui) srl 'tui (parse-tui tui) :lrlname 'klrl
400 (find-ucon-cui (ensure-integer cui) :srl srl)))
402 (defun find-ucon-word (word &key (srl *current-srl*) (like nil))
403 "Return list of ucons that match word. Optionally, use SQL's LIKE syntax"
404 (with-umlisp-query ('mrxw_eng (cui) srl 'wd word :like like :distinct t
405 :lrlname 'klrl :order '(cui asc))
406 (find-ucon-cui cui :srl srl)))
408 (defun find-ucon-normalized-word (word &key (srl *current-srl*) (like nil))
409 "Return list of ucons that match word, optionally use SQL's LIKE syntax"
410 (with-umlisp-query ('mrxnw_eng (cui) srl 'nwd word :like like :distinct t
411 :lrlname 'klrl :order '(cui asc))
412 (find-ucon-cui cui :srl srl)))
414 (defun find-ustr-word (word &key (srl *current-srl*))
415 "Return list of ustrs that match word"
416 (with-umlisp-query ('mrxw_eng (cui sui) srl 'wd word
418 :order '(cui asc sui asc))
419 (find-ustr-cuisui (ensure-integer cui) (ensure-integer sui) :srl srl)))
421 (defun find-ustr-normalized-word (word &key (srl *current-srl*))
422 "Return list of ustrs that match word"
423 (with-umlisp-query ('mrxnw_eng (cui sui) srl 'nwd word :lrlname 'klrl
424 :order '(cui asc sui asc))
425 (find-ustr-cuisui (ensure-integer cui) (ensure-integer sui) :srl srl)))
429 (defun find-usrl-all ()
430 (with-umlisp-query ('usrl (sab srl) nil nil nil :order '(sab asc))
431 (make-instance 'usrl :sab sab :srl (ensure-integer srl))))
433 ;;; Multiword lookup and score functions
435 (defun find-ucon-multiword (str &key (srl *current-srl*))
436 "Return sorted list of ucon's that match a multiword string"
437 (let* ((words (delimited-string-to-list str #\space))
440 (setq ucons (append ucons (find-ucon-word word :srl srl))))
441 (sort-score-ucon-str str (delete-duplicates ucons :test #'eql :key #'cui))))
443 (defun find-ustr-multiword (str &key (srl *current-srl*))
444 "Return sorted list of ustr's that match a multiword string"
445 (let* ((words (delimited-string-to-list str #\space))
448 (setq ustrs (append ustrs (find-ustr-word word :srl srl))))
449 (sort-score-ustr-str str (delete-duplicates ustrs :test #'eql :key #'cui))))
451 (defun sort-score-ucon-str (str ucons)
452 "Return list of sorted and scored ucons. Score by match of str to ucon-pfstr"
453 (sort-score-umlsclass-str ucons str #'pfstr))
455 (defun sort-score-ustr-str (str ustrs)
456 "Return list of sorted and scored ucons. Score by match of str to ucon-pfstr"
457 (sort-score-umlsclass-str ustrs str #'str))
459 (defun sort-score-umlsclass-str (objs str lookup-func)
460 "Sort a list of objects based on scoring to a string"
465 (score-multiword-match str (funcall lookup-func obj)))
467 (mapcar #'car (sort scored #'> :key #'cadr))))
469 (defun score-multiword-match (s1 s2)
470 "Score a match between two strings with s1 being reference string"
471 (let* ((word-list-1 (delimited-string-to-list s1 #\space))
472 (word-list-2 (delimited-string-to-list s2 #\space))
473 (n1 (length word-list-1))
474 (n2 (length word-list-2))
479 short-list long-list)
480 (declare (fixnum n1 n2 nshort nlong score unmatched))
485 (setq long-list word-list-1)
486 (setq short-list word-list-2))
490 (setq long-list word-list-2)
491 (setq short-list word-list-1)))
492 (decf score (- nlong nshort)) ;; reduce score for extra words
493 (dotimes (iword nshort)
494 (declare (fixnum iword))
495 (kmrcl:aif (position (nth iword short-list) long-list :test #'string-equal)
497 (incf score (- 10 (abs (- kmrcl::it iword))))
499 (decf score (* 2 unmatched))
503 ;;; LEX SQL functions
505 (defun find-lexterm-eui (eui)
506 (with-umlisp-query ('lrwd (wrd) nil 'eui eui :single t)
507 (make-instance 'lexterm :eui eui :wrd wrd)))
509 (defun find-lexterm-word (wrd)
510 (with-umlisp-query ('lrwd (eui) nil 'wrd wrd)
511 (make-instance 'lexterm :eui (ensure-integer eui)
512 :wrd (copy-seq wrd))))
514 ;; LEX SQL Read functions
516 (defun find-labr-eui (eui)
517 (with-umlisp-query ('lrabr (bas abr eui2 bas2) nil 'eui eui)
518 (make-instance 'labr :eui eui :bas bas :abr abr :bas2 bas2
519 :eui2 (ensure-integer eui2))))
521 (defun find-labr-bas (bas)
522 (with-umlisp-query ('labr (eui abr eui2 bas2) nil 'bas bas)
523 (make-instance 'labr :eui (ensure-integer eui) :abr abr :bas2 bas2
524 :bas (copy-seq bas) :eui2 (ensure-integer eui2))))
526 (defun find-lagr-eui (eui)
527 (with-umlisp-query ('lragr (str sca agr cit bas) nil 'eui eui)
528 (make-instance 'lagr :eui eui :str str :sca sca :agr agr
531 (defun find-lcmp-eui (eui)
532 (with-umlisp-query ('lrcmp (bas sca com) nil 'eui eui)
533 (make-instance 'lcmp :eui eui :bas bas :sca sca :com com)))
535 (defun find-lmod-eui (eui)
536 (with-umlisp-query ('lrmod (bas sca psn_mod fea) nil 'eui eui)
537 (make-instance 'lmod :eui eui :bas bas :sca sca :psnmod psn_mod :fea fea)))
539 (defun find-lnom-eui (eui)
540 (with-umlisp-query ('lrnom (bas sca eui2 bas2 sca2) nil 'eui eui)
541 (make-instance 'lnom :eui eui :bas bas :sca sca :bas2 bas2 :sca2 sca2
542 :eui2 (ensure-integer eui2))))
544 (defun find-lprn-eui (eui)
545 (with-umlisp-query ('lrprn (bas num gnd cas pos qnt fea) nil 'eui eui)
546 (make-instance 'lprn :eui eui :bas bas :num num :gnd gnd
547 :cas cas :pos pos :qnt qnt :fea fea)))
549 (defun find-lprp-eui (eui)
550 (with-umlisp-query ('lrprp (bas str sca fea) nil 'eui eui)
551 (make-instance 'lprp :eui eui :bas bas :str str :sca sca :fea fea)))
553 (defun find-lspl-eui (eui)
554 (with-umlisp-query ('lrspl (spv bas) nil 'eui eui)
555 (make-instance 'lspl :eui eui :spv spv :bas bas)))
557 (defun find-ltrm-eui (eui)
558 (with-umlisp-query ('lrtrm (bas gen) nil 'eui eui)
559 (make-instance 'ltrm :eui eui :bas bas :gen gen)))
561 (defun find-ltyp-eui (eui)
562 (with-umlisp-query ('lrtyp (bas sca typ) nil 'eui eui)
563 (make-instance 'ltyp :eui eui :bas bas :sca sca :typ typ)))
565 (defun find-lwd-wrd (wrd)
566 (make-instance 'lwd :wrd
567 :euilist (with-umlisp-query ('lrwd (eui) nil 'wrd wrd)
568 (ensure-integer eui))))
570 ;;; Semantic Network SQL access functions
572 (defun find-sdef-ui (ui)
573 (with-umlisp-query ('srdef (rt sty_rl stn_rtn def ex un rh abr rin)
574 nil 'ui ui :single t)
575 (make-instance 'sdef :rt rt :ui ui :styrl sty_rl :stnrtn stn_rtn
576 :def def :ex ex :un un :rh rh :abr abr :rin rin)))
578 (defun find-sstre1-ui (ui)
579 (with-umlisp-query ('srstre1 (ui2 ui3) nil 'ui ui)
580 (make-instance 'sstre1 :ui ui :ui2 (ensure-integer ui2)
581 :ui3 (ensure-integer ui3))))
583 (defun find-sstre1-ui2 (ui2)
584 (with-umlisp-query ('srstre1 (ui ui3) nil 'ui2 ui2)
585 (make-instance 'sstre1 :ui (ensure-integer ui) :ui2 ui2
586 :ui3 (ensure-integer ui3))))
588 (defun find-sstr-rl (rl)
589 (with-umlisp-query ('srstre (sty_rl sty_rl2 ls) nil 'rl rl)
590 (make-instance 'sstr :rl rl :styrl sty_rl :styrl2 sty_rl2 :ls ls)))
592 (defun find-sstre2-sty (sty)
593 (with-umlisp-query ('srstre2 (rl sty2) nil 'sty sty)
594 (make-instance 'sstre2 :sty (copy-seq sty) :rl rl :sty2 sty2)))
596 (defun find-sstr-styrl (styrl)
597 (with-umlisp-query ('srstr (rl sty_rl2 ls) nil 'styrl styrl)
598 (make-instance 'sstr :styrl styrl :rl rl :styrl2 sty_rl2 :ls ls)))