;;; -*- Mode: LISP; Syntax: Common-Lisp; Package: LKB -*-

(unless (lkb-version-after-p "2006/07/05 12:00:00")
  (error "this version of the ERG requires an LKB version >= 2006/07/05"))
  
(set-coding-system utf-8)

(unless (member :arboretum *features*) (push :arboretum *features*))

(time
 (progn
  (lkb-load-lisp (parent-directory) "Version.lsp" t nil)
  (setf *grammar-directory* (parent-directory))
  (load-lkb-preferences (this-directory) "user-prefs.lsp")
  (lkb-load-lisp (this-directory) "globals.lsp" nil nil)
  (lkb-load-lisp (this-directory) "user-fns.lsp" nil nil)
  (lkb-load-lisp (this-directory) "checkpaths.lsp" t nil)
  (lkb-load-lisp (this-directory) "patches.lsp" t nil)
  #+:speech
  (lkb-load-lisp (this-directory) "convert-wcn.lsp" t nil)
  (load-irregular-spellings 
   (list
    (lkb-pathname (parent-directory) "irregs.tab")))
  (read-tdl-type-files-aux
   (list (lkb-pathname (parent-directory) "fundamentals.tdl")
         (lkb-pathname (parent-directory) "tmt.tdl")
         (lkb-pathname (parent-directory) "lextypes.tdl")
         (lkb-pathname (parent-directory) "syntax.tdl")
         #+:speech
         (lkb-pathname (parent-directory) "syntax-speech.tdl")
         (lkb-pathname (parent-directory) "lexrules.tdl")
         (lkb-pathname (parent-directory) "auxverbs.tdl")
         (lkb-pathname (parent-directory) "educ/lextypes-epgy.tdl")
         #+:arboretum
	 (lkb-pathname (parent-directory) "arboretum/mal-types.tdl")
         #+:mt
         (lkb-pathname (parent-directory) "mtr.tdl")
         )
   (lkb-pathname (this-directory) "settings.lsp"))
  (read-cached-leaf-types-if-available
   (list (lkb-pathname (parent-directory) "letypes.tdl")
         #+:arboretum
         (lkb-pathname (parent-directory) "arboretum/mal-letypes.tdl")))

  (if nil ;(and (boundp '*lexdb-params*) *lexdb-params*)
      (progn
	(load-lexdb-from-script)
	(read-cached-sublex-if-available 
	"gle" (lkb-pathname (parent-directory) "gle.tdl"))
	)
    (read-cached-lex-if-available 
     (list
      (lkb-pathname (parent-directory) "lexicon.tdl")
      (lkb-pathname (parent-directory) "educ/lexicon-epgy.tdl")
      (lkb-pathname (parent-directory) "gle.tdl")
      #+:arboretum
      (lkb-pathname (parent-directory) "arboretum/mal-lex.tdl")
      )))

  (read-tdl-grammar-file-aux 
   (lkb-pathname (parent-directory) "educ/constr-epgy.tdl"))
  #+:speech
  (read-tdl-grammar-file-aux 
   (lkb-pathname (parent-directory) "constr-speech.tdl"))
  #+:arboretum
  (read-tdl-grammar-file-aux 
   (lkb-pathname (parent-directory) "arboretum/mal-constructions.tdl"))

  (read-morph-file-aux (lkb-pathname (parent-directory) "inflr.tdl"))
  (read-morph-file-aux (lkb-pathname (parent-directory) "inflr-pnct.tdl"))
  #+:arboretum
  (read-morph-file-aux (lkb-pathname (parent-directory) "arboretum/mal-inflr.tdl"))
  (read-tdl-psort-file-aux 
   (lkb-pathname (parent-directory) "roots.tdl"))

  (read-tdl-lex-rule-file-aux 
   (lkb-pathname (parent-directory) "educ/lexrinst-epgy.tdl"))
  (read-tdl-parse-node-file-aux 
   (lkb-pathname (parent-directory) "parse-nodes.tdl"))

  (lkb-load-lisp (this-directory) "mrsglobals.lsp" t nil)
  #+:tsdb
  (lkb-load-lisp (parent-directory "www") "setup.lsp" t nil)
 
  #+:arboretum  
  (lkb-load-lisp (system:getenv "DELPHINHOME") "lkb/src/graft/arboretum.lsp" t nil)
  #+:arboretum  
  (lkb-load-lisp (parent-directory) "arboretum/errordesc.lsp" t nil)))

;;;
;;; the Regular Expression Pre-Processor (REPP) is now broken up into quite a
;;; number of files.  to ease re-use across the LKB and PET, keep the REPP 
;;; configuration in a separate file.
;;;
(lkb-load-lisp (parent-directory "rpp") "setup.lsp" t nil)

;;;
;;; when loaded into an environment including [incr tsdb()] and the Redwoods
;;; tools, also load a Maximum Entropy realization ranking model and activate
;;; selective unpacking (for generation).
;;;
#+(and :tsdb :logon)
(tsdb::read-model (lkb-pathname (parent-directory) "jhpstg.g.mem"))
#+(and :tsdb :logon)
(setf *unpacking-scoring-hook* #'tsdb::mem-score-configuration)

;;;
;;; the semantic interface (SEM-I), used only in batch testing (for now)
;;;
#+:logon
(mt:read-semi (lkb-pathname (parent-directory) "erg.smi"))

;;;
;;; the mapping from grammar-internal to SEM-I compliant variable properties
;;;
(mt:read-vpm (lkb-pathname (parent-directory) "semi.vpm") :semi)
;;;
;;; another variable property mapping, used only when constructing the SEM-I
;;;
(mt:read-vpm (lkb-pathname (parent-directory) "abstract.vpm") :abstract)


;;;
;;; finally, use the new transfer component: load any number of rule sets, each
;;; in a separate file, associated with its identifier.  
;;;
(lkb-load-lisp (this-directory) "mt.lsp" t nil)

;;;
;;; the following two rule sets could possibly be merged at some point, but
;;; for right now dan prefers keeping them separate.            (3-may-05; oe)
;;;
(mt:read-transfer-rules 
 (list
  (lkb-pathname (parent-directory) "paraphraser.mtr")
  (lkb-pathname (parent-directory) "educ.mtr"))
 "MWE Paraphraser"
 :before "mrs::normalize-mrs" :filter nil :task :paraphrase)

(mt:read-transfer-rules 
 (list
  (lkb-pathname (parent-directory) "idioms.mtr"))
 "Idiom Tests"
 :filter nil :task :idiom)

(mt:read-transfer-rules 
 (list
  (lkb-pathname (parent-directory) "trigger.mtr"))
 "Generation Trigger Rules"
 :filter nil :task :trigger :recurse nil :edges 200 :subsume nil)

(mt:read-transfer-rules 
 (list
  (lkb-pathname (parent-directory) "generation.mtr"))
 "Generation Input Fix-Up Rules"
 :filter nil :task :comply :edges 200)

#+:null
(mt:read-transfer-rules 
 (list
  (lkb-pathname (parent-directory) "cluster.mtr"))
 "Cluster Normalizer"
 :filter nil :task :paraphrase)

#+:null
(mt:read-transfer-rules 
 (list
  (lkb-pathname (parent-directory) "semiout.mtr"))
 "SEMI example generator"
 :filter nil :task :paraphrase :recurse nil :subsume t)

(setf tsdb::*tsdb-maximal-number-of-analyses* 1)
(setf tsdb::*tsdb-maximal-number-of-results* 1)