-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
EnglishPTBTreebankCorrector.java
1908 lines (1480 loc) · 56.3 KB
/
EnglishPTBTreebankCorrector.java
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package edu.stanford.nlp.trees.treebank;
import java.io.BufferedReader;
import java.io.StringReader;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.trees.tregex.Macros;
import edu.stanford.nlp.trees.tregex.TregexPattern;
import edu.stanford.nlp.trees.tregex.TregexPatternCompiler;
import edu.stanford.nlp.trees.tregex.tsurgeon.Tsurgeon;
import edu.stanford.nlp.trees.tregex.tsurgeon.TsurgeonPattern;
import edu.stanford.nlp.util.Pair;
import edu.stanford.nlp.util.logging.Redwood;
/** Correct some of the errors in the LDC99T42 Penn Treebank 3.
* You can use this class from {@link edu.stanford.nlp.trees.Treebanks} via a command like: <p>
* {@code java edu.stanford.nlp.trees.Treebanks -correct -pennPrint LDC99T42-Treebank3/parsed/mrg/wsj 200-2199 > train-fixed}
*/
public class EnglishPTBTreebankCorrector implements TreeTransformer, TreebankTransformer {
/** A logger for this class */
private static final Redwood.RedwoodChannels log = Redwood.channels(EnglishPTBTreebankCorrector.class);
private static final boolean DEBUG = false;
// "ai" is from "ai n't"; occasionally there is a bare "s" from "is", etc.
private static final String BE =
"/^(?i:am|is|are|was|were|be|being|been|'s|'m|'re|s|ai|r|m|`s|art|ar|wase)$/";
private static final String DO =
"/^(?i:do|did|does|doing|done)$/";
/** List of be, have, and get auxiliary forms: things that you would expect
* to have a VBN complement if anything verbal.
* A few times the apostrophe is missing on "'s", so we have just "s".
* Could also add become, feel, seem, remain for some PTB cases, but
* maybe should reparse them?
*/
private static final String BE_HAVE_GET =
"/^(?i:i:am|is|are|was|were|be|being|been|'s|'m|'re|s|ai|r|m|`s|art|ar|wase|has|have|had|having|'s|'ve|'d|s|get|gets|getting|got|gotten)$/";
private static final String MODAL_WORD =
"/^(?i:should|would|wo|could|may|might|ca|can|dare|will|'ll|must|shall|sha|'d)$/";
private static final String MODAL =
"[ < (__ < /^(?i:should|would|wo|could|may|might|ca|can|dare|will|'ll|must|shall|sha)$/) | < (MD < /^(?i:'d)$/) ]";
/** Contexts that take VB complement. This is a tregex subexpression
* that includes the tag. Something to specify next to VP:
* "(@VP" + MODAL_DO_TO + ")". na is gonna. sha is shan't (though doesn't occur).
* Not modals that take TO: need, ought. Or mighta.
* Note that "'d" can also be "had", so one needs to be careful on that!
*/
private static final String MODAL_DO_TO =
"[ < (__ < /^(?i:do|did|does|doing|done|to|na|should|would|wo|could|may|might|ca|can|dare|will|'ll|must|shall|sha)$/) | < (MD < /^(?i:'d)$/) ]";
/** Verbs that take bare VB complements.
* 'say' is sort of special, these are semi-direct speech cases where there
* are no inverted quotes but imperatives follow. Check for
* overgeneralization.
*/
private static final String BARE_VP_VERB =
" < (__ < /^(?i:help|helps|helping|helped|make|makes|making|made|see|sees|saw|seen|seeing|hear|heard|hears|hearing|let|lets|letting)$/)";
private static final String SAY_VERB =
" < (__ < /^(?i:say|says|said|saying)$/)";
private final List<Pair<TregexPattern,TsurgeonPattern>> ops;
public EnglishPTBTreebankCorrector() {
// initialize the transformations to be done
ops = new ArrayList<>();
TreebankLanguagePack tlp = new PennTreebankLanguagePack();
TregexPatternCompiler tpc = new TregexPatternCompiler(tlp.headFinder(), tlp.getBasicCategoryFunction());
Macros.addAllMacros(tpc, getBufferedReader(macroStr));
try {
BufferedReader br = getBufferedReader(editStr);
List<TsurgeonPattern> tsp = new ArrayList<>();
for (String line; (line = br.readLine()) != null; ) {
TregexPattern matchPattern = tpc.compile(line);
tsp.clear();
if (DEBUG) log.info("Pattern is " + line + " [" + matchPattern + ']');
while (continuing(line = br.readLine())) {
TsurgeonPattern p = Tsurgeon.parseOperation(line);
if (DEBUG) log.info("Operation is " + line + " [" + p + ']');
tsp.add(p);
}
if ( ! tsp.isEmpty()) {
TsurgeonPattern tp = Tsurgeon.collectOperations(tsp);
ops.add(new Pair<>(matchPattern, tp));
}
} // while not at end of file
} catch (IOException ioe) {
log.warn(ioe);
}
}
@Override
public Tree transformTree(Tree t) {
return Tsurgeon.processPatternsOnTree(ops, t);
}
/** Fix all the English Penn Treebank errors, or at least some of them (!).
*/
@Override
public MemoryTreebank transformTrees(Treebank tb) {
MemoryTreebank mtb = new MemoryTreebank(tb.treeReaderFactory(),
tb.encoding());
for (Tree t : tb) {
mtb.add(transformTree(t));
}
return mtb;
}
private static boolean continuing(String str) {
return str != null && ! str.matches("\\s*");
}
private static BufferedReader getBufferedReader(String source) {
return new BufferedReader(new StringReader(source));
}
// Note that backslashes and dollar signs need to be escaped.
// Maybe we should have an easy syntax for invoking Matcher.quoteReplacement?
private static final String macroStr =
"HAVE_AUX_WORD\t/^(?i:has|have|had|having|'s|'ve|'d)\\$/\n";
private static final String editStr =
// 1. Bung tree fixing
// NOTE: if you add more of these, make sure to group the string concatenations
// into chunks using parentheses, or the compiler will choke with a
// StackOverflowError (!)
(
// Fix a bad parse in wsj_0415.mrg
("@VP=adj < (NP < (NP=ex < (NN < growth)) < CC=bad < (NP=bd < (VB < service)))\n" +
"excise ex ex\n" +
"delete bad\n" +
"delete bd\n" +
"adjoinF (VP VP@ (CC and) (VP (VB service) (NP (NN debt)))) adj\n" +
'\n') +
// sec 24
("@SBAR=home <1 /^-NONE-$/=emp <2 (@S < (@NP <1 (DT=bad < that|That) <-1 NNS))\n" +
"delete emp\n" +
"relabel bad IN\n" +
"move bad >1 home\n" +
'\n') +
// secs 0, 13, 20 bad parses!
("@NP < (@NP=dest <: JJ) < NN=bad < @PP\n" +
"move bad >-1 dest\n" +
'\n') +
// sec 22 bad parse!
("@NP < (@NP=gone < (NN < authority)) < (@PP=bad < (TO < to) < (NP=vp < (NN=newv < block) < (NNS=newnp < mergers)))\n" +
"excise gone gone\n" +
"adjoin (S (NP-SBJ (-NONE- *)) VP@) bad\n" +
"relabel vp VP\n" +
"relabel newv VB\n" +
"adjoin (NP NN@) newnp\n" +
'\n') +
// Fix some cases of 'as well as' not made into a CONJP unit
// There are a few other weird cases that should also be reviewed with the tregex
// well|Well|WELL , as|AS|As . as|AS|As !>(__ > @CONJP)
// but note that there are also non-CONJP uses as adverbial form of 'as good as'
// This bleeds retagging of 'well' inside NP below
("@NP < (__=bad < well|Well|WELL $, (__=before < as|AS|As) $. (__=after < as|AS|As))\n" +
"adjoinH (CONJP RB@) bad\n" +
"relabel bad CONJP\n" +
"move before >1 bad\n" +
"move after >-1 bad\n" +
'\n' )
) +
// 2. POS tag fixing
// 2.a. Ones specific to a phrasal category
// 2.a.i NP
(
("@NP < (/^``$/ < /^`$/) < (POS=bad < /^'$/)\n" +
"relabel bad /''/\n" +
'\n') +
("@NP < (IN|WDT=bad < /^(?:a|that|That)$/)\n" +
"relabel bad DT\n" +
'\n') +
("@NP < (IN=bad < /^(?:so|about)$/)\n" +
"relabel bad RB\n" +
'\n') +
("@NP < (IN=bad < /^(?:fiscal|next)$/)\n" +
"relabel bad JJ\n" +
'\n') +
("@NP < (RB=bad < /^(?:a|that|Some)$/)\n" +
"relabel bad DT\n" +
'\n') +
("@NP < (RB=bad < most $. DT)\n" +
"relabel bad PDT\n" +
'\n') +
("@NP < (RB=bad < /^(?:MORE)$/)\n" +
"relabel bad JJR\n" +
'\n') +
("@NP < (NN=bad < the)\n" +
"relabel bad DT\n" +
'\n') +
("@NP < (/^VB/=bad < won)\n" +
"relabel bad NN\n" +
'\n') +
// "well". Other rules for under INTJ further below.
("@NP < (/^RB/=bad < well|WELL|Well)\n" +
"relabel bad NN\n" +
'\n') +
// treat like "sheep": if it would be "dollars", make it plural
("@NP < (NN=bad < yen|won [ $- (CD !< one|One|1) | $- (@QP !< (CD < one|One|1)) ] )\n" +
"relabel bad NNS\n" +
'\n') +
// it's 69 NNPS, 17 NNS, 3 NNP for Democrats; 46, 17, 3 for Republicans; all political party mentions
("@NP < (NNP|NNS=bad < Democrats|Republicans)\n" +
"relabel bad NNPS\n" +
'\n') +
// Parks for Korean name plural or national Parks but not elsewhere ("Rosa Parks", etc.)
("@NP < (NNP|NNS=bad < Parks) [ < (DT < The|the) | < (NNP|JJ < National) ]\n" +
"relabel bad NNPS\n" +
'\n') +
("@NP < (CD=bad < the)\n" +
"relabel bad DT\n" +
'\n') +
("@NP <: (JJ=bad < /^(UV-B|sterling|then-president|secretary-general|static|gold|cyclosporine|sales)$/)\n" +
"relabel bad NN\n" +
'\n') +
// "Major could be ambiguous but is former British leader in WSJ. Ditto for Sharp
("@NP <: (JJ=bad < /^(Hungary|Major|Sharp|National)$/)\n" +
"relabel bad NNP\n" +
'\n') +
("@NP < (JJ=bad < the)\n" +
"relabel bad DT\n" +
'\n') +
("@NP|NX < (NNP=bad < the)\n" +
"relabel bad DT\n" +
'\n') +
("@NP=bad < (NNP=badder < Technically|Historically)\n" +
"relabel bad ADVP\n" +
"relabel badder RB\n" +
'\n') +
("@NP < (RB=bad < /^(?:McNally)$/)\n" +
"relabel bad NNP\n" +
'\n') +
("@NP < (RB=bad < /^(?:vice|night|multifamily|hand|fist)$/)\n" +
"relabel bad NN\n" +
'\n') +
("@NP < (RP=bad < /^(?:whole)$/)\n" +
"relabel bad JJ\n" +
'\n') +
("@NP < (RP=bad < Howard) < (NN=badder < /^A\\.$/)\n" +
"relabel bad NNP\n" +
"relabel badder NNP\n" +
'\n') +
("@NP < (JJ=bad < (First , (__ !> /^``$/ !> /^-LRB-$/ !> /^PRP\\$$/)) $. NNP)\n" +
"relabel bad NNP\n" +
'\n') +
("@NP < (JJ=bad < /^(?:U\\.S\\.|Sept\\.)$/)\n" +
"relabel bad NNP\n" +
'\n') +
// WSJ treats 'Department' as NNP, except in a couple of standalone cases in 00, 01 which seeem to be mistakes
("@NP < (NN=bad < Department)\n" +
"relabel bad NNP\n" +
'\n') +
("@NP < (JJ=bad < /^(?:mine)$/)\n" +
"relabel bad NN\n" + // noun usages (mining)
'\n') +
("@NP <-1 (JJ=bad < firm)\n" +
"relabel bad NN\n" + // noun usages
'\n') +
("@NP < (JJ=bad < /^(?:ours)$/)\n" +
"relabel bad PRP\n" +
'\n') +
("@NP <: (JJ=bad < /^(?i:mine|yours|hers|ours|theirs)$/)\n" +
"relabel bad PRP\n" +
'\n') +
("@NP < (JJ=bad < /^(?:ours)$/)\n" +
"relabel bad PRP\n" +
'\n') +
// don't regard aluminum as an adjective (color)
// all uses of plastic are also for the noun, not adjectivally for things showing plasticity
("@NP < (JJ=bad < aluminum|plastic|textile)\n" +
"relabel bad NN\n" +
'\n') +
// gold and silver can validly be colours but are usually metals in WSJ. Use noun to decide
("@NP < (JJ=bad < gold|silver|bronze . stocks|bat|standard|reserves|prices|market|price|prices|fund|funds|consumers|use|commemorative|medal|bullion|exploration|producer|producers|trader|traders)\n" +
"relabel bad NN\n" +
'\n') +
// gold and silver can validly be colours but are usually metals in WSJ. Use noun to decide
("@NP <: (JJ=bad < gold|silver|bronze)\n" +
"relabel bad NN\n" +
'\n') +
// make all uses of 'the House' (Congress) NNP, like most, and
// like all uses of 'the Senate'
("@NP <2 (NN=bad < House $- (DT < /^[Tt]he$/))\n" +
"relabel bad NNP\n" +
'\n') +
("@NP < (NNP=bad < Democrats|Republicans)\n" +
"relabel bad NNPS\n" +
'\n') +
("@NP < (NNS=bad < Democrats|Republicans , __)\n" +
"relabel bad NNPS\n" +
'\n') +
("@NP < (NN=bad < /^(?:Chapman|Ok|Oslo|Boeing|Jan\\.|Sept\\.|Oct\\.|Nov\\.|Dec\\.|Treasury|Esso)$/)\n" +
"relabel bad NNP\n" +
'\n') +
("@NP < (NN=bad < /^(?:members|bureaus|days|outfits|institutes|innings|write-offs|wines|trade-offs|tie-ins|thrips|1980s|1920s|receivables|earnings)$/)\n" +
"relabel bad NNS\n" +
'\n') +
("@NP < (NNP=bad < Dutch $. NN|NNS|JJ|VBG)\n" +
"relabel bad JJ\n" +
'\n') +
("@NP < (NN=bad < /^(?:this)$/)\n" +
"relabel bad DT\n" +
'\n') +
("@NP < (/^:/=bad < /^(?:')$/)\n" +
"relabel bad /''/\n" +
'\n') +
("@NP < (NNS=bad < /^(?:start-up|ground-handling|word-processing|T-shirt|co-pilot|sell-off)$/)\n" +
"relabel bad NN\n" +
'\n') +
// not clear why Sens isn't NNPS
("@NP < (NNS=bad < /^(?:Sens\\.|Aichi|Asahi|Cincinnati|Hawaii|Pepsi)$/)\n" +
"relabel bad NNP\n" +
'\n') +
// VBZ under @NP. Strong rule ordering!
// move up misplaced possessives
("@NP <1 (@NP=dest !< @NP . (__=wrong < /^\u0027s$/))\n" +
"move wrong >-1 dest\n" +
'\n') +
// fix bung syntax in wsj_0295 and wsj_1142
("@S < (@NP=bad < PRP < (VBZ=bottom < /^'s$/)) < (@VP=adj < VBN|VBG)\n" +
"adjoin (VP (VBZ 's) VP@) adj\n" +
"delete bottom\n" +
'\n') +
("@S < (NP-SBJ < (PRP < I)) < (VP < (VB=bad < think) < SBAR)\n" +
"relabel bad VBP\n" +
'\n') +
// and an extra weird NP in wsj_0446 and wsj_1101
("@VP < (@NP=bad < (VBZ < kills|blames) < @NP)\n" +
"excise bad bad\n" +
'\n') +
// then turn all 's VBZ ino a POS
// except for Everything's a Dollar Inc. !
("@NP < (VBZ=bad < /^'s$/) !< (NNP < Everything)\n" +
"relabel bad POS\n" +
'\n') +
// and then turn all other VBZ that aren't the 's into NNS.
// 100% precision now!
// CHECK IF CAN DELETE kills HERE NOW!
("@NP|NX < (VBZ=bad !< /^(?:'s|kills)/)\n" +
"relabel bad NNS\n" +
'\n') +
// but turn POS under NP to PRP if it is the 's of let's
("@NP < (POS=bad < /^'s$/) > (@S > (@VP < (VB < let)))\n" +
"relabel bad PRP\n" +
'\n') +
// fix VB at root level
(
// these ones are VBD
("@S < (@VP < (VB=bad < /...ed$/ )) < (/^NP-SBJ/ !< /^-NONE-$/) > (__ !> __)\n" +
"relabel bad VBD\n" +
'\n') +
// these ones are also VBD in practice (though in principle ambiguous)
("@S < (@VP < (VB=bad < let|cut|bid| )) < (/^NP-SBJ/ !< /^-NONE-$/) > (__ !> __)\n" +
"relabel bad VBD\n" +
'\n') +
// Then, except in a few weird cases (treebank err, missing letter, reduced "better not" they should be VBP
("@S < (@VP < (VB=bad !, Tait|MD|not )) < (/^NP-SBJ/ !< /^-NONE-$/) > (__ !> __)\n" +
"relabel bad VBP\n" +
'\n')
) +
// VBP under NP. First fix one that should be a verb! NP is wrong
("@NP=bad < (VBP < are) > (@VP > (@S < NP-SBJ))\n" +
"excise bad bad\n" +
'\n') +
("@NP < (VBP=bad < charge)\n" +
"relabel bad NN\n" +
'\n') +
("@NP < (VBP=bad < the)\n" +
"relabel bad DT\n" +
'\n') +
("@NP < (VBP=bad < we)\n" +
"relabel bad PRP\n" +
'\n') +
("@NP < (VBP=bad < /^[A-Z]/)\n" +
"relabel bad NNP\n" +
'\n') +
// VBN under NP
("@NP < (VBN=bad < Applied !$ __)\n" +
"relabel bad NNP\n" +
'\n') +
("@NP < (VBG=bad < preferred)\n" +
"relabel bad VBN\n" +
'\n') +
("@NP < (VB=bad < The)\n" +
"relabel bad DT\n" +
'\n') +
("@NP < (VB=bad < allowed)\n" +
"relabel bad VBD\n" +
'\n') +
("@NP <-1 (JJR=bad < cleaner)\n" +
"relabel bad NN\n" +
'\n') +
("@NP < (VB=bad < /^(?:Nov\\.|Jan\\.|Dec\\.|Tandy|Release|Orkem|McDonald|Citicorp|Anne)$/)\n" +
"relabel bad NNP\n" +
'\n') +
("@NP < (VB=bad < /^(?:short|key|many|last|further)$/)\n" +
"relabel bad JJ\n" +
'\n') +
("@NP < (VB=bad < lower)\n" +
"relabel bad JJR\n" +
'\n') +
("@NP < (VB=bad < /^(?:spill|watch|review|risk|realestate|love|experience|control|Transport|mind|term|program|gender|audit|blame|stock|run|group|affect|rent|show|accord|change|finish|work|schedule|influence|school|freight|growth|travel|call|autograph|demand|abuse|return|defeat|pressure|bank|notice|tax|ooze|network|concern|pit|contract|cash|help|lunch|combat|pot|care|date|Streetspeak|face|effect|worry)$/)\n" +
"relabel bad NN\n" +
'\n') +
("@NP <1 (NNP=bad < Officials|Cartoonists|Prices)\n" +
"relabel bad NNS\n" +
'\n') +
("@NP=badder < (NNP=bad < Currently)\n" +
"relabel bad RB\n" +
"relabel badder ADVP-TMP\n" +
'\n') +
// nth-quarter as a modifier: may as well treat it as JJ as manual says and majority of instances are
("@NP < (NN=bad < /^(?i:first|second|third|fourth)-quarter$/ $+ __)\n" +
"relabel bad JJ\n" +
'\n') +
// may as well take all of "K mart" as a proper noun
("@NP < (NNP < K $+ (NN=bad < mart))\n" +
"relabel bad NNP\n" +
'\n') +
("@NP < (PRP=bad < US & $. __)\n" +
"relabel bad NNP\n" +
'\n') +
("@NP < (PRP=bad < her & $. __)\n" +
"relabel bad /PRP$/\n" +
'\n') +
("@NP <1 (PRP=bad < his) !<2 __\n" +
"relabel bad /PRP$/\n" +
'\n') +
("VBD=bad [ > @NP | > (@ADJP < CC|CONJP > @NP) ]\n" +
"relabel bad VBN\n" +
'\n') +
("@NP < (NN=bad < Time) < (NNP < Warner)\n" +
"relabel bad NNP\n" +
'\n') +
("@NP < (MD=bad < Can|May)\n" +
"relabel bad NNP\n" +
'\n') +
// there are a number of cases of 'the the' -- errors in sources or
// mistakes in Perl scripts?
// and one case of a/DT half/DT
("@NP <1 (DT=bad !< the $. (DT !< half))\n" +
"relabel bad PDT\n" +
'\n') +
// filling out NP with PP modifier. This rule should precede
("@NP=place < (@NP <1 DT !<2 __ $. (JJ=bad $. (NN=badder $. PP)))\n" +
"move bad >-1 place\n" +
"move badder >-1 place\n" +
'\n') +
// filling out NP with PP modifier. This rule should follow
("@NP=place < (@NP <1 DT|JJ !<2 __ $. (NN=bad $. PP))\n" +
"move bad >-1 place\n" +
'\n') +
// NEWSPAPERS
("@NP < (NNPS=bad < NEWSPAPERS ! $ /^NN/)\n" +
"relabel bad NNS\n" +
'\n') +
("@NP < (@NP < (NNPS=bad < CERTIFICATES)) < (PP < (IN < OF) < (NP < (__ < DEPOSIT)))\n" +
"relabel bad NNS\n" +
'\n') +
("@NP < (@NP < (__ < CERTIFICATES)) < (PP < (IN < OF) < (NP < (NNPS=bad < DEPOSIT)))\n" +
"relabel bad NN\n" +
'\n') +
("@NP < (NNP=bad < DISCOUNT) < (NNP=badder < RATE)\n" +
"relabel bad NN\n" +
"relabel bad NN\n" +
'\n') +
("@NP < (JJ=bad < DISCOUNT) < (NN < RATE)\n" +
"relabel bad NN\n" +
"relabel bad NN\n" +
'\n') +
("@NP < (__ < chief $. (NN=bad < executive $. (NN < officer)))\n" +
"relabel bad JJ\n" +
'\n') +
("@NP < (NN=bad < chief $. (__ < executive $. (NN < officer)))\n" +
"relabel bad JJ\n" +
'\n') +
("@NP <: (NNP=bad < /^'s$/)\n" +
"relabel bad PRP\n" +
'\n') +
"NP-TMP=bad < (NN < Leisure)\n" +
"relabel bad NP\n" +
'\n' +
"@NP < (RB=bad < well !$, (RB < as) $,, (DT < The|the))\n" +
"relabel bad NN\n" +
'\n' +
// chief executive officer
("@NP < (NN < officer $- (NN=bad < executive $- (__ < chief)))\n" +
"relabel bad JJ\n" +
'\n') +
// chief executive officer
("@NP < (NN < officer $- (JJ < executive $- (NN=bad < chief)))\n" +
"relabel bad JJ\n" +
'\n') +
// the infamous "Ad Notes"
("@NP < (NNP=bad < Ad) < (/^NN/ < Notes)\n" +
"relabel bad NN\n" +
'\n') +
// the infamous "Ad Notes"
("@NP < (/^NN/ < Ad) < (NNPS=bad < Notes)\n" +
"relabel bad NNS\n" +
'\n') +
// the infamous "Ad Notes"
("NP=bad < (/^NN/ < Ad) < (/^NN/ < Notes)\n" +
"relabel bad NP-HLN\n" +
'\n') +
("@NP < (NN=bad < nonperforming)\n" +
"relabel bad JJ\n" +
'\n') +
("@NP < (IN=bad < next|Next) < NN|NNP\n" +
"relabel bad JJ\n" +
'\n') +
("NP-PRD=x < (JJ=y $+ (NN=z < simple))\n" +
"relabel x ADJP-PRD\n" +
"relabel y RB\n" +
"relabel z JJ\n" +
'\n') +
("NP-PRD=x <: (NN=z < simple)\n" +
"relabel x ADJP-PRD\n" +
"relabel z JJ\n" +
'\n') +
// this needs to be after the above two "simple" ones
("NN=z < simple\n" +
"relabel z JJ\n" +
'\n') +
"") +
("@PP < (IN < behind) < (@NP < PRP=bad < (RB=no < back))\n" +
"relabel bad /PRP$/\n" +
"relabel no NN\n" +
'\n') +
// equally infamous "Who's News:"
("@SBAR=bad < (@WHNP < (WP < WHO)) < (S=badder < (VP < (@NP < (NN < NEWS))))\n" +
"relabel bad /SBARQ-HLN/\n" +
"relabel badder SQ\n" +
'\n') +
// equally infamous "Who's News:"
("@SBARQ < (@WHNP < (WP < WHO)) < (SQ < (VP < (@NP < (NNP=bad < NEWS))))\n" +
"relabel bad NN\n" +
'\n') +
// equally infamous "Who's News:"
("@SBARQ < (@WHNP < (WP < WHO)) < (S=bad < (VP < (@NP < (NN < NEWS))))\n" +
"relabel bad SQ\n" +
'\n') +
("@WHNP < @WHNP=bad < @WHPP\n" +
"relabel bad NP\n" +
'\n') +
// How much can have "much" as RB or JJ depending on environment. JJ if under WHADJP or WHNP
("@WHADJP|WHNP|NP < (WRB < /^(?i:how)$/) < (__=bad < (much !> JJ))\n" +
"relabel bad JJ\n" +
'\n') +
// the VP is for extraposed relatives....
("@WHNP|WHADVP < (VBP|DT|IN=bad < /^(?i:that)$/) [ > (@SBAR > @NP|VP) | > (@SBAR > (@SBAR < /^(?:CC|CONJP|,)$/ > @NP|VP)) ]\n" +
"relabel bad WDT\n" +
'\n') +
("@UCP < (RB=bad < multifamily)\n" +
"relabel bad NN\n" +
'\n') +
("@PRT < (RBR=bad < in)\n" +
"relabel bad RP\n" +
'\n') +
("@PRT < (NNP=bad < up)\n" +
"relabel bad RP\n" +
'\n') +
// PP parent
("@PP < (RP=bad < through) < @NP\n" +
"relabel bad IN\n" +
'\n') +
("@PP < (RP|NN=bad < in) < @NP\n" +
"relabel bad IN\n" +
'\n') +
("@PP < (RB=bad < for|For|after|After|past|Past|under|Under)\n" +
"relabel bad IN\n" +
'\n') +
("@PP < (JJ=bad < if)\n" +
"relabel bad IN\n" +
'\n') +
// VP parent
("@VP=bad < (IN < past) < @NP\n" +
"relabel bad PP\n" +
'\n') +
("@VP < (RB=bad < back $. (PRT < (RP < down))) > (@SINV|SQ|VP < MD)\n" +
"relabel bad VB\n" +
'\n') +
("@VP < (IN=bad < complicated) > @S\n" +
"relabel bad VBD\n" +
'\n') +
("@VP < (IN=bad < near) > @VP\n" +
"relabel bad VB\n" +
'\n') +
("@VP < (IN=bad < like|post) > (@SQ|VP < /^(?:VB|MD)/)\n" +
"relabel bad VB\n" +
'\n') +
("@VP < (IN=bad < like|post) [ > @S | > (@VP < CC|CONJP > @S) ]\n" +
"relabel bad VBP\n" +
'\n') +
("@VP < (/^VBD?$/=ins < take|sold) < (IN=bad < off)\n" +
"delete bad\n" +
"insert (PRT (RP off)) $- ins\n" +
'\n') +
// NNS under VP. Easy.
("@VP < NNS=bad\n" +
"relabel bad VBZ\n" +
'\n') +
// ordered rules for NN under VP
// first fix the ones ending in -ing
("@VP < (NN=bad < /.{2}ing$/)\n" +
"relabel bad VBG\n" +
'\n') +
("@VP < (NN=bad [ < set|beat|bid|redone|reset|hurt|underwritten|overrun | < /.{2}[^e]ed$/ ]) [ > (@VP < (/^VB/ < " + BE_HAVE_GET + ")) | > (@NP < @NP)]\n" +
"relabel bad VBN\n" +
'\n') +
("@VP < (NN=bad < agreed|set|rebounded|fell) [ > @S | > (@VP < @CC|CONJP > @S) ]\n" +
"relabel bad VBD\n" +
'\n') +
// contexts where an untensed verb should occur
// an imperative is VB! The 'say' cases are direct speech imperatives
("@VP !< /^VB/ < (NN|NNP|JJ=bad !< /...(?i:ing)$/) [ > (@VP|SINV|SQ " + MODAL_DO_TO + ") | > (@VP|SINV|UCP|SQ < CC|CONJP > (@VP|SINV|UCP|SQ " + MODAL_DO_TO + ")) | > (@S > (@VP " + BARE_VP_VERB + ")) | > (@VP " + BARE_VP_VERB + ") | > (@S < (/^NP-SBJ/ < /^-NONE-$/) > (@VP " + SAY_VERB + ")) ]\n" +
"relabel bad VB\n" +
'\n') +
// file should maybe be VB - subjunctive (look at higher verb? wsj_0979)
("@VP !< /^VB/ < (NN=bad [ [ !< /s$/ & !< /e[dn]$/ & !< /ing$/ ] | < stress ] ) [ > @S | > (@VP < @CONJP|CC > @S) ]\n" +
"relabel bad VBP\n" +
'\n') +
// not just anything ending in s. Definitely not if -ss, but also 'focus'
("@VP < (NN=bad < institutes) > @S\n" +
"relabel bad VBZ\n" +
'\n') +
("@VP < (VBP=bad !< /...(?i:ing)$/) [ > (@VP|SQ|SINV " + MODAL_DO_TO + ") | > (@VP|UCP|SQ|SINV < CC|CONJP > (@VP|UCP|SQ|SINV " + MODAL_DO_TO + ")) | > (@S > (@VP " + BARE_VP_VERB + ")) | > (@VP " + BARE_VP_VERB + ") | > (@S < (/^NP-SBJ/ < /^-NONE-$/) > (@VP " + SAY_VERB + ")) ]\n" +
"relabel bad VB\n" +
'\n') +
// Don't allow SINV for VBN as get participial clauses
// unless the SINV has a modal under it
// Allow VBN in complement of SEE or HEAR (but not LET or MAKE)
("@VP < (VBN=bad !< /...(?i:ing)$/ !< /...(?i:ed)$/) [ > (@VP|SQ " + MODAL_DO_TO + ") | > (@VP|SQ < CC|CONJP !< /^VB/ > (@VP|SQ " + MODAL_DO_TO + ")) | > (@SINV " + MODAL + ") | > (@SINV < CC|CONJP !< /^VB/ > (@SINV " + MODAL + ")) ]\n" +
"relabel bad VB\n" +
'\n') +
// for transitive, it can't be VBN under see/hear
("@VP < (VBN=bad !< /...(?i:ing)$/) < (NP !< /^-NONE-$/) [ > (@S > (@VP " + BARE_VP_VERB + ")) | > (@VP " + BARE_VP_VERB + ") | > (@S < (/^NP-SBJ/ < /^-NONE-$/) > (@VP " + SAY_VERB + ")) ]\n" +
"relabel bad VB\n" +
'\n') +
("@VP < (NN=bad < relocate) > (@VP < @CONJP > (@VP < MD))\n" +
"relabel bad VB\n" +
'\n') +
("@VP < (NN=bad < might|will)\n" +
"relabel bad MD\n" +
'\n') +
// ordered rules for NNP under VP
// it's VBD for SINV
("@VP < (NNP=bad < /...(?i:ed)$/) [ > (SINV !> /TTL/) | > (@VP < @CONJP|CC > (SINV !> /TTL/)) ]\n" +
"relabel bad VBD\n" +
'\n') +
// it's VBN not VBD because the one or two there are headline-speak
("@VP < (NNP=bad < /...(?i:ed)$/) [ > (S|S-HLN|S-ADV !> /TTL/) | > (@VP < @CONJP|CC > (S|S-HLN|S-ADV !> /TTL/)) | > (@VP < (__ < " + BE_HAVE_GET + ")) ]\n" +
"relabel bad VBN\n" +
'\n') +
// it's VBN not VBD because the one or two there are headline-speak
("@VP < (NNP=bad < Got|Gotten) [ > (S|S-HLN|S-ADV !> /TTL/) | > (@VP < @CONJP|CC > (S|S-HLN|S-ADV !> /TTL/)) | > (@VP < (__ < " + BE_HAVE_GET + ")) ]\n" +
"relabel bad VBN\n" +
'\n') +
// ordered rules for NNP under VP (2 dots as want to get "Adds")
("@VP < (NNP=bad < /..[^Ss](?i:s)$/) [ > (S|S-HLN|SINV !> /TTL/) | > (@VP < @CONJP|CC > (S|SINV|S-HLN !> /TTL/)) ]\n" +
"relabel bad VBZ\n" +
'\n') +
// ordered rules for NNP under VP
("@VP !< /^VB/ < (NNP=bad < /(?i:ing)$/)\n" +
"relabel bad VBG\n" +
'\n') +
// ordered rules for NNP under VP
("@VP < NNP=bad [ > (S|S-HLN !> /TTL/) | > (@VP < @CONJP|CC > (S|S-HLN !> /TTL/)) ]\n" +
"relabel bad VBP\n" +
'\n') +
// this one is in a title....
("@VP < (NNP=bad < are) [ > @S | > (@VP < @CONJP|CC > @S) ]\n" +
"relabel bad VBP\n" +
'\n') +
// a few trees start with "Either way", etc but get labeled as if they
// were Either X or Y, or in one case, labeled completely randomly
("/CC|NNP/=bad < /Either|Neither/ !$++ CC\n" +
"relabel bad DT\n" +
'\n') +
// there are a bunch of lowercase either which are also mislabeled,
// but with RB for either X or Y
// TODO: there are also some trees with ADVP < RB < either
// with a deeper nested structure leading to a CC.
// "either structured in ways that create unnecessary burdens..."
// "either receive a percentage of cash flow, a percentage of ..."
// "either look for greater equity participation..."
("/neither|either/ > (RB=bad $++ CC)\n" +
"relabel bad CC\n" +
'\n') +
// this is also wrong: all of the either X or Y constructions should be
// either_CC X or_CC Y
("/Neither|neither|either/ > (DT=bad $++ CC)\n" +
"relabel bad CC\n" +
'\n') +
/* ----------------------------
tregex3 -f -w '@VP < NN' | & less
// unresolved: some bid, ask cases
// so far only done 1-1000 inclusive
} else if (word.equals("reconfirm")) {
cat = changeBaseCat(cat, "VB");
} else if (word.equals("rebounded")) {
cat = changeBaseCat(cat, "VBD");
}
// still need to do NNP > VP rules as well!
--------------------- */
/*
} else if (baseCat.equals("NNP")) {
if (word.equals("GRAB")) {
cat = changeBaseCat(cat, "VBP");
} else if (word.equals("mature")) {
cat = changeBaseCat(cat, "VB");
} else if (word.equals("Face")) {
cat = changeBaseCat(cat, "VBP");
} else if (word.equals("are")) {
cat = changeBaseCat(cat, "VBP");
} else if (word.equals("say")) {
cat = changeBaseCat(cat, "VBP");
} else if (word.equals("Added")) {
cat = changeBaseCat(cat, "VBD");
} else if (word.equals("Adds")) {
cat = changeBaseCat(cat, "VBZ");
} else if (word.equals("BRACED")) {
cat = changeBaseCat(cat, "VBD");
} else if (word.equals("REQUIRED")) {
cat = changeBaseCat(cat, "VBN");
} else if (word.equals("REVIEW")) {
cat = changeBaseCat(cat, "VB");
} else if (word.equals("code-named")) {
cat = changeBaseCat(cat, "VBN");
} else if (word.equals("Printed")) {
cat = changeBaseCat(cat, "VBN");
} else if (word.equals("Rated")) {
cat = changeBaseCat(cat, "VBN");
} else if (word.equals("FALTERS")) {
cat = changeBaseCat(cat, "VBZ");
} else if (word.equals("Got")) {
cat = changeBaseCat(cat, "VBN");
} else if (word.equals("Adds")) {
cat = changeBaseCat(cat, "VBZ");
}
*/
// Modal fixes: of 'd tagged as VBD and others tagged VBP
// first fix one where the complement verb tag is wrong
("@VP < (VBD < /^(?i:'d)$/) < (@VP < (VB=badder < seen))\n" +
"relabel badder VBN\n" +
'\n') +
("@VP < (VBP=bad < " + MODAL_WORD + ") < (@VP < VB)\n" +
"relabel bad MD\n" +
'\n') +
("@VP < (VBP=bad < /^(?i:'d)$/) < (@VP < VB)\n" +
"relabel bad MD\n" +
'\n') +
// this must be ordered before the have/be auxiliary complement fix!
("@VP < POS=bad\n" +
"relabel bad VBZ\n" +
'\n') +
("@VP < (VBD=bad < heaves)\n" +
"relabel bad VBZ\n" +
'\n') +
("@VP < (VB=bad < /.{2}[^e]ed$/) > @S\n" +
"relabel bad VBD\n" +
'\n') +
("@VP < (VB=bad < /^(?i:.{2,}[^e]ed|reset|run|become|hit|remade|gone|rid|put|hurt|become)$/) [ > (@VP < (/^VB/ < " + BE_HAVE_GET + ")) | > (@NP < @NP) ]\n" +
"relabel bad VBN\n" +
'\n') +
("@VP < (VBN=bad < has)\n" +
"relabel bad VBZ\n" +
'\n') +
("@VP < (VBN=bad < grew|fell|had) [ > @S | > (@VP < CONJP|CC > @S)]\n" +
"relabel bad VBD\n" +
'\n') +
// Doing the VBN to VBD is too general because of auxiliary deletion in
// contracted constructions, headlines, etc.
// Nevertheless, there are quite a few cases....
// Try ones with objects??
// "@VP < VBN=bad [ > @S | > (@VP < CONJP|CC > @S) ]\n" +
// "relabel bad VBN\n" +
// "\n" +
// Below are three patterns that doesn't overgeneralize and still gets a
// lot of the cases: note that they don't use @ so as to not match NP-TMP
// or S-HLN, and checks for non-NULL constituents
// must be finite in clause with overt NPsubj and NPobj
("@VP < VBN=bad < (NP !< /^-NONE-$/) [ > (S < (@NP !< /^-NONE-$/)) | > (@VP < CONJP|CC > (S < (@NP !< /^-NONE-$/))) ]\n" +
"relabel bad VBD\n" +
'\n') +
// root main clauses with overt subj must be finite
("@VP < VBN=bad [ > (S < (@NP !< /^-NONE-$/) > (__ !> __)) | > (@VP < CONJP|CC > (S < (@NP !< /^-NONE-$/) > (__ !> __))) ]\n" +
"relabel bad VBD\n" +
'\n') +
// that clauses (or that-less that clauses) with overt subjects are finite
("@SBAR [ < (/^-NONE-$/ < /^0$/) | < (IN < that) ] < (@S < (NP-SBJ !< /^-NONE-$/) < (@VP < VBN=bad))\n" +
"relabel bad VBD\n" +
'\n') +