r11704: can not use keywords in :subobject functions
[umlisp.git] / class-support.lisp
index a085828956576010adfb476ebf66fd5a30da0af6..e4f49cbcedeb36749d18008bfc56036fbd937dc7 100644 (file)
@@ -2,15 +2,15 @@
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
-;;;; Name:         classes-support.lisp
-;;;; Purpose:      Support for UMLisp classes
-;;;; Author:       Kevin M. Rosenberg
-;;;; Date Started: Apr 2000
+;;;; Name:     classes-support.lisp
+;;;; Purpose:  Support for UMLisp classes
+;;;; Author:   Kevin M. Rosenberg
+;;;; Created:  Apr 2000
 ;;;;
-;;;; $Id: class-support.lisp,v 1.19 2003/07/21 08:41:44 kevin Exp $
+;;;; $Id$
 ;;;;
 ;;;; This file, part of UMLisp, is
-;;;;    Copyright (c) 2000-2003 by Kevin M. Rosenberg, M.D.
+;;;;    Copyright (c) 2000-2006 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.
 
 (in-package #:umlisp)
 
-
 ;;; Formatting routines
 
 (defgeneric fmt-cui (c))
 (defmethod fmt-cui ((c ucon))
   (fmt-cui (cui c)))
 
-(defmethod fmt-cui ((c fixnum))
-  (prefixed-fixnum-string c #\C 7))
+(when *has-fixnum-class*
+  (defmethod fmt-cui ((c fixnum))
+    (prefixed-fixnum-string c #\C 7)))
+
+(defmethod fmt-cui ((c integer))
+    (prefixed-integer-string c #\C 7))
 
 (defmethod fmt-cui ((c string))
   (if (eql (aref c 0) #\C)
 (defmethod fmt-lui ((l uterm))
   (fmt-lui (lui l)))
 
-(defmethod fmt-lui ((l fixnum))
-  (prefixed-fixnum-string l #\L 7))
+(when *has-fixnum-class*
+  (defmethod fmt-lui ((l fixnum))
+    (prefixed-fixnum-string l #\L 7)))
+
+(defmethod fmt-lui ((l integer))
+  (prefixed-integer-string l #\L 7))
 
 (defmethod fmt-lui ((l string))
   (if (eql (aref l 0) #\L)
 (defmethod fmt-sui ((s ustr))
   (fmt-sui (sui s)))
 
-(defmethod fmt-sui ((s fixnum))
-  (prefixed-fixnum-string s #\S 7))
+(when *has-fixnum-class*
+  (defmethod fmt-sui ((s fixnum))
+    (prefixed-fixnum-string s #\S 7)))
+
+(defmethod fmt-sui ((s integer))
+  (prefixed-integer-string s #\S 7))
 
 (defmethod fmt-sui ((s string))
   (if (eql (aref s 0) #\S)
       (fmt-sui (parse-integer s))))
 
 (defgeneric fmt-tui (tui))
-(defmethod fmt-tui ((tui fixnum))
-  (prefixed-fixnum-string tui #\T 3))
+(when *has-fixnum-class*
+  (defmethod fmt-tui ((tui fixnum))
+    (prefixed-fixnum-string tui #\T 3)))
+
+(defmethod fmt-tui ((tui integer))
+  (prefixed-integer-string tui #\T 3))
 
 (defmethod fmt-tui ((tui string))
   (if (eql (aref tui 0) #\T)
       tui
-      (fmt-tui (parse-integer tui))))
+    (fmt-tui (parse-integer tui))))
+
+(defgeneric fmt-aui (aui))
+(when *has-fixnum-class*
+  (defmethod fmt-aui ((aui fixnum))
+    (if (>= aui 10000000)
+      (prefixed-fixnum-string aui #\A 8)
+      (prefixed-fixnum-string aui #\A 7))))
+
+(defmethod fmt-aui ((aui integer))
+  (if (>= aui 10000000)
+    (prefixed-integer-string aui #\A 8)
+    (prefixed-integer-string aui #\A 7)))
+
+(defmethod fmt-aui ((aui string))
+  (if (eql (aref aui 0) #\A)
+      aui
+      (fmt-aui (parse-integer aui))))
+
+(defgeneric fmt-rui (rui))
+(when *has-fixnum-class*
+  (defmethod fmt-rui ((rui fixnum))
+    (prefixed-fixnum-string rui #\A 8)))
+
+(defmethod fmt-rui ((rui integer))
+  (prefixed-integer-string rui #\A 8))
+
+(defmethod fmt-rui ((rui string))
+  (if (eql (aref rui 0) #\R)
+      rui
+    (fmt-rui (parse-integer rui))))
 
 (defgeneric fmt-eui (e))
-(defmethod fmt-eui ((e fixnum))
-  (prefixed-fixnum-string e #\E 7))
+(when *has-fixnum-class*
+  (defmethod fmt-eui ((e fixnum))
+    (prefixed-fixnum-string e #\E 7)))
+
+(defmethod fmt-eui ((e integer))
+  (prefixed-integer-string e #\E 7))
 
 (defmethod fmt-eui ((e string))
   (if (eql (aref e 0) #\E)
   "Returns T if UCON has a semantic type of TUI."
   (some #'(lambda (usty) (= tui (tui usty))) (s#sty ucon)))
 
-(defgeneric suistr (lo))
-(defmethod suistr ((lo ulo))
-  "Return the string for a ulo object"
-  (find-string-sui (sui lo)))
-
 (defgeneric pf-ustr (obj))
 (defmethod pf-ustr ((ucon ucon))
   "Return the preferred ustr for a ucon"
 
 (defmethod mesh-number ((ustr ustr))
   (let ((codes
-        (filter (lambda (sat)
-                  (when (and (string-equal "MSH" (sab sat))
-                             (string-equal "MN" (atn sat)))
-                    (atv sat)))
-                (s#sat ustr))))
+        (map-and-remove-nils
+         (lambda (sat)
+           (when (and (string-equal "MSH" (sab sat))
+                      (string-equal "MN" (atn sat)))
+             (atv sat)))
+         (s#sat ustr))))
     (if (= 1 (length codes))
        (car codes)
       codes)))
     (dolist (term (s#term ucon) (nreverse res))
       (dolist (str (s#str term))
        (push str res)))))
-                    
+
 
 (defmethod pfstr ((uterm uterm))
   "Return the preferred string for a uterm"
 
 
 (defvar +language-abbreviations+
-  '(("BAQ" . "Basque")
-    ("DAN" . "Danish")
-    ("DUT" . "Dutch")
-    ("ENG" . "English")
-    ("FIN" . "Finnish")
-    ("FRE" . "French")
-    ("GER" . "German")
-    ("HEB" . "Hebrew")
-    ("HUN" . "Hungarian")
-    ("ITA" . "Italian")
-    ("NOR" . "Norwegian")
-    ("POR" . "Portuguese")
-    ("RUS" . "Russian")
-    ("SPA" . "Spanish")
-    ("SWE" . "Swedish")))
+    '(("BAQ" . "Basque")
+      ("CZE" . "Chech")
+      ("DAN" . "Danish")
+      ("DUT" . "Dutch")
+      ("ENG" . "English")
+      ("FIN" . "Finnish")
+      ("FRE" . "French")
+      ("GER" . "German")
+      ("HEB" . "Hebrew")
+      ("HUN" . "Hungarian")
+      ("ITA" . "Italian")
+      ("JPN" . "Japanese")
+      ("NOR" . "Norwegian")
+      ("POR" . "Portuguese")
+      ("RUS" . "Russian")
+      ("SPA" . "Spanish")
+      ("SWE" . "Swedish")))
 
 (defvar *lat-info-table* (make-hash-table :size 30 :test 'equal))
 (defvar *is-lat-table-init* nil)
   (setq *is-lat-table-init* t))
 
 (defun lat-abbr-info (lat)
-  (nth-value 0 (gethash (string-downcase lat) *lat-info-table*)))
+  (aif (nth-value 0 (gethash (string-downcase lat) *lat-info-table*))
+       it
+       lat))
+
 
 
 (defun stt-abbr-info (stt)
         ((char-equal #\O c)
          "Other"))))
 
-           
-(defun ucon-parents (con &optional sab)
-  (ucon-ancestors con sab t))
-
-(defun ucon-ancestors (ucon &optional sab single-level)
-  "Returns a list of ancestor lists for a concept"
-  (let* ((parent-rels (filter-urels-by-rel (s#rel ucon) "par"))
-        (anc nil))
-    (when sab
-      (setq parent-rels (delete-if-not 
-                        (lambda (rel) (string-equal sab (sab rel)))
-                        parent-rels)))
-    (dolist (rel parent-rels (nreverse anc))
-      (let ((parent (find-ucon-cui (cui2 rel))))
-       (push
-        (if single-level
-            (list parent)
-          (list* parent (car (ucon-ancestors parent (sab rel) nil))))
-        anc)))))
-
-(defgeneric cxt-ancestors (obj))
-(defmethod cxt-ancestors ((con ucon))
-  (loop for term in (s#term con)
-      append (cxt-ancestors term)))
-                   
-
-(defmethod cxt-ancestors ((term uterm))
-  (loop for str in (s#str term)
-      append (cxt-ancestors str)))
-    
-(defmethod cxt-ancestors ((str ustr))
-  "Return the ancestory contexts of a ustr"
-  (let* ((anc (remove-if-not
-              (lambda (cxt) (string-equal "ANC" (cxl cxt)))
-              (s#cxt str)))
-        (num-contexts (if anc
-                          (apply #'max (mapcar (lambda (cxt) (cxn cxt)) anc))
-                        0))
-        (anc-lists '()))
-    (dotimes (i num-contexts (nreverse anc-lists))
-      (let* ((anc-this-cxn (remove-if-not
-                           (lambda (cxt) (= (1+ i) (cxn cxt))) anc)))
-       (push
-        (sort anc-this-cxn (lambda (a b) (< (rnk a) (rnk b))))
-        anc-lists)))))
-
-  
+(defun uso-unique-codes (usos)
+  (let ((sab-codes (make-hash-table :test 'equal)))
+    (dolist (uso usos)
+      (setf (gethash (sab uso) sab-codes) (code uso)))
+    (loop for key being the hash-key in sab-codes
+        collect (list key (gethash key sab-codes)))))
+
+(defun ucon-has-sab (ucon sab)
+  (and (find-if (lambda (uso) (string-equal sab (sab uso))) (s#so ucon)) t))
+
+
 #+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))
+(dolist (c '(urank udef usat uso ucxt ustr uterm usty urel ucoc uatx uconso uxw uxnw uxns lexterm labr lagr lcmp lmod lnom lprn lprp lspl ltrm ltyp lwd sdef sstr sstre1 sstre2 usrl))
     (let ((cl (find-class c)))
       (clos:finalize-inheritance cl)))