;;; Copyright (c) 2003--2004 ;;; John Carroll, Ann Copestake, Robert Malouf, Stephan Oepen; ;;; see `LICENSE' for conditions. (in-package :mrs) (defun def-rmrs-print-operations (class indentation stream) (make-instance class :indentation indentation :stream stream)) (defclass rmrs-output-type () ((indentation :initform 0 :initarg :indentation) (stream :initarg :stream) (nonewlines :initform nil))) (defmethod rmrs-output-error-fn ((rmrsout rmrs-output-type) rmrs-instance) (with-slots (stream) rmrsout (format stream "~%::: ~A is not an rmrs structure~%" rmrs-instance))) ;;; The XML situation is complicated because we've actually got to support ;;; three dtds ;;; ;;; rmrs.dtd is the main one for real rmrs's ;;; ;;; gram.dtd is for grammar rules and tag.dtd for the `lexicon' ;;; for RASP->RMRS. These have their own functions for the `outer' ;;; layers - for the inner parts, the differences are ;;; a) variables don't have separate id and type so are elements ;;; with no attributes ;;; b) notion of a semstruct and a hook - not found in `main' dtd ;;; ;;; xml rmrs-output-type class for rmrs.dtd ;;; (defclass xml (rmrs-output-type) ()) ;;; ;;; (defmethod rmrs-output-start-fn ((rmrsout xml) cfrom cto &optional surface ident) (with-slots (stream nonewlines) rmrsout (unless nonewlines (terpri stream)) (write-string " stream) (unless nonewlines (terpri stream)))) #| (format stream "~%~%" (or cfrom -1) (or cto -1) surface ident))) |# (defmethod rmrs-output-end-fn ((rmrsout xml)) (with-slots (stream nonewlines) rmrsout (unless nonewlines (terpri stream)) (write-string "" stream) (unless nonewlines (terpri stream)))) #| |# (defmethod rmrs-output-start-ep ((rmrsout xml) cfrom cto str) (with-slots (stream nonewlines) rmrsout ;;(format stream "~% stream))) (defun xml-escaped-output (string stream) (unless (stringp string) (setf string (string string))) (dolist (c (coerce string 'list)) (cond ((char= #\" c) (write-string """ stream)) ((char= #\' c) (write-string "'" stream)) ((char= #\& c) (write-string "&" stream)) ((char= #\< c) (write-string "<" stream)) ((char= #\> c) (write-string ">" stream)) (t (write-char c stream))))) #| |# (defmethod rmrs-output-realpred ((rmrsout xml) lemma pos sense) (with-slots (stream) rmrsout (write-string "" stream))) ;;; (defmethod rmrs-output-gpred ((rmrsout xml) pred) (with-slots (stream) rmrsout (if (dummy-pred-p pred) (write-string "" stream) (format stream "~(~a~)" pred)))) #| " stream))) (defmethod rmrs-output-start-extra ((rmrsout xml)) nil) (defmethod rmrs-output-extra-feat-val ((rmrsout xml) feat val) (with-slots (stream) rmrsout (format stream " ~(~a~)='~(~a~)'" feat (cond ((eql val '+) "plus") ((eql val '-) "minus") (t val))))) ;;; (defmethod rmrs-output-constant-fn ((rmrsout xml) constant) (with-slots (stream) rmrsout (write-string "" stream) (xml-escaped-output constant stream) (write-string "" stream))) (defmethod rmrs-output-end-ep ((rmrsout xml)) (with-slots (stream) rmrsout (write-string "" stream))) #| |# (defmethod rmrs-output-label ((rmrsout xml) label-id) (with-slots (stream) rmrsout (format stream "