;; Evaluate the following line. It will first load FCG, and then some predefined templates: ;; (asdf:operate 'asdf:load-op :root-templates) ;; Then evaluate the following lines: (in-package :fcg) (activate-monitor trace-fcg) (setf *constructions* (make-default-cxn-set)) ;; This will create a default construction-inventory. ;;;;; ------------------------------------------------------------------------------------- ;;;;; Example of a lexical construction. ;;;;; ------------------------------------------------------------------------------------- (def-construction mouse-lex (:label lex) ((root (tag ?the-meaning (meaning (== (mouse ?ref))))) ((J ?mouse-word) ?the-meaning (args (?ref)) (sem-cat ((sem-class identifier))))) <--> ((root (tag ?the-form (form (== (string ?mouse-word "mouse"))))) ((J ?mouse-word) ?the-form (syn-cat ((lex-class noun) (agreement ((person 3) (number sg)))))))) ;; Testing the construction: (parse '("mouse") *constructions*) (produce '((mouse x)) *constructions*) ;;;;; ------------------------------------------------------------------------------------- ;;;;; Using lexical templates ;;;;; ------------------------------------------------------------------------------------- ;; The following template builds a new lexical construction: (def-lex-skeleton mouse-lex :meaning (== (mouse ?ref)) :args (?ref) :string "mouse") ;; Testing the construction: (parse '("mouse") *constructions*) (produce '((mouse x)) *constructions*) ;; The following template modifies an existing construction: (def-lex-cat mouse-lex :sem-cat ((sem-class identifier)) :syn-cat ((lex-class noun) (agreement ((person 3) (number sg))))) ;; Lexical templates are typically wrapped into a def-lex-cxn environment, which performs some ;; safety checks in the background: (def-lex-cxn mouse-lex (def-lex-skeleton mouse-lex :meaning (== (mouse ?ref)) :args (?ref) :string "mouse") (def-lex-cat mouse-lex :sem-cat ((sem-class identifier)) :syn-cat ((lex-class noun) (agreement ((person 3) (number sg)))))) ;; By default, a construction is added to *constructions*. But you can also ;; specify yourself where to put it explicitly: (defparameter *my-construction-set* (make-default-cxn-set)) (def-lex-cxn mouse-lex :cxn-set *my-construction-set* (def-lex-skeleton mouse-lex :meaning (== (mouse ?ref)) :args (?ref) :string "mouse") (def-lex-cat mouse-lex :sem-cat ((sem-class identifier)) :syn-cat ((lex-class noun) (agreement ((person 3) (number sg)))))) ;; Let's define another word: (def-lex-cxn the-lex (def-lex-skeleton the-lex :meaning (== (identify-referent ?referent)) :args (?referent) :string "the") (def-lex-cat the-lex :sem-cat ((sem-class selector)) :syn-cat ((lex-class article) (syn-function determiner) (agreement ((person 3) (number ?number)))))) ;; And test parsing and production: (parse '("the" "mouse") *constructions*) (produce '((identify-referent x) (mouse x)) *constructions*) ;;;;; ------------------------------------------------------------------------------------- ;;;;; Using phrasal templates ;;;;; ------------------------------------------------------------------------------------- (def-phrasal-cxn DetNP-cxn ;; The template def-phrasal-skeleton will build the construction. The rule we want to ;; implement is (Sem: referring-expression -> selector identifier / Syn: NP -> Det Noun) (def-phrasal-skeleton DetNP-cxn :phrase (?np :form (== (meets ?determiner ?noun)) :sem-cat ((sem-function referring-expression)) :syn-cat ((phrase-type NP))) :constituents ((?determiner :sem-cat (==1 (sem-class selector)) :syn-cat (==1 (syn-function determiner))) (?noun :sem-cat (==1 (sem-class identifier)) :syn-cat (==1 (lex-class noun)))) :head ?noun) ;; This templates links the args-features of all units to each other: (def-phrasal-linking DetNP-cxn (?np :args (?ref)) (?determiner :args (?ref)) (?noun :args (?ref))) ;; This templates links the args-features of all units to each other: (def-phrasal-agreement DetNP-cxn :units (?np ?determiner ?noun) :syn-cat (==1 (agreement ?agreement)))) ;; Test parsing and production: (parse '("the" "mouse") *constructions*) (produce '((identify-referent x) (mouse x)) *constructions*) ;; For more examples: ;; /Babel2/sharing/root-templates/examples-lexical.lisp ;; /Babel2/sharing/root-templates/examples-phrasal.lisp