;;*************************************************************************
;;   
;;   EDIT THIS SECTION BEFORE YOU START
;;
;;
;;  Set the pathname appropriately to where the parser directory
;;   is located on your machine. All load functions within the parser
;;   use this function, so this is the only change require to set up the system.
;;  This is used to  maintain uniform code across different platforms
;;  This is cuirrently set for a UNIX system

;; >>>>>>>> CHANGE THE NEXT LINE TO BE YOUR OWN PATH <<<<<<<<<<<<<<<<<<<

(let ((*PATH* "/u/james/Code/DistribParser1.1/Parser1.1")
	;;   >>>> AND CHANGE THIS ONE TO BE THE FILE_SEPARATOR: "/" for unix, ":" for Mac
	(*FILE-SEPARATOR* "/"))

  ;;  LOADF takes one or two strings as arguments. If one string, it
  ;;  is a filename. If two, it is a directory and a file name,

  (defun loadf (id1 &optional id2)
    (if id2 
      (load (format nil "~a~a~a~a~a" 
	*PATH* *FILE-SEPARATOR* id1 *FILE-SEPARATOR* id2))
      (load (format nil "~a~a~a" *PATH* *FILE-SEPARATOR* id1))))
) ;; end scope of variable *PATH*

;;************************************************************************
;;
;;   LOADING THE PARSER


;;  This loads the bottom up parser

(Format t "~%~% Loading bottom up parser, Version 1.1~%~%")
(Format t "~%To load preset grammars and lexicons, call one of")
(Format t "~%  (LoadChapter4) (LoadChapter5) (LoadSection9-3) (LoadSection9-5)")
(Format t "~%  or (LoadSection9-6). For stochastic parsing examples, call (Loadchapt7)")

(loadf "Code" "chart")
(loadf "Code" "feats")
(loadf "Code" "gramlx")
(loadf "Code" "parser")
(loadf "Code" "print")
(loadf "Code" "stat")


(Format t "~%Loading Generator, Version 1.0~%  To test call (LoadSection9-7)")
(loadf "Code" "gen")

(defvar *lexicon4-6*)
(defvar *grammar4-5*)
(defvar *grammar4-7*)


(defun LoadChapter4 nil
  ;;  This loads the grammar handling features
  ;;   as described in Chapter 4
  ;;  plus the lexicon in Figure 4.4, the lexical grammar 4.5,
  ;;   and grammar 4.7.
  (no-probabilities)	
  (disablegaps)
  (disablesem)
  (loadf "Grams" "chapt4")
  (Format t "~% Loading Lexicon 4.6 and Grammars 4.5 and 4.7")
  (make-lexicon *lexicon4-6*)
  (make-grammar *grammar4-5*)
  (augment-grammar *grammar4-7*)
  (Format t "~% Words defined are ~%~s" (defined-words))
  T)

(defvar *lexicon5-2*)
(defvar *lexicon5-6*)
(defvar *grammar5-7*)
(defvar *grammar5-8*)
(defvar *grammar-RelClause*)
(defvar *lexicon-additions*)

(defun LoadChapter5 nil
  ;;  This loads the parser and lexicon for Chapter 5, and the lexicon for
  ;;   chapter 4  see grammars and lexicon in Grammars/Chapter5.
  
  ;; Turn on GAP processing
  (Format t "~% Loading Lexicon 4.6, 5.2, 5.6 plus addition words")
  (Format t "~% Loading Grammars 4.5, 5.7, 5.8 plus rules for relative clauses")
  
  (enableGaps)
  (no-probabilities)	
  (disablesem)
  (loadf "Grams" "chapt4")
  (loadf "Grams" "chapt5")
  (make-lexicon (append *lexicon4-6* 
                        (append *lexicon5-2* 
                                (append *lexicon5-6* *lexicon-additions*))))
  ;; Add general lexical rules
  (make-grammar *grammar4-5*)
  
  (augment-grammar *grammar5-7*)
  (augment-grammar *grammar5-8*)
  (augment-grammar *grammar-RelClause*)
  (Format t "~% Words defined are ~%~s" (defined-words))
  
  T)

(defvar *grammar9-3*)
(defvar *grammar9-4*)
(defvar *grammar9-7*)
(defvar *lexicon9-2*)
(defvar *lexicon-auxs*)

(defun LoadSection9-3 nil
  ;;  This loads the grammar and lexicon for Section 9.3
   ;;   see file Grams/chapt9
  
  (enableSem)
  (no-probabilities)	
  (disablegaps)

  (loadf "Grams" "chapt9")
  
  (Make-lexicon (append *lexicon9-2* 
                        (append *lexicon-auxs* *lexicon-additions*)))
  (make-grammar *grammar9-3*)
  (augment-grammar *grammar9-4*)
  (augment-grammar *grammar9-7*)
  (Format t "~%Loading Grams 9.3, 9.4 and 9.7 and lexicon 9.2 plus additional words")
  (Format t "~%Words defined are ~S " (defined-words))
  T)

(defvar *grammar9-10*)
(defvar *lexicon-whs*)


(defun LoadSection9-5 nil
  ;;  This loads the parser and lexicon for Section 9.5
  ;;   see file Grams/chapt9
  
  (enableSem)
  (enableGaps)
  (no-probabilities)	
 
  (loadf "Grams" "chapt9")
  
  (Make-lexicon (append *lexicon9-2* 
                        (append *lexicon-whs*
                                (append *lexicon-auxs* *lexicon-additions*))))
  
  (make-grammar *grammar9-3*)
  (augment-grammar *grammar9-4*)
  (augment-grammar *grammar9-7*)
  (augment-grammar *grammar9-10*)
  (Format t "~%Loading Grams 9.3, 9.4, 9.7 and 0.10, and lexicon 9.2 plus additional words")
  (Format t "~%Words defined are ~S " (defined-words))
 
  T
  )

(defvar *grammar9-13*)

(defun LoadSection9-6 nil
  ;;  This loads the parser and lexicon for Section 9.6
  ;;  see file Grams/chapt9
  
  (enableSem)
  
  (loadf "Grams" "chapt9")
  (no-probabilities)	
 
  (Make-lexicon (append *lexicon9-2* 
                        (append *lexicon-auxs* *lexicon-additions*)))
  (make-grammar *grammar9-3*)
  (augment-grammar *grammar9-13*)
  (Format t "~%Loading grammars 9.3 and 9.13 and lexicon 9.2 plus additional words")
  (Format t "~%Words defined are ~S " (defined-words))
  T)

(defvar *grammar9-13plus*)

(defun LoadSection9-7 nil
  ;;  This loads the grammars for Section 9.7
 
  (Format t "~%Loading grammars 9.3 and 9.13 and lexicon 9.2 plus additional words")
  (Format t "~%   for test cases see vars *test1* and *test2*")
  (format t "~% To invoke, call the function WORDS. e.g., (words *test1*)")

  (enableSem)
  (no-probabilities)	
  (loadf "Grams" "chapt9")
  
  (Make-lexicon (append *lexicon9-2* 
                        (append *lexicon-whs*
                                (append *lexicon-auxs* *lexicon-additions*))))
  
  (make-grammar *grammar9-3*)
  (augment-grammar *grammar9-13*)
  (augment-grammar *grammar9-13plus*)
  (Format t "~%Words defined are ~S " (defined-words))
  T)

(defvar *test1*
      (make-constit :cat 'S
                    :feats '((INV -)
                             (SEM 
                              ((UNSCOPED PAST SEES1) V17 
                               (NAME V13 JILL) (UNSCOPED THE V20 (DOG1 V20)))))))

(defvar *test2*
      (make-constit :cat 'S
                    :feats '((INV +) (SEM ((UNSCOPED PAST DO1) 
                                           (SEES1 V50 (NAME V49 JILL) 
                                                  (UNSCOPED THE V53 (DOG1 V53))))))))

;; STAT PARSER


(defvar *lexicon7*)
(defvar *grammar7-17*)

(defun LoadChapter7 nil
  ;; disable gaps and sem features to simplify the examples. The system works
  ;;  with them enabled
  
  (disablegaps)
  (disablesem)
  
  (Format t "~% Loading Grammar 7.17  and chapter 7 lexicon")
  (Format t "~% New Settings: Stop on first S found, use context-free probabilities")
  (loadf "Grams" "chapt7")
  (make-lexicon *lexicon7*)
  (make-grammar *grammar7-17*)
  (loadf "Grams" "stats")
  (use-cf-probabilities)
  (set-best-only)
 (Format t "~%Words defined are ~S " (defined-words))
 
  t)

T
