;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Sample grammar. ;; Borrowed/adapted from G. Gazdar and C. Mellish, ;; Natural Language Processing in Lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defparameter *start-symbol* 's) (defparameter *nonterminals* '(s vp np pp det n tv p)) (defparameter *rules* (list ;; Grammar rules (make-rule :mother 's :child1 'np :child2 'vp :prob 1) (make-rule :mother 'vp :child1 'tv :child2 'np :prob 0.5) (make-rule :mother 'vp :child1 'vp :child2 'vp :prob 0.1 ) (make-rule :mother 'vp :child1 'vp :child2 'pp :prob 0.3 ) (make-rule :mother 'np :child1 'det :child2 'n :prob 0.4 ) (make-rule :mother 'np :child1 'np :child2 'pp :prob 0.2) (make-rule :mother 'pp :child1 'p :child2 'np :prob 1))) (defparameter *lexicon* (list ;; Lexicon (make-lexeme :pos 'vp :form 'run :prob 0.1) (make-lexeme :pos 'det :form 'her :prob 1) (make-lexeme :pos 'np :form 'her :prob 0.2) (make-lexeme :pos 'np :form 'they :prob 0.2 ) (make-lexeme :pos 'n :form 'nurses :prob 0.25 ) (make-lexeme :pos 'tv :form 'nurses :prob 0.2) (make-lexeme :pos 'n :form 'book :prob 0.25) (make-lexeme :pos 'tv :form 'book :prob 0.2) (make-lexeme :pos 'n :form 'travel :prob 0.25) (make-lexeme :pos 'tv :form 'travel :prob 0.2) (make-lexeme :pos 'n :form 'report :prob 0.25) (make-lexeme :pos 'tv :form 'report :prob 0.2) (make-lexeme :pos 'tv :form 'hear :prob 0.2) (make-lexeme :pos 'tv :form 'see :prob 0.2) (make-lexeme :pos 'p :form 'on :prob 1)))