;;;
;;; First, load a number of LKB-specific settings; typically no need to look
;;; too closely here
;;;
(lkb-load-lisp (parent-directory) "Version.lsp" t)
(setf *grammar-directory* (parent-directory))
(lkb-load-lisp (this-directory) "globals.lsp")
(lkb-load-lisp (this-directory) "user-fns.lsp")
(load-lkb-preferences (this-directory) "user-prefs.lsp")

;;;
;;; Optionally, load a set of irregular morphological patterns
;;;
(load-irregular-spellings (lkb-pathname (parent-directory) "irregs.tab"))

;;;
;;; Now the core grammar: to preserve the fiction of separating the matrix 
;;; from language-specific parts, we recommend at least one additional file;
;;; larger grammars have ended up organizing files roughly by content, e.g.
;;; fundamental types (similar to what comes with the matrix already), types
;;; for constructions, lexical types, semantic types, etc.  If you have 
;;; multiple such files, there should be a line for each in the following.
;;; Here we have just included matrix.tdl and one other grammar file
;;; `my_language.tdl', which you might want to rename.
;;;
(read-tdl-type-files-aux
  (list 
   (lkb-pathname (parent-directory) "matrix.tdl")
;   (lkb-pathname (parent-directory) "transfer.tdl")
   (lkb-pathname (parent-directory) "ga.tdl")
;   (lkb-pathname (parent-directory) "labels.tdl")
;    (lkb-pathname (parent-directory) "ga-daem.tdl")
;   (lkb-pathname (parent-directory) "predsort.tdl")
;   (lkb-pathname (parent-directory) "constructions/syntactic.types.tdl")
;   (lkb-pathname (parent-directory) "constructions/semantic.types.tdl")
;   (lkb-pathname (parent-directory) "constructions/construction.types.tdl")
;   (lkb-pathname (parent-directory) "constructions/ga-construction.types.tdl")
))


;;;
;;; Next, the lexicon itself, instantiating (lexical) types of the grammar
;;; (some grammars with larger lexica organize them into multiple files).
;;;

  (or
   (handler-case
       (when (and *psql-lexicon-parameters*
	          (load-psql-lexicon-from-script))
	  (read-cached-sublex-if-available "lexicon-skip"
					   (list (lkb-pathname (parent-directory)
					   "lexdb.skip")))
          ;;;
          ;;; we must index the grammar rules before we can use the generator
          ;;;
          (index-lexical-rules)
          (index-grammar-rules)
	  t)
     (t () 
       (format t "~%; PSQL lexical database unavailable")
       nil))
       (read-cached-lex-if-available
	(list
	(lkb-pathname (parent-directory) "lexicon.tdl")
;;;	(lkb-pathname (parent-directory) "lexicon-daem.tdl")
	(lkb-pathname (parent-directory) "lexicon-eng.tdl")
;;;	(lkb-pathname (parent-directory) "constructions/lex.constr.ga.tdl")
	)))

;(read-tdl-lex-file-aux
(read-cached-lex-if-available
(list
   (lkb-pathname (parent-directory) "lexicon.tdl")
;;;   (lkb-pathname (parent-directory) "lexicon-daem.tdl")
   (lkb-pathname (parent-directory) "lexicon-eng.tdl")
;;;   (lkb-pathname (parent-directory) "constructions/lex.constr.ga.tdl")
))

;;;
;;; Finally, the grammar rules, lexical rules (given special treatment in the
;;; parser in that they can apply _prior_ to `inflectional' rules), and the
;;; `inflectional' rules themselves (rules with an associated orthographemic
;;; alternation of the surface string).
;;;
(read-tdl-grammar-file-aux (lkb-pathname (parent-directory) "rules.tdl"))
(read-tdl-lex-rule-file-aux (lkb-pathname (parent-directory) "lrules.tdl"))
(read-morph-file-aux (lkb-pathname (parent-directory) "irules.tdl"))
;;;(read-morph-file-aux (lkb-pathname (parent-directory) "inflr.tdl"))
;(read-morph-file-aux (lkb-pathname (parent-directory) "irules-all.tdl"))

;;;
;;; The `start symbol(s)' of the grammar.
;;;
(read-tdl-psort-file-aux (lkb-pathname (parent-directory) "roots.tdl"))

;;;

;;; Optionally, a set of types providing labels for nodes in parse trees
;;;
(read-tdl-parse-node-file-aux (lkb-pathname (parent-directory) "labels-nodes.tdl"))


  ;; if the preprocessor code is loaded (which it is by default)
  ;; load the finite state rules.  Documentation awaited
  #+:preprocessor
;;  (read-preprocessor (lkb-pathname (parent-directory) "preprocessor.fsr"))


;;;
;;; A few more LKB-specific settings, this time for MRS post-processing and
;;; generation; also, we always compute the generation index (while we have
;;; small lexica) in the hope that the generator will be used frequently.
;;;
(lkb-load-lisp (this-directory) "mrsglobals.lisp" t)
;(read-mrs-rule-file-aux (lkb-pathname (parent-directory) "transfer.mrs"))
;(index-for-generator)

