-
Notifications
You must be signed in to change notification settings - Fork 1
/
new-ulf-test1.lisp
217 lines (167 loc) · 5.39 KB
/
new-ulf-test1.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
(declaim (sb-ext:muffle-conditions cl:warning))
(load "ll-load.lisp")
(ll-load "new-ulf-parser.lisp")
(ll-load-subdir "stories" "roc-mcguffey-stories.lisp")
(ll-load-subdir "stories" "school-roc-stories.lisp")
(ll-load-subdir "parse-webpage" "collapse-html.lisp")
; (dbg-tag 'coref)
; (setf *random-state* (make-random-state t))
(defparameter *PRINT-OUTPUT* t)
(defparameter *USE-DEBUG-STORIES* nil)
(defparameter *SHUFFLE-STORIES* t)
(defparameter *HANDLE-ERRORS* t)
(defparameter *PRINT-VALID-SENTS* t)
(defparameter *PRINT-INVALID-SENTS* t)
(defparameter *FILTER-INVISIBLE-PREDS* t)
(defparameter *TEST-NO-POSTPROC* t)
(defparameter *STORY-START* 151)
(defparameter *STORY-LIMIT* 50)
; (defparameter *STORY-LIMIT* 3)
; (setf stories *MCGUFFEY*)
(setf stories *ROC*)
; (setf stories *ROC-MCGUFFEY*)
(if *PRINT-OUTPUT*
(dbg-tag 'ulf-html)
)
(if *USE-DEBUG-STORIES*
; then
(setf stories '((
"The man folded the clothes."
"He put them away."
"The next day they were gone."
"He went to look for them."
"Yesterday he saw them."
"His wife was refolding them."
)))
)
(if *SHUFFLE-STORIES*
; then
(setf stories (shuffle stories))
)
(if (not (null *STORY-LIMIT*))
(setf stories (subseq stories *STORY-START* (min (length stories) (+ *STORY-START* *STORY-LIMIT*))))
)
(format t "~s~%" (length stories))
(ldefun invisible? (wff)
(let ((pred (prop-pred wff)))
(or
(equal pred 'HAS-DET.PR)
(equal pred 'ORIENTS)
)
)
)
(ldefun print-story-wffs (story)
(block outer
(setf sent-trees (list))
; (setf sents (len-parse-sents story))
; (setf ulf-el-sents (len-ulfs-and-els story))
; (setf ulf-sents (mapcar #'car ulf-el-sents))
; (setf sents (mapcar #'second ulf-el-sents))
(setf parser-full-output (full-debug-sents story))
(setf pso parser-full-output) ; shorthand
(setf raw-len-ulfs (nth 0 pso))
(setf ulf-sents (nth 1 pso))
(setf raw-interps (nth 2 pso))
(setf cleaned-interps (nth 3 pso))
(setf resolved-interps (nth 4 pso))
(setf no-idx-interps (nth 5 pso))
(setf sents (nth 6 pso))
(loop for eng-sent in story
for raw-ulf-sent in raw-len-ulfs
for ulf-sent in ulf-sents
for raw-el-sent in raw-interps
for cleaned-el-sent in cleaned-interps
for coref-el-sent in resolved-interps
for stripped-el-sent in no-idx-interps
for el-sent in sents
do (block wff-loop
(setf sent-tree (list eng-sent))
(format nil "~s~%" eng-sent)
(setf valid-wffs (list))
(setf invalid-wffs (list))
(setf target-sents el-sent)
(if *TEST-NO-POSTPROC*
(setf target-sents raw-el-sent))
(loop for wff in target-sents
if (canon-prop? wff)
do (setf valid-wffs (append valid-wffs (list wff)))
else
do (setf invalid-wffs (append invalid-wffs (list wff))))
(if (> (length invalid-wffs) 0)
; then
(setf sent-tree (append sent-tree (list nil)))
; else
(setf sent-tree (append sent-tree (list t)))
)
(setf parse-pair-tree (list))
(setf raw-ulf-tree (list "ULF (Len's parser's raw output)" raw-ulf-sent))
(setf parse-pair-tree (append parse-pair-tree (list raw-ulf-tree)))
(setf ulf-tree (list "ULF (post-processed by Lane's code)" ulf-sent))
(setf parse-pair-tree (append parse-pair-tree (list ulf-tree)))
(setf raw-el-tree (list "EL (Len's parser's raw conversion of post-processed ULF)" raw-el-sent))
(setf parse-pair-tree (append parse-pair-tree (list raw-el-tree)))
(setf el-tree (list "EL (post-processed by Lane's code)" "Individual WFFs:"
(append
(loop for wff in valid-wffs
collect (list t wff))
(loop for wff in invalid-wffs
collect (list nil wff))
)
))
(setf parse-pair-tree (append parse-pair-tree (list el-tree)))
; (setf sent-tree (append sent-tree (list (list el-tree))))
(setf sent-tree (append sent-tree (list parse-pair-tree)))
(setf sent-trees (append sent-trees (list sent-tree)))
(if (and *PRINT-VALID-SENTS* (> (length valid-wffs) 0))
(progn
(format nil " Valid ELFs: ~%")
(loop for valid-wff in valid-wffs
if (or (not *FILTER-INVISIBLE-PREDS*) (not (invisible? valid-wff)))
do (format nil " ~s~%" valid-wff)
)
)
)
(if (and *PRINT-INVALID-SENTS* (> (length invalid-wffs) 0))
(progn
(format nil "~% Invalid ELFs: ~%")
(loop for invalid-wff in invalid-wffs
do (format nil " ~s~%" invalid-wff)
)
)
)
(format nil "~%")
)
)
(return-from outer sent-trees)
; (print-story "Story" sent-trees)
))
(dbg 'ulf-html *COLLAPSE-PAGE-OPENER*)
(loop for story in stories
for i from 1
do (block pr-st
(setf outer-sent-trees nil)
(if *HANDLE-ERRORS*
(handler-case (progn
(setf outer-sent-trees (print-story-wffs story))
; (format nil "~%~%==================~%~%")
)
(error ()
(format nil "; error processing story:~%")
; (loop for sent in story
; do (format nil "; ~s~%" sent)
; )
; (print-story (format nil "Story ~d of ~d" i (length stories)) nil)
; (setf sent-tree (list (format nil "Story ~d of ~d" i (length stories)))
))
)
(if (not *HANDLE-ERRORS*)
; do (len-parse-sents story)
; do (get-len-ulfs story)
(progn
(setf outer-sent-trees (print-story-wffs story))
; (format nil "~%~%==================~%~%")
)
)
(print-story (format nil "Story ~d of ~d" i (length stories)) outer-sent-trees)
))
(dbg 'ulf-html *COLLAPSE-PAGE-CLOSER*)