;;;;;; ############################################################## ;;;;;; ##### Lecture 4: Construction inventories ##### ;;;;;; ############################################################## ;;; Evaluate the following to load FCG (CTRL-X+E) and wait until ;;; loading is finished. (asdf:operate 'asdf:load-op :fcg) ;;; Also evaluate the following lines: (in-package :fcg) (activate-monitor trace-fcg) ;; You can now open a web browser ;; (preferrably Safari or Firefox) at ;; http://localhost:8000/ (defparameter *constructions* nil "We will use this parameter for storing a construction set") (defparameter *construction-network* nil "We will use this parameter for storing a construction network.") ;;; INTRODUCTION ;;; --------------------------------------------------------- ;;; In Fluid Construction Grammar, constructions are saved in ;;; construction inventories, either as a set or a network. When you ;;; create a new grammar, you subclass from the abstract construction ;;; set/network class, which is a subclass of the construction ;;; inventory class. ;;; 1. Construction sets ;;; -------------------------- ;;; A construction set contains a flat list of constructions, lacking ;;; any internal organization ;;; We start by creating a new grammar and save it to the ;;; *constructions* parameter: (setf *constructions* (make-instance 'construction-set)) ;; Inspect the new grammar in the FCG web interface: (add-element (make-html *constructions*)) ;; Now, our grammar is still empty, so let's create a number of ;; constructions that our grammar can host: (defparameter *joe-cxn* (make-cxn joe-cxn () ((root (tag ?meaning (meaning (== (joe ?x))))) ((J ?joe-word) ?meaning (sem-class person))) <--> ((root (tag ?form (form (== (string ?joe-word "joe"))))) ((J ?joe-word) ?form (cat proper-noun) (number sg) (person 3) (gender masc))))) (defparameter *mary-cxn* (make-cxn mary-cxn () ((root (tag ?meaning (meaning (== (mary ?x))))) ((J ?mary-word) ?meaning (sem-class person))) <--> ((root (tag ?form (form (== (string ?mary-word "mary"))))) ((J ?mary-word) ?form (cat proper-noun) (number sg) (person 3) (gender fem))))) ;; You can add the constructions to the grammar as follows: (add-cxn *joe-cxn* *constructions*) (add-cxn *mary-cxn* *constructions*) ;; And check the web interface again to see whether you were successful: (add-element (make-html *constructions*)) ;; Let's do some additional checks on the actual organization of our grammar: ;; 1) Check it's size: (size *constructions*) ;; 2) Check the actual list where the constructions are saved in: (constructions *constructions*) ;; 3) Are there already constructions in the trash? (trash *constructions*) ;; You can search for constructions as follows: (find-cxn 'joe-cxn *constructions*) ;; use construction name only (find-cxn *mary-cxn* *constructions*) ;; use complete construction ;; You can remove constructions from the set (destructive!): (delete-cxn *joe-cxn* *constructions* :key #'name) ;; Check the size of the grammar again. Is it smaller? (size *constructions*) ;; Did the deleted construction move to the trash? (trash *constructions*) ;; You can keep deleted constructions in the trash by using the ;; :move-to-trash keyword: (delete-cxn *mary-cxn* *constructions* :key #'name :move-to-trash t) (trash *constructions*) ;; Finally, to clear the full grammar, including the trash, use the ;; clear command: (clear *constructions*) ;;; 2. Construction networks ;;; -------------------------- ;; Instead of a set, we create a construction network now: (setf *construction-network* (make-instance 'construction-network)) (add-cxn *joe-cxn* *construction-network*) ;; A construction-node is a net-node that contains a ;; construction. This has-a relation is better than a is-a relation ;; since you might want to use the exact same construction in different ;; nets. (For example when you have a production and parsing net): (construction-nodes *construction-network*) ;; In the web interface, the network is displayed the same as before: (add-element (make-html *construction-network*)) ;; Let's add a construction for the proper nouns: (defparameter *proper-noun-cxn* (make-cxn proper-noun-cxn () ((root (tag ?meaning (meaning (== (individual-referent ?x))))) (?individual-word (sem-cat (==1 (sem-class person)))) ((J ?individual-word) (sem-cat (==1 (sem-function unique-identifier))) ?meaning)) <--> ((root) (?individual-word (syn-cat (==1 (cat proper-noun)))) ((J ?individual-word) (syn-cat (==1 (syn-function nominal))))))) (add-cxn *proper-noun-cxn* *construction-network*) ;; You can explicitly link constructions in a network: (link-constructions *joe-cxn* *proper-noun-cxn* 'inheritance *construction-network*) ;; A future lecture will be completely dedicated to network ;; processing, so you will learn much more about this organization and ;; how it can influence language processing later. ;; To visualize the relation between the linked constructions, we have ;; to load another system on top of the FCG system: (asdf:operate 'asdf:load-op :network-processing) ;; Evaluate this line and select option 1 in the window that pops up: (use-package :network-processing) (show-construction-network *construction-network*) ;;; 3. Configurations ;;; -------------------------- ;;; Configurations determine the behavior of the construction ;;; inventory in processing. By default, when you create a ;;; construction set, a whole range of configurations have been ;;; pre-set for you. You can check them as follows: (add-element (make-html (configuration *constructions*))) ;; Alternatively, you can simply click twice on your construction set ;; in the web interface. ;; To change the default configurations, you can use the ;; set-configuration function: (set-configuration *constructions* :parse-goal-tests '(:no-applicable-cxns)) (set-configuration *constructions* :production-goal-tests '(:no-applicable-cxns)) (set-configuration *constructions* :max-search-depth 100) ;; Check whether you were successful: (configuration *constructions*) (add-element (make-html (configuration *constructions*))) ;; You can also add a new configuration through set-configuration. ;; Your configuration will be pushed to the already existing list of ;; configurations: (set-configuration *constructions* :new-configuration t) (add-element (make-html (configuration *constructions*))) ;; To access configurations, you can use the get-configuration function: (get-configuration *constructions* :de-render-mode) ;; It returns two values: the actual value of the configuration key ;; asked for and a boolean that indicates whether this was a valid key: (get-configuration *constructions* :de-friender-mode) ;; not a valid key (get-configuration *constructions* :show-meaning/utterance) ;; valid key ;; Apart from configurations, a cxn-inventory also has data slot, ;; which can be accessed as follows: (blackboard *constructions*) ;; By default, this data blackboard is empty. The idea behind it is to ;; store meta information about the grammar in this place (e.g. when ;; it was created, which constructions were changed over time, etc.) (fields (blackboard *constructions*))