-
Notifications
You must be signed in to change notification settings - Fork 1
/
load-and-save.lisp
executable file
·178 lines (151 loc) · 6.53 KB
/
load-and-save.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
;;; Copyright (C) 2019-present Sony Computer Science Laboratories Paris
;;; Remi van Trijp (www.remivantrijp.eu)
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, version 3 of the License.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; ----------------------------------------------------------------------------
(in-package :beng)
;;;;;; Loading utilities.
;;;;;; ----------------------------------------------------------------
(defun lex-directory (lex-class)
(remove-if-not #'(lambda(p)
(string= "lisp" (pathname-type p)))
(directory (beng-pathname :directory (list "lexicon" lex-class)))))
(defun grammar-directory (class)
(remove-if-not #'(lambda(p)
(string= "lisp" (pathname-type p)))
(directory (beng-pathname :directory (list "grammar" class)))))
(defun idioms-directory ()
(remove-if-not #'(lambda(p)
(string= "lisp" (pathname-type p)))
(directory (beng-pathname :directory (list "idioms")))))
(defun load-idioms ()
(loop for path in (idioms-directory)
do (load path)))
(defun load-lexical-constructions (lex-class)
(loop for path in (lex-directory lex-class)
do (load path)))
(defun load-lexicon (&optional (lex-classes '("adjectives"
"adverbs"
"auxiliaries"
"determiners"
"meta"
"nationalities"
"nouns"
"prepositions"
"pronouns"
"verbs")))
(with-disabled-monitors
(loop for lex-class in lex-classes
do (load-lexical-constructions lex-class))))
(defun load-adjective (word)
(load (beng-pathname :directory '("lexicon" "adjectives")
:name word
:type "lisp")))
(defun load-adverb (word)
(load (beng-pathname :directory '("lexicon" "adverbs")
:name word
:type "lisp")))
(defun load-nationality (word)
(load (beng-pathname :directory '("lexicon" "nationalities")
:name word
:type "lisp")))
(defun load-noun (word)
(load (beng-pathname :directory '("lexicon" "nouns")
:name word
:type "lisp")))
(defun load-preposition (word)
(load (beng-pathname :directory '("lexicon" "prepositions")
:name word
:type "lisp")))
(defun load-verb (word)
(load (beng-pathname :directory '("lexicon" "verbs")
:name word
:type "lisp")))
(defun load-auxiliary (word)
(load (beng-pathname :directory '("lexicon" "auxiliaries")
:name word
:type "lisp")))
(defun load-articles ()
(load (beng-pathname :directory '("lexicon" "determiners")
:name "articles"
:type "lisp")))
;; (load-articles)
(defun load-quantifiers ()
(load (beng-pathname :directory '("lexicon" "determiners")
:name "quantifiers"
:type "lisp")))
;; (load-quantifiers)
(defun load-possessive-pronouns ()
(load (beng-pathname :directory '("lexicon" "determiners")
:name "possessive-pronouns"
:type "lisp")))
;; (load-possessive-pronouns)
(defun load-demonstratives ()
(load (beng-pathname :directory '("lexicon" "determiners")
:name "demonstratives"
:type "lisp")))
;; (load-demonstratives)
(defun load-determiners ()
(load-lexicon '("determiners")))
;; (load-determiners)
(defun load-grammatical-constructions (class)
(loop for path in (grammar-directory class)
do (load path)))
(defun load-grammar (&optional (classes '("referring-expressions"
"argument-structure")))
;;"tam"
;;"voice")))
(with-disabled-monitors
(loop for class in classes
do (load-grammatical-constructions class))))
;; (load-grammar)
;;;;;; Writing the lexicon.
;;;;;; ----------------------------------------------------------------
(defun write-lexicon ()
(write-adjectives)
(write-adverbs)
(write-nationalities)
(write-nouns)
(write-prepositions)
(write-verbs))
;; (write-lexicon)
;;;;;; Build a grammar.
;;;;;; ----------------------------------------------------------------
(defun build-grammar (&key (write-files? t))
"For writing and loading constructions. Only use after instantiating a construction inventory."
(with-disabled-monitors
(when write-files?
(format t "~%Writing constructional definitions (this may take a few seconds)...")
(write-lexicon))
(make-beng-cxns)
(load-lexicon)
(load-idioms)
(load-grammar)
(set-data (blackboard *fcg-constructions*) :fusion-hierarchy *fusion-hierarchy*)
*fcg-constructions*))
;; (build-grammar)
;; (comprehend "the window broke")
;;;;;; Make and store an English lexicon image
;;;;;; ----------------------------------------------------------------
(defun save-beng (grammar &key (directory '("models"))
(name "beng")
(type "lisp"))
"Stores the grammar 'grammar' in path 'file-path'"
(let ((path (beng-pathname :directory directory :name name :type type)))
(cl-store:store grammar path)))
;; (save-beng *fcg-constructions* :name "beng-only-lexicon")
(defun restore-beng (&key (name "beng") (directory '("models")) (type "lisp"))
"Loads and returns the grammar 'grammar' in path 'file-path'"
(let ((path (beng-pathname :directory directory :name name :type type)))
(cl-store:restore path)))
;; (restore-beng :name "beng")