1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: umlisp -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: classes-support.lisp
6 ;;;; Purpose: Support for UMLisp classes
7 ;;;; Author: Kevin M. Rosenberg
8 ;;;; Date Started: Apr 2000
10 ;;;; $Id: class-support.lisp,v 1.16 2003/07/16 20:40:43 kevin Exp $
12 ;;;; This file, part of UMLisp, is
13 ;;;; Copyright (c) 2000-2003 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 ;;;; *************************************************************************
22 ;;; Formatting routines
24 (defgeneric fmt-cui (c))
25 (defmethod fmt-cui ((c ucon))
28 (defmethod fmt-cui ((c fixnum))
29 (prefixed-fixnum-string c #\C 7))
31 (defmethod fmt-cui ((c string))
32 (if (eql (aref c 0) #\C)
34 (fmt-cui (parse-integer c))))
36 (defmethod fmt-cui ((c null))
39 (defgeneric fmt-lui (c))
40 (defmethod fmt-lui ((l uterm))
43 (defmethod fmt-lui ((l fixnum))
44 (prefixed-fixnum-string l #\L 7))
46 (defmethod fmt-lui ((l string))
47 (if (eql (aref l 0) #\L)
49 (fmt-lui (parse-integer l))))
51 (defgeneric fmt-sui (s))
52 (defmethod fmt-sui ((s ustr))
55 (defmethod fmt-sui ((s fixnum))
56 (prefixed-fixnum-string s #\S 7))
58 (defmethod fmt-sui ((s string))
59 (if (eql (aref s 0) #\S)
61 (fmt-sui (parse-integer s))))
63 (defgeneric fmt-tui (tui))
64 (defmethod fmt-tui ((tui fixnum))
65 (prefixed-fixnum-string tui #\T 3))
67 (defmethod fmt-tui ((tui string))
68 (if (eql (aref tui 0) #\T)
70 (fmt-tui (parse-integer tui))))
72 (defgeneric fmt-eui (e))
73 (defmethod fmt-eui ((e fixnum))
74 (prefixed-fixnum-string e #\E 7))
76 (defmethod fmt-eui ((e string))
77 (if (eql (aref e 0) #\E)
79 (fmt-eui (parse-integer e))))
81 (defmethod fmt-eui ((e null))
85 "Check if a string is a CUI"
89 "Check if a string is a LUI"
93 "Check if a string is a SUI"
102 (defun check-ui (ui start-char len)
103 (when (and (stringp ui)
104 (= (length ui) (1+ len))
105 (char-equal start-char (schar ui 0))
106 (ignore-errors (parse-integer ui :start 1)))
110 ;;; Generic display functions
112 (eval-when (:compile-toplevel :load-toplevel :execute)
113 (defun english-term-p (obj)
114 "Returns two values: T/NIL if term is english and T/NIL if obj is a TERM"
115 (if (eq (hyperobject::class-name (hyperobject::class-of obj)) 'uterm)
116 (values (string-equal (lat obj) "ENG") t)
119 (defun english-term-filter (obj)
120 "Retrns NIL if object is a term and not english"
121 (multiple-value-bind (is-english is-term) (english-term-p obj)
122 (or (not is-term) is-english)))
124 (defun print-umlsclass (obj &key (stream *standard-output*)
126 (file-wrapper nil) (english-only t) (subobjects nil)
127 (refvars nil) (link-printer nil))
128 (view obj :stream stream :vid vid :subobjects subobjects
129 :file-wrapper file-wrapper
130 :filter (if english-only nil #'english-term-filter)
131 :link-printer link-printer
134 (defmacro define-lookup-display (newfuncname lookup-func)
135 "Defines functions for looking up and displaying objects"
136 `(defun ,newfuncname (keyval &key (stream *standard-output*) (vid :compact-text)
137 (file-wrapper t) (english-only nil) (subobjects nil))
138 (let ((obj (funcall ,lookup-func keyval)))
139 (print-umlsclass obj :stream stream :vid vid
140 :file-wrapper file-wrapper :english-only english-only
141 :subobjects subobjects)
144 (define-lookup-display display-con #'find-ucon-cui)
145 (define-lookup-display display-term #'find-uterm-lui)
146 (define-lookup-display display-str #'find-ustr-sui)
148 (defun ucon-has-tui (ucon tui)
149 "Returns T if UCON has a semantic type of TUI."
150 (some #'(lambda (usty) (= tui (tui usty))) (s#sty ucon)))
152 (defgeneric suistr (lo))
153 (defmethod suistr ((lo ulo))
154 "Return the string for a ulo object"
155 (find-string-sui (sui lo)))
157 (defmethod pfstr ((uterm uterm))
158 "Return the preferred string for a uterm"
159 (dolist (ustr (s#str uterm))
160 (when (string= "PF" (stt ustr))
161 (return-from pfstr (str ustr)))))
163 (defun remove-non-english-terms (uterms)
164 (remove-if-not #'english-term-p uterms))
168 (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))
170 (let ((cl (pcl:find-class c)))
171 (pcl:finalize-inheritance cl))
173 (let ((cl (find-class c)))
174 (clos:finalize-inheritance cl)))