r5181: *** empty log message ***
[umlisp.git] / class-support.lisp
index 09bca9126f99449ed0b8f49c25bc2d41ca2ec4d3..7614a1565902128339d2d121a92afca98266da19 100644 (file)
@@ -7,10 +7,10 @@
 ;;;; Author:       Kevin M. Rosenberg
 ;;;; Date Started: Apr 2000
 ;;;;
-;;;; $Id: class-support.lisp,v 1.6 2003/05/14 21:33:02 kevin Exp $
+;;;; $Id: class-support.lisp,v 1.14 2003/06/17 04:56:02 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.
 
 ;;; 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 8))
+  (prefixed-fixnum-string c #\C 7))
 
 (defmethod fmt-cui ((c string))
   (if (eql (aref c 0) #\C)
@@ -43,7 +41,7 @@
   (fmt-lui (lui l)))
 
 (defmethod fmt-lui ((l fixnum))
-  (prefixed-fixnum-string l #\L 8))
+  (prefixed-fixnum-string l #\L 7))
 
 (defmethod fmt-lui ((l string))
   (if (eql (aref l 0) #\L)
   (fmt-sui (sui s)))
 
 (defmethod fmt-sui ((s fixnum))
-  (prefixed-fixnum-string s #\S 8))
+  (prefixed-fixnum-string s #\S 7))
 
 (defmethod fmt-sui ((s string))
   (if (eql (aref s 0) #\S)
       s
       (fmt-sui (parse-integer s))))
 
-(defgeneric fmt-tui (t))
-(defmethod fmt-tui ((t fixnum))
-  (prefixed-fixnum-string t #\T 4))
+(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
-      (fmt-tui (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))
-  (prefixed-fixnum-string e #\E 8))
+  (prefixed-fixnum-string e #\E 7))
 
 (defmethod fmt-eui ((e string))
   (if (eql (aref e 0) #\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))
+(defun print-umlsclass (obj &key (stream *standard-output*)
+                       (category :compact-text)
+                       (file-wrapper nil) (english-only t) (subobjects nil)
+                       (refvars nil) (link-printer nil))
   (view obj :stream stream :category category :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)
   "Return the string for a ulo object"
   (find-string-sui (sui lo)))
 
+(defun uterm-pfstr (uterm)
+  "Return the preferred string for a uterm"
+  (dolist (ustr (s#str uterm))
+    (when (string= "PF" (stt ustr))
+      (return-from uterm-pfstr (str ustr)))))
+
+(defun remove-non-english-terms (uterms)
+  (remove-if-not #'english-term-p uterms))
+
+
 #+(or scl cmu)
 (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