r5354: *** empty log message ***
[umlisp.git] / class-support.lisp
index 8f97dd150001680086fac9885689c2350441bb0d..3245a1f96154a680b36514786ac689cb7daee95b 100644 (file)
@@ -7,10 +7,10 @@
 ;;;; Author:       Kevin M. Rosenberg
 ;;;; Date Started: Apr 2000
 ;;;;
-;;;; $Id: class-support.lisp,v 1.5 2003/05/07 22:53:36 kevin Exp $
+;;;; $Id: class-support.lisp,v 1.18 2003/07/21 00:53:27 kevin Exp $
 ;;;;
 ;;;; This file, part of UMLisp, is
-;;;;    Copyright (c) 2000-2002 by Kevin M. Rosenberg, M.D.
+;;;;    Copyright (c) 2000-2003 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.
 
 (defgeneric fmt-cui (c))
 (defmethod fmt-cui ((c ucon))
-  (format nil "C~7,'0d" (cui c)))
+  (fmt-cui (cui c)))
 
 (defmethod fmt-cui ((c fixnum))
-  (format nil "C~7,'0d" c))
+  (prefixed-fixnum-string c #\C 7))
 
 (defmethod fmt-cui ((c string))
   (if (eql (aref c 0) #\C)
       c
-    (format nil "C~7,'0d" (parse-integer c))))
+      (fmt-cui (parse-integer c))))
 
 (defmethod fmt-cui ((c null))
   (format nil "nil"))
 
 (defgeneric fmt-lui (c))
 (defmethod fmt-lui ((l uterm))
-  (format nil "L~7,'0d" (lui l)))
+  (fmt-lui (lui l)))
 
 (defmethod fmt-lui ((l fixnum))
-  (format nil "L~7,'0d" l))
+  (prefixed-fixnum-string l #\L 7))
 
 (defmethod fmt-lui ((l string))
   (if (eql (aref l 0) #\L)
       l
-  (format nil "L~7,'0d" (parse-integer l))))
+      (fmt-lui (parse-integer l))))
 
 (defgeneric fmt-sui (s))
 (defmethod fmt-sui ((s ustr))
-  (format nil "S~7,'0d" (sui s)))
+  (fmt-sui (sui s)))
 
 (defmethod fmt-sui ((s fixnum))
-  (format nil "S~7,'0d" s))
+  (prefixed-fixnum-string s #\S 7))
 
 (defmethod fmt-sui ((s string))
   (if (eql (aref s 0) #\S)
       s
-  (format nil "S~7,'0d" (parse-integer s))))
+      (fmt-sui (parse-integer s))))
 
-(defgeneric fmt-tui (t))
-(defmethod fmt-tui ((s fixnum))
-  (format nil "T~3,'0d" s))
+(defgeneric fmt-tui (tui))
+(defmethod fmt-tui ((tui fixnum))
+  (prefixed-fixnum-string tui #\T 3))
 
-(defmethod fmt-tui ((s string))
-  (if (eql (aref s 0) #\T)
-      s
-  (format nil "T~3,'0d" (parse-integer s))))
+(defmethod fmt-tui ((tui string))
+  (if (eql (aref tui 0) #\T)
+      tui
+      (fmt-tui (parse-integer tui))))
 
 (defgeneric fmt-eui (e))
 (defmethod fmt-eui ((e fixnum))
-  (format nil "E~7,'0d" e))
+  (prefixed-fixnum-string e #\E 7))
 
 (defmethod fmt-eui ((e string))
   (if (eql (aref e 0) #\E)
       e
-    (format nil "E~7,'0d" (parse-integer e))))
+      (fmt-eui (parse-integer e))))
 
 (defmethod fmt-eui ((e null))
   (format nil "nil"))
 
+(defun cui-p (ui)
+  "Check if a string is a CUI"
+  (check-ui ui #\C 7))
+
+(defun lui-p (ui)
+  "Check if a string is a LUI"
+  (check-ui ui #\L 7))
+
+(defun sui-p (ui)
+  "Check if a string is a SUI"
+  (check-ui ui #\S 7))
+
+(defun tui-p (ui)
+  (check-ui ui #\T 3))
+
+(defun eui-p (ui)
+  (check-ui ui #\E 7))
+
+(defun check-ui (ui start-char len)
+  (when (and (stringp ui)
+            (= (length ui) (1+ len))
+            (char-equal start-char (schar ui 0))
+            (ignore-errors (parse-integer ui :start 1)))
+    t))
+
+
 ;;; Generic display functions
 
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (multiple-value-bind (is-english is-term) (english-term-p obj)
       (or (not is-term) is-english)))
 
-(defun print-umlsclass (obj &key (stream *standard-output*) (category :compact-text)
-                       (file-wrapper t) (english-only nil) (subobjects nil)
-                       (refvars nil))
-  (view obj :stream stream :category category :subobjects subobjects
+(defun print-umlsclass (obj &key (stream *standard-output*)
+                       (vid :compact-text)
+                       (file-wrapper nil) (english-only t) (subobjects nil)
+                       (refvars nil) (link-printer nil))
+  (view obj :stream stream :vid vid :subobjects subobjects
        :file-wrapper file-wrapper
        :filter (if english-only nil #'english-term-filter)
+       :link-printer link-printer
        :refvars refvars))
 
 (defmacro define-lookup-display (newfuncname lookup-func)
   "Defines functions for looking up and displaying objects"
-  `(defun ,newfuncname  (keyval &key (stream *standard-output*) (category :compact-text)
+  `(defun ,newfuncname  (keyval &key (stream *standard-output*) (vid :compact-text)
                         (file-wrapper t) (english-only nil) (subobjects nil))
      (let ((obj (funcall ,lookup-func keyval)))
-       (print-umlsclass obj :stream stream :category category
+       (print-umlsclass obj :stream stream :vid vid
                        :file-wrapper file-wrapper :english-only english-only
                        :subobjects subobjects)
        obj)))
   "Return the string for a ulo object"
   (find-string-sui (sui lo)))
 
-#+(or scl cmu)
+(defmethod pfstr ((uterm uterm))
+  "Return the preferred string for a uterm"
+  (dolist (ustr (s#str uterm))
+    (when (string= "PF" (stt ustr))
+      (return-from pfstr (str ustr)))))
+
+(defmethod pfstr ((ustr ustr))
+  "Return the preferred string for a ustr, which is the string itself"
+  (str ustr))
+
+(defun remove-non-english-terms (uterms)
+  (remove-if-not #'english-term-p uterms))
+
+(defun remove-english-terms (uterms)
+  (remove-if #'english-term-p uterms))
+
+
+(defvar +relationship-abbreviations+
+  '(("RB" "Broader" "has a broader relationship")
+    ("RN" "Narrower" "has a narrower relationship")
+    ("RO" "Other related" "has relationship other than synonymous, narrower, or broader")
+    ("RL" "Like" "the two concepts are similar or 'alike'.  In the current edition of the Metathesaurus, most relationships with this attribute are mappings provided by a source")
+    ("RQ" "Unspecified" "unspecified source asserted relatedness, possibly synonymous")
+    ("SY" "Source Synonymy" "source asserted synonymy")
+    ("PAR" "Parent" "has parent relationship in a Metathesaurus source vocabulary")
+    ("CHD" "Child" "has child relationship in a Metathesaurus source vocabulary")
+    ("SIB" "Sibling" "has sibling relationship in a Metathesaurus source vocabulary")
+    ("AQ" "Allowed" "is an allowed qualifier for a concept in a Metathesaurus source vocabulary")
+    ("QB" "Qualified" "can be qualified by a concept in a Metathesaurus source vocabulary")))
+
+(defvar *rel-info-table* (make-hash-table :size 30 :test 'equal))
+(defvar *is-rel-table-init* nil)
+(unless *is-rel-table-init*
+  (dolist (relinfo +relationship-abbreviations+)
+    (setf (gethash (string-downcase (car relinfo)) *rel-info-table*)
+      (cdr relinfo)))
+  (setq *is-rel-table-init* t))
+
+(defun rel-abbr-info (rel)
+  (nth-value 0 (gethash (string-downcase rel) *rel-info-table*)))
+
+
+#+(or scl)
 (dolist (c '(urank udef usat uso ucxt ustr ulo uterm usty urel ucoc uatx ucon uxw uxnw uxns lexterm labr lagr lcmp lmod lnom lprn lprp lspl ltrm ltyp lwd sdef sstr sstre1 sstre2 usrl))
     #+cmu
     (let ((cl (pcl:find-class c)))