(in-package "KPML")

;;; File: morphology-declarations.lisp
;;; KPML-0.8
;;; June 1995, John Bateman.
;;; IPSI.
;;;

;;;----------------------------------------------------------------------
;;; Individual languages can declare what kind of morphology they
;;; wish to use. The basic option is between systemicized and
;;; not systemicized.

;;; Code here is modelled exactly on ml-default-orderings.lisp. Could
;;; maybe be parameterized one fine day. Uses a list of three
;;; elements in the profiles instead of one of two.
;;;----------------------------------------------------------------------


;;; ----------------------------------------------------------------------
;;; Following allows languages to state a preference for whether
;;; morphology will be activated without doing it explicitly
;;; all the time...
;;; Is picked up in express.
;;; ----------------------------------------------------------------------

(defvar *language-morphology-profiles*
  '((:english  nil english-grammatical-features-to-lexical-feature)
    (:german   nil german-grammatical-features-to-lexical-feature)
    (:dutch    T   dutch-grammatical-features-to-lexical-feature)  
    (:french   T  french-grammatical-features-to-lexical-feature) 
    (:japanese nil nil)
    ))

;;; ----------------------------------------------------------------------
;;; 3.1+ addition suggested by Serge, making the loading of language
;;;      specific morphology code possible without messing with the
;;;      KPML code additions defaults...
;;; 3.2  Generator file info recorded properly so that it can be written
;;;      out when resources are saved.
;;; ----------------------------------------------------------------------

(defmacro DEFINE-LANGUAGE-MORPHOLOGY-REQUIREMENTS
  (&key (language nil)(systemicized nil)(generator-fn NIL)(generator-file nil))
  (if language
      `(let ((lg (intern (string ',language) :keyword)))
         ,(when generator-file `(load-morphology-generator-file lg ,generator-file))
         (setf *language-morphology-profiles*
               (merge-in-morphology-declaration 
                lg ,systemicized ',generator-fn ,generator-file 
		*language-morphology-profiles*)))
    (warning "Ill-formed morphology requirement definition!")))


(defun MERGE-IN-MORPHOLOGY-DECLARATION (lg systemicized? gen-fn gen-file profiles)
  (let ((modified-profiles nil)
	(consumed nil))
    (loop for lg-defaults in profiles
	  do
	  (cond ((eq (first lg-defaults) lg)
		 (push (list lg systemicized? gen-fn gen-file) modified-profiles)
		 (warning "Morphology profile for language " lg 
			  " being updated.")
		 (setf consumed t))
		(t
		 (push lg-defaults modified-profiles))))
    (unless consumed (push (list lg systemicized? gen-fn gen-file) modified-profiles))
    modified-profiles))


;;; ----------------------------------------------------------------------
;;; 3.1 addition...
;;;     3.2 note that the generator file should be taken from the
;;;         same directory as the properties.lisp file! We should
;;;         not do this by looking in the directory with the same
;;;         name as the language variety as we may have several 
;;;         in different directories, etc.
;;; ----------------------------------------------------------------------

(defun LOAD-MORPHOLOGY-GENERATOR-FILE (lg generator-file)
  (let* ((lg-name (string lg))
	 (directory-of-properties-file
	  (make-pathname 
	   :host (pathname-host cl-user::*load-truename*) 
	   :directory (pathname-directory cl-user::*load-truename*)))
	 #+ignore(lg-root-directory 
		  (pathname
		   (concatenate 
		    'string (namestring *root-of-resources*) 
		    lg-name (string *directory-delimiter*))))
         (generator-file-path 
	  (merge-pathnames directory-of-properties-file generator-file)))
    (if (open generator-file-path :direction :probe)
        (load generator-file-path)
      (warning "Requested generator file: " 
	       generator-file-path " for language " lg " not found."))))
