generated from freelawproject/new-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathtest_FindTest.py
1129 lines (1102 loc) · 57.7 KB
/
test_FindTest.py
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
import os
from copy import copy
from datetime import datetime
from unittest import TestCase
from eyecite import get_citations
from eyecite.find import extract_reference_citations
from eyecite.helpers import filter_citations
# by default tests use a cache for speed
# call tests with `EYECITE_CACHE_DIR= python ...` to disable cache
from eyecite.models import (
Document,
FullCaseCitation,
ReferenceCitation,
ResourceCitation,
)
from eyecite.test_factories import (
case_citation,
id_citation,
journal_citation,
law_citation,
reference_citation,
supra_citation,
unknown_citation,
)
from eyecite.tokenizers import (
EDITIONS_LOOKUP,
EXTRACTORS,
AhocorasickTokenizer,
HyperscanTokenizer,
Tokenizer,
)
cache_dir = os.environ.get("EYECITE_CACHE_DIR", ".test_cache") or None
tested_tokenizers = [
Tokenizer(),
AhocorasickTokenizer(),
HyperscanTokenizer(cache_dir=cache_dir),
]
class FindTest(TestCase):
maxDiff = None
def run_test_pairs(self, test_pairs, message, tokenizers=None):
def get_comparison_attrs(cite):
# Remove pin_cite start and end from metadata for this test
cite.metadata.pin_cite_span_start = None
cite.metadata.pin_cite_span_end = None
out = {
"groups": cite.groups,
"metadata": cite.metadata,
}
if isinstance(cite, ResourceCitation):
out["year"] = cite.year
out["corrected_reporter"] = cite.corrected_reporter()
return out
if tokenizers is None:
tokenizers = tested_tokenizers
for q, expected_cites, *kwargs in test_pairs:
kwargs = kwargs[0] if kwargs else {}
clean_steps = kwargs.get("clean_steps", [])
for tokenizer in tokenizers:
with self.subTest(
message, tokenizer=type(tokenizer).__name__, q=q
):
if "html" in clean_steps:
kwargs["markup_text"] = q
else:
kwargs["plain_text"] = q
cites_found = get_citations(tokenizer=tokenizer, **kwargs)
self.assertEqual(
[type(i) for i in cites_found],
[type(i) for i in expected_cites],
f"Extracted cite count doesn't match for {repr(q)}",
)
for a, b in zip(cites_found, expected_cites):
found_attrs = get_comparison_attrs(a)
expected_attrs = get_comparison_attrs(b)
self.assertEqual(
found_attrs,
expected_attrs,
f"Extracted cite attrs don't match for {repr(q)}",
)
def test_find_citations(self):
"""Can we find and make citation objects from strings?"""
# fmt: off
test_pairs = (
# Basic test
('1 U.S. 1',
[case_citation()]),
# Basic test with a line break
('1 U.S.\n1',
[case_citation()],
{'clean_steps': ['all_whitespace']}),
# Basic test with a line break within a reporter
('1 U.\nS. 1',
[case_citation(reporter_found='U. S.')],
{'clean_steps': ['all_whitespace']}),
# Basic test of non-case name before citation (should not be found)
('lissner test 1 U.S. 1',
[case_citation()]),
# Test with plaintiff and defendant
('lissner v. test 1 U.S. 1',
[case_citation(metadata={'plaintiff': 'lissner',
'defendant': 'test'})]),
# Test with plaintiff, defendant and year
('lissner v. test 1 U.S. 1 (1982)',
[case_citation(metadata={'plaintiff': 'lissner',
'defendant': 'test'},
year=1982)]),
# Don't choke on misformatted year
('lissner v. test 1 U.S. 1 (198⁴)',
[case_citation(metadata={'plaintiff': 'lissner',
'defendant': 'test'})]),
# Test with different reporter than all of above.
('bob lissner v. test 1 F.2d 1 (1982)',
[case_citation(reporter='F.2d', year=1982,
metadata={'plaintiff': 'lissner',
'defendant': 'test'})]),
# Test with comma after defendant's name
('lissner v. test, 1 U.S. 1 (1982)',
[case_citation(metadata={'plaintiff': 'lissner',
'defendant': 'test'},
year=1982)]),
# can we handle variations with parenthesis
('1 So.2d at 1',
[case_citation(volume="1", reporter="So.2d", page="1", short=True,
metadata={'pin_cite': '1'})]),
# Test with court and extra information
('bob lissner v. test 1 U.S. 12, 347-348 (4th Cir. 1982)',
[case_citation(page='12', year=1982,
metadata={'plaintiff': 'lissner',
'defendant': 'test',
'court': 'ca4',
'pin_cite': '347-348'})]),
# Test with court string without space
('bob lissner v. test 1 U.S. 12, 347-348 (Pa.Super. 1982)',
[case_citation(page='12', year=1982,
metadata={'plaintiff': 'lissner',
'defendant': 'test',
'court': 'pasuperct',
'pin_cite': '347-348'})]),
# Test with court string exact match
('Commonwealth v. Muniz, 164 A.3d 1189 (Pa. 2017)',
[case_citation(page='1189', reporter='A.3d', volume='164', year=2017,
metadata={'plaintiff': 'Commonwealth',
'defendant': 'Muniz',
'court': 'pa'})]),
# Test with month/day in court parenthetical
('Commonwealth v. Muniz, 164 A.3d 1189 (Pa. Feb. 9, 2017)',
[case_citation(page='1189', reporter='A.3d', volume='164', year=2017,
metadata={'plaintiff': 'Commonwealth',
'defendant': 'Muniz',
'court': 'pa'})]),
# Parallel cite with parenthetical
('bob lissner v. test 1 U.S. 12, 347-348, 1 S. Ct. 2, 358 (4th Cir. 1982) (overruling foo)',
[case_citation(page='12', year=1982,
metadata={'plaintiff': 'lissner',
'defendant': 'test',
'court': 'ca4',
'pin_cite': '347-348',
'extra': "1 S. Ct. 2, 358",
'parenthetical': 'overruling foo'}),
case_citation(page='2', reporter='S. Ct.', year=1982,
metadata={'plaintiff': 'lissner',
'defendant': 'test',
'court': 'ca4',
'pin_cite': '358',
'parenthetical': 'overruling foo'}),
]),
# Test full citation with nested parenthetical
('lissner v. test 1 U.S. 1 (1982) (discussing abc (Holmes, J., concurring))',
[case_citation(metadata={'plaintiff': 'lissner',
'defendant': 'test',
'parenthetical': 'discussing abc (Holmes, J., concurring)'},
year=1982)]),
# Test full citation with parenthetical and subsequent unrelated parenthetical
('lissner v. test 1 U.S. 1 (1982) (discussing abc); blah (something).',
[case_citation(metadata={'plaintiff': 'lissner',
'defendant': 'test',
'parenthetical': 'discussing abc'},
year=1982)]),
# Test with text before and after and a variant reporter
('asfd 22 U. S. 332 (1975) asdf',
[case_citation(page='332', volume='22',
reporter_found='U. S.', year=1975)]),
# Test with finding reporter when it's a second edition
('asdf 22 A.2d 332 asdf',
[case_citation(page='332', reporter='A.2d', volume='22')]),
# Test if reporter in string will find proper citation string
('A.2d 332 11 A.2d 333',
[case_citation(page='333', reporter='A.2d', volume='11')]),
# Test finding a variant second edition reporter
('asdf 22 A. 2d 332 asdf',
[case_citation(page='332', reporter='A.2d', volume='22',
reporter_found='A. 2d')]),
# Test finding a variant of an edition resolvable by variant alone.
('171 Wn.2d 1016',
[case_citation(page='1016', reporter='Wash. 2d', volume='171',
reporter_found='Wn.2d')]),
# Test finding two citations where one of them has abutting
# punctuation.
('2 U.S. 3, 4-5 (3 Atl. 33)',
[case_citation(page='3', volume='2', metadata={'pin_cite': '4-5'}),
case_citation(page='33', reporter="A.", volume='3',
reporter_found="Atl.")]),
# Test with the page number as a Roman numeral
('12 Neb. App. lxiv (2004)',
[case_citation(page='lxiv', reporter='Neb. Ct. App.',
volume='12',
reporter_found='Neb. App.', year=2004)]),
# Test with page range with a weird suffix
('559 N.W.2d 826|N.D.',
[case_citation(page='826', reporter='N.W.2d', volume='559')]),
# Test with malformed page number
('1 U.S. f24601', []),
# Test with page number that is indicated as missing
('1 U.S. ___',
[case_citation(volume='1', reporter='U.S.', page=None)]),
# Test with page number that is indicated as missing, followed by
# a comma (cf. eyecite#137)
('1 U. S. ___,',
[case_citation(volume='1', reporter_found='U. S.', page=None)]),
# Test with the 'digit-REPORTER-digit' corner-case formatting
('2007-NMCERT-008',
[case_citation(source_text='2007-NMCERT-008', page='008',
reporter='NMCERT', volume='2007')]),
('2006-Ohio-2095',
[case_citation(source_text='2006-Ohio-2095', page='2095',
reporter='Ohio', volume='2006')]),
('2017 IL App (4th) 160407',
[case_citation(page='160407', reporter='IL App (4th)',
volume='2017')]),
('2017 IL App (1st) 143684-B',
[case_citation(page='143684-B', reporter='IL App (1st)',
volume='2017')]),
# Test first kind of short form citation (meaningless antecedent)
('before asdf 1 U. S., at 2',
[case_citation(page='2', reporter_found='U. S.', short=True,
metadata={'antecedent_guess': 'asdf'})]),
# Test second kind of short form citation (meaningful antecedent)
('before asdf, 1 U. S., at 2',
[case_citation(page='2', reporter='U.S.',
reporter_found='U. S.', short=True,
metadata={'antecedent_guess': 'asdf'})]),
# Test short form citation with preceding ASCII quotation
('before asdf,” 1 U. S., at 2',
[case_citation(page='2', reporter_found='U. S.',
short=True)]),
# Test short form citation when case name looks like a reporter
('before Johnson, 1 U. S., at 2',
[case_citation(page='2', reporter_found='U. S.', short=True,
metadata={'antecedent_guess': 'Johnson'})]),
# Test short form citation with no comma after reporter
('before asdf, 1 U. S. at 2',
[case_citation(page='2', reporter='U.S.',
reporter_found='U. S.', short=True,
metadata={'antecedent_guess': 'asdf'})]),
# Test short form citation at end of document (issue #1171)
('before asdf, 1 U. S. end', []),
# Test supra citation across line break
('before asdf, supra,\nat 2',
[supra_citation("supra,",
metadata={'pin_cite': 'at 2',
'antecedent_guess': 'asdf'})],
{'clean_steps': ['all_whitespace']}),
# Test short form citation with a page range
('before asdf, 1 U. S., at 20-25',
[case_citation(page='20', reporter_found='U. S.', short=True,
metadata={'pin_cite': '20-25',
'antecedent_guess': 'asdf'})]),
# Test short form citation with a page range with weird suffix
('before asdf, 1 U. S., at 20-25\\& n. 4',
[case_citation(page='20', reporter_found='U. S.', short=True,
metadata={'pin_cite': '20-25',
'antecedent_guess': 'asdf'})]),
# Test short form citation with a parenthetical
('before asdf, 1 U. S., at 2 (overruling xyz)',
[case_citation(page='2', reporter='U.S.',
reporter_found='U. S.', short=True,
metadata={'antecedent_guess': 'asdf',
'parenthetical': 'overruling xyz'}
)]),
# Test short form citation with no space before parenthetical
('before asdf, 1 U. S., at 2(overruling xyz)',
[case_citation(page='2', reporter='U.S.',
reporter_found='U. S.', short=True,
metadata={'antecedent_guess': 'asdf',
'parenthetical': 'overruling xyz'}
)]),
# Test short form citation with nested parentheticals
('before asdf, 1 U. S., at 2 (discussing xyz (Holmes, J., concurring))',
[case_citation(page='2', reporter='U.S.',
reporter_found='U. S.', short=True,
metadata={'antecedent_guess': 'asdf',
'parenthetical': 'discussing xyz (Holmes, J., concurring)'}
)]),
# Test that short form citation doesn't treat year as parenthetical
('before asdf, 1 U. S., at 2 (2016)',
[case_citation(page='2', reporter='U.S.',
reporter_found='U. S.', short=True,
metadata={'antecedent_guess': 'asdf'}
)]),
# Test short form citation with page range and parenthetical
('before asdf, 1 U. S., at 20-25 (overruling xyz)',
[case_citation(page='20', reporter='U.S.',
reporter_found='U. S.', short=True,
metadata={'antecedent_guess': 'asdf',
'pin_cite': '20-25',
'parenthetical': 'overruling xyz'}
)]),
# Test short form citation with subsequent unrelated parenthetical
('asdf, 1 U. S., at 4 (discussing abc). Some other nonsense (clarifying nonsense)',
[case_citation(page='4', reporter='U.S.',
reporter_found='U. S.', short=True,
metadata={'antecedent_guess': 'asdf',
'parenthetical': 'discussing abc'}
)]
),
# Test short form citation generated from non-standard regex for full cite
('1 Mich. at 1',
[case_citation(reporter='Mich.', short=True)]),
# Test parenthetical matching with multiple citations
('1 U. S., at 2. foo v. bar 3 U. S. 4 (2010) (overruling xyz).',
[case_citation(page='2', reporter='U.S.',
reporter_found='U. S.',
short=True, volume='1',
metadata={'pin_cite': '2'}),
case_citation(page='4', reporter='U.S.',
reporter_found='U. S.', short=False,
year=2010, volume='3',
metadata={'parenthetical': 'overruling xyz',
'plaintiff': 'foo', 'defendant': 'bar'})
]),
# Test with multiple citations and parentheticals
('1 U. S., at 2 (criticizing xyz). foo v. bar 3 U. S. 4 (2010) (overruling xyz).',
[case_citation(page='2', reporter='U.S.',
reporter_found='U. S.',
short=True, volume='1',
metadata={'pin_cite': '2',
'parenthetical': 'criticizing xyz'}),
case_citation(page='4', reporter='U.S.',
reporter_found='U. S.', short=False,
year=2010, volume='3',
metadata={'parenthetical': 'overruling xyz',
'plaintiff': 'foo', 'defendant': 'bar'})
]),
# Test first kind of supra citation (standard kind)
('before asdf, supra, at 2',
[supra_citation("supra,",
metadata={'pin_cite': 'at 2',
'antecedent_guess': 'asdf'})]),
# Test second kind of supra citation (with volume)
('before asdf, 123 supra, at 2',
[supra_citation("supra,",
metadata={'pin_cite': 'at 2',
'volume': '123',
'antecedent_guess': 'asdf'})]),
# Test third kind of supra citation (sans page)
('before asdf, supra, foo bar',
[supra_citation("supra,",
metadata={'antecedent_guess': 'asdf'})]),
# Test third kind of supra citation (with period)
('before asdf, supra. foo bar',
[supra_citation("supra,",
metadata={'antecedent_guess': 'asdf'})]),
# Test supra citation at end of document (issue #1171)
('before asdf, supra end',
[supra_citation("supra,",
metadata={'antecedent_guess': 'asdf'})]),
# Supra with parenthetical
('Foo, supra (overruling ...) (ignore this)',
[supra_citation("supra",
metadata={'antecedent_guess': 'Foo',
'parenthetical': 'overruling ...'})]),
('Foo, supra, at 2 (overruling ...)',
[supra_citation("supra",
metadata={'antecedent_guess': 'Foo',
'pin_cite': 'at 2',
'parenthetical': 'overruling ...'})]),
# Test Ibid. citation
('foo v. bar 1 U.S. 12. asdf. Ibid. foo bar lorem ipsum.',
[case_citation(page='12',
metadata={'plaintiff': 'foo',
'defendant': 'bar'}),
id_citation('Ibid.')]),
# Test italicized Ibid. citation
('<p>before asdf. <i>Ibid.</i></p> <p>foo bar lorem</p>',
[id_citation('Ibid.')],
{'clean_steps': ['html', 'inline_whitespace']}),
# Test Id. citation
('foo v. bar 1 U.S. 12, 347-348. asdf. Id., at 123. foo bar',
[case_citation(page='12',
metadata={'plaintiff': 'foo',
'defendant': 'bar',
'pin_cite': '347-348'}),
id_citation('Id.,',
metadata={'pin_cite': 'at 123'})]),
# Test Id. citation across line break
('foo v. bar 1 U.S. 12, 347-348. asdf. Id.,\nat 123. foo bar',
[case_citation(page='12',
metadata={'plaintiff': 'foo',
'defendant': 'bar',
'pin_cite': '347-348'}),
id_citation('Id.,', metadata={'pin_cite': 'at 123'})],
{'clean_steps': ['all_whitespace']}),
# Test italicized Id. citation
('<p>before asdf. <i>Id.,</i> at 123.</p> <p>foo bar</p>',
[id_citation('Id.,', metadata={'pin_cite': 'at 123'})],
{'clean_steps': ['html', 'inline_whitespace']}),
# Test italicized Id. citation with another HTML tag in the way
('<p>before asdf. <i>Id.,</i> at <b>123.</b></p> <p>foo bar</p>',
[id_citation('Id.,', metadata={'pin_cite': 'at 123'})],
{'clean_steps': ['html', 'inline_whitespace']}),
# Test weirder Id. citations (#1344)
('foo v. bar 1 U.S. 12, 347-348. asdf. Id. ¶ 34. foo bar',
[case_citation(page='12',
metadata={'plaintiff': 'foo',
'defendant': 'bar',
'pin_cite': '347-348'}),
id_citation('Id.', metadata={'pin_cite': '¶ 34'})]),
('foo v. bar 1 U.S. 12, 347-348. asdf. Id. at 62-63, 67-68. f b',
[case_citation(page='12',
metadata={'plaintiff': 'foo',
'defendant': 'bar',
'pin_cite': '347-348'}),
id_citation('Id.', metadata={'pin_cite': 'at 62-63, 67-68'})]),
('foo v. bar 1 U.S. 12, 347-348. asdf. Id., at *10. foo bar',
[case_citation(page='12',
metadata={'plaintiff': 'foo',
'defendant': 'bar',
'pin_cite': '347-348'}),
id_citation('Id.,', metadata={'pin_cite': 'at *10'})]),
('foo v. bar 1 U.S. 12, 347-348. asdf. Id. at 7-9, ¶¶ 38-53. f b',
[case_citation(page='12',
metadata={'plaintiff': 'foo',
'defendant': 'bar',
'pin_cite': '347-348'}),
id_citation('Id.', metadata={'pin_cite': 'at 7-9, ¶¶ 38-53'})]),
('foo v. bar 1 U.S. 12, 347-348. asdf. Id. at pp. 45, 64. foo bar',
[case_citation(page='12',
metadata={'plaintiff': 'foo',
'defendant': 'bar',
'pin_cite': '347-348'}),
id_citation('Id.', metadata={'pin_cite': 'at pp. 45, 64'})]),
# Cleanup parentheses and square brackets
('Thus, (Newbold v Arvidson, 105 Idaho 663, 672 P2d 231 [1983]) becomes (Newbold, 105 Idaho at 667, 672 P2d at 235).',
[case_citation(volume='105', reporter='Idaho', page='663',
metadata={'plaintiff': 'Newbold',
'defendant': 'Arvidson',
'extra': '672 P2d 231',
'year': '1983'}),
case_citation(volume='672', reporter='P2d', page='231',
metadata={'plaintiff': 'Newbold',
'defendant': 'Arvidson',
'year': '1983'}),
case_citation(volume='105', reporter='Idaho', page='667',
short=True,
metadata={'antecedent_guess': 'Newbold', 'pin_cite': '667'}),
case_citation(volume='672', reporter='P2d', page='235',
short=True,
metadata={'antecedent_guess': None, 'pin_cite': '235'})
]),
# Square brackets around year
('Rogers v Rogers (63 NY2d 582 [1984])',
[case_citation(volume='63', reporter='NY2d', page='582',
metadata={'plaintiff': 'Rogers',
'defendant': 'Rogers',
'year': '1984'})]
),
# Square brackets around year and court
('Mavrovich v Vanderpool, 427 F Supp 2d 1084 [D Kan 2006]',
[case_citation(volume='427', reporter='F Supp 2d', page='1084',
metadata={'plaintiff': 'Mavrovich',
'defendant': 'Vanderpool',
'court': 'ksd',
'year': '2006'})]),
# Parentheses not square brackets
('Mavrovich v Vanderpool, 427 F Supp 2d 1084 (D Kan 2006)',
[case_citation(volume='427', reporter='F Supp 2d', page='1084',
metadata={'plaintiff': 'Mavrovich',
'defendant': 'Vanderpool',
'court': 'ksd',
'year': '2006'})]),
('foo v. bar 1 U.S. 12, 347-348. asdf. id. 119:12-14. foo bar',
[case_citation(page='12',
metadata={'plaintiff': 'foo',
'defendant': 'bar',
'pin_cite': '347-348'}),
id_citation('id.', metadata={'pin_cite': '119:12-14'})]),
# Test Id. citation without page number
('foo v. bar 1 U.S. 12, 347-348. asdf. Id. No page number.',
[case_citation(page='12',
metadata={'plaintiff': 'foo',
'defendant': 'bar',
'pin_cite': '347-348'}),
id_citation('Id.')]),
# Id. with parenthetical
('Id. (overruling ...) (ignore this)',
[id_citation("Id.", metadata={'parenthetical': 'overruling ...'})]),
('Id. at 2 (overruling ...)',
[id_citation("Id.",
metadata={'pin_cite': 'at 2',
'parenthetical': 'overruling ...'})]),
# Test unknown citation
('lorem ipsum see §99 of the U.S. code.',
[unknown_citation('§99')]),
# Test address that's not a citation (#1338)
('lorem 111 S.W. 12th St.',
[],),
('lorem 111 N. W. 12th St.',
[],),
# Eyecite has issue with linebreaks when identifying defendants and
# previously could store defendant as only whitespace
('<em>\n rt. denied,\n </em>\n \n 541 U.S. 1085 (2004);\n <em>\n',
[case_citation(
page='1085',
volume="541",
reporter="U.S.",
year=2004,
metadata={'plaintiff': None,
'defendant': None,
'court': 'scotus'})],
{'clean_steps': ['html', 'inline_whitespace']}),
# Test filtering overlapping citations - this finds four citations
# but should filter down to three
("Miles v. Smith 1 Ga. 1; asdfasdf asd Something v. Else, 1 Miles 3; 1 Miles at 10",
[case_citation(page='1',
volume="1",
reporter="Ga.",
metadata={'plaintiff': 'Miles',
'defendant': 'Smith'}),
case_citation(page='3',
volume="1",
reporter="Miles",
metadata={'plaintiff': 'Something',
'defendant': 'Else'}
),
case_citation(volume="1", page='10', reporter='Miles',
short=True,
metadata={'pin_cite': '10'})]),
('General Casualty cites as compelling Amick v. Liberty Mut. Ins. Co., 455 A.2d 793 (R.I. 1983). In that case ... Stats, do. See Amick at 795',
[case_citation(page='793',
volume="455",
reporter="A.2d",
year=1983,
metadata={'plaintiff': 'Amick',
'defendant': 'Liberty Mut. Ins. Co.',
'court': 'ri'
}),
reference_citation('Amick at 795', metadata={'plaintiff': 'Amick', 'pin_cite': '795'})]),
# Test reference citation
('Foo v. Bar 1 U.S. 12, 347-348. something something, In Foo at 62 we see that',
[case_citation(page='12',
metadata={'plaintiff': 'Foo',
'defendant': 'Bar',
'pin_cite': '347-348'}),
reference_citation('Foo at 62', metadata={'plaintiff': 'Foo', 'pin_cite': '62'})]),
('Foo v. United States 1 U.S. 12, 347-348. something something ... the United States at 1776 we see that and Foo at 62',
[case_citation(page='12',
metadata={'plaintiff': 'Foo',
'defendant': 'United States',
'pin_cite': '347-348'}),
reference_citation('Foo at 62', metadata={'plaintiff': 'Foo', 'pin_cite': '62'})]),
# Test that reference citation must occur after full case citation
('In Foo at 62 we see that, Foo v. Bar 1 U.S. 12, 347-348. something something,',
[case_citation(page='12',
metadata={'plaintiff': 'Foo',
'defendant': 'Bar',
'pin_cite': '347-348'})]),
# Test reference against defendant name
('In re Foo 1 Mass. 12, 347-348. something something, in Foo at 62 we see that, ',
[case_citation(page='12', reporter="Mass.", volume="1",
metadata={'defendant': 'Foo', 'pin_cite': '347-348'}),
reference_citation('Foo at 62',
metadata={'defendant': 'Foo',
"pin_cite": "62"})]),
# Test reference citation that contains at
('In re Foo 1 Mass. 12, 347-348. something something, in at we see that',
[case_citation(page='12', reporter="Mass.", volume="1",
metadata={'defendant': 'Foo', 'pin_cite': '347-348'})]),
# Test U.S. as plaintiff with reference citations
('U.S. v. Boch Oldsmobile, Inc., 909 F.2d 657, 660 (1st Cir.1990); Piper Aircraft, 454 U.S. at 241',
[case_citation(page='657', reporter="F.2d", volume="909",
metadata={'plaintiff': 'U.S.', 'defendant': 'Boch Oldsmobile, Inc.', 'pin_cite': '660'}),
case_citation(volume="454", page='241', reporter_found='U.S.', short=True,
metadata={'antecedent_guess': 'Aircraft', 'court': "scotus", 'pin_cite': "241"})]),
# Test reference citation after an id citation
('we said in Morton v. Mancari, 417 U. S. 535, 552 (1974) “Literally every piece ....”. “asisovereign tribal entities . . . .” Id. In Mancari at 665',
[case_citation(page='535', year=1974, volume="417",
reporter="U. S.",
metadata={'plaintiff': 'Morton', 'defendant': 'Mancari', "pin_cite": "552", "court": "scotus"}),
id_citation('Id.,', metadata={}),
reference_citation('Mancari',
metadata={'defendant': 'Mancari', "pin_cite": "665"})]),
# Test Conn. Super. Ct. regex variation.
('Failed to recognize 1993 Conn. Super. Ct. 5243-P',
[case_citation(volume='1993', reporter='Conn. Super. Ct.',
page='5243-P')]),
# Test that the tokenizer handles commas after a reporter. In the
# past, " U. S. " would match but not " U. S., "
('foo 1 U.S., 1 bar',
[case_citation()]),
# Test reporter with custom regex
('blah blah Bankr. L. Rep. (CCH) P12,345. blah blah',
[case_citation(volume=None, reporter='Bankr. L. Rep.',
reporter_found='Bankr. L. Rep. (CCH)', page='12,345')]),
('blah blah, 2009 12345 (La.App. 1 Cir. 05/10/10). blah blah',
[case_citation(volume='2009', reporter='La.App. 1 Cir.',
page='12345', groups={'date_filed': '05/10/10'})]),
# Token scanning edge case -- incomplete paren at end of input
('1 U.S. 1 (', [case_citation()]),
# Token scanning edge case -- missing plaintiff name at start of input
('v. Bar, 1 U.S. 1', [case_citation(metadata={'defendant': 'Bar'})]),
# Token scanning edge case -- short form start of input
('1 U.S., at 1', [case_citation(short=True)]),
(', 1 U.S., at 1', [case_citation(short=True)]),
# Token scanning edge case -- supra at start of input
('supra.', [supra_citation("supra.")]),
(', supra.', [supra_citation("supra.")]),
('123 supra.', [supra_citation("supra.", metadata={'volume': "123"})]),
# Token scanning edge case -- Id. at end of input
('Id.', [id_citation('Id.,')]),
('Id. at 1.', [id_citation('Id.,', metadata={'pin_cite': 'at 1'})]),
('Id. foo', [id_citation('Id.,')]),
# Reject citations that are part of larger words
('foo1 U.S. 1, 1. U.S. 1foo', [],),
# Long pin cite -- make sure no catastrophic backtracking in regex
('1 U.S. 1, 2277, 2278, 2279, 2280, 2281, 2282, 2283, 2284, 2286, 2287, 2288, 2289, 2290, 2291',
[case_citation(metadata={'pin_cite': '2277, 2278, 2279, 2280, 2281, 2282, 2283, 2284, 2286, 2287, 2288, 2289, 2290, 2291'})]),
('Commonwealth v. Muniz, 164 A.3d 1189 (Pa. 2017)', [
case_citation(volume='164', reporter='A.3d', year=2017,
page='1189',
metadata={'plaintiff': 'Commonwealth', 'defendant': 'Muniz',
'court': 'pa'})]),
('Foo v. Bar, 1 F.Supp. 1 (SC 1967)', [case_citation(volume='1', reporter='F.Supp.', year=1967, page='1', metadata={'plaintiff': 'Foo', 'defendant': 'Bar', 'court': 'sc'})]),
('trial court’s ruling. (See In re K.F. (2009) 1 U.S. 1 ', [
case_citation(
year=2009, metadata={'defendant': 'K.F.', "year": "2009"})]
),
('(See In re K.F. (2009) 1 U.S. 1, 4 [92 Cal.Rptr.3d 784]; Yield Dynamics, Inc. v. TEA Systems Corp. (2007) 154 Cal.App.4th 547, 558 [66 Cal.Rptr.3d 1].)”', [
case_citation(
year=2009,
metadata={'defendant': 'K.F.', "year": "2009", 'pin_cite': '4'}
),
case_citation(
year=2009, volume='92', reporter='Cal.Rptr.3d', page='784',
metadata={'defendant': 'K.F.', "year": "2009"}
),
case_citation(
year=2007, volume='154', reporter='Cal.App.4th', page='547',
metadata={'plaintiff': 'Inc.', 'defendant': 'TEA Systems Corp.', "year": "2007", "pin_cite": "558"}
),
case_citation(
year=2007, volume='66', reporter='Cal.Rptr.3d', page='1',
metadata={'plaintiff': 'Inc.', 'defendant': 'TEA Systems Corp.', "year": "2007"}
),
])
)
# fmt: on
self.run_test_pairs(test_pairs, "Citation extraction")
def test_find_law_citations(self):
"""Can we find citations from laws.json?"""
# fmt: off
"""
see Ariz. Rev. Stat. Ann. § 36-3701 et seq. (West 2009)
63 Stat. 687 (emphasis added)
18 U. S. C. §§4241-4243
Fla. Stat. § 120.68 (2007)
"""
test_pairs = (
# Basic test
('Mass. Gen. Laws ch. 1, § 2',
[law_citation('Mass. Gen. Laws ch. 1, § 2',
reporter='Mass. Gen. Laws',
groups={'chapter': '1', 'section': '2'})]),
('1 Stat. 2',
[law_citation('1 Stat. 2',
reporter='Stat.',
groups={'volume': '1', 'page': '2'})]),
# year
('Fla. Stat. § 120.68 (2007)',
[law_citation('Fla. Stat. § 120.68 (2007)',
reporter='Fla. Stat.', year=2007,
groups={'section': '120.68'})]),
# et seq, publisher, year
('Ariz. Rev. Stat. Ann. § 36-3701 et seq. (West 2009)',
[law_citation('Ariz. Rev. Stat. Ann. § 36-3701 et seq. (West 2009)',
reporter='Ariz. Rev. Stat. Ann.',
metadata={'pin_cite': 'et seq.', 'publisher': 'West'},
groups={'section': '36-3701'},
year=2009)]),
# multiple sections
('Mass. Gen. Laws ch. 1, §§ 2-3',
[law_citation('Mass. Gen. Laws ch. 1, §§ 2-3',
reporter='Mass. Gen. Laws',
groups={'chapter': '1', 'section': '2-3'})]),
# parenthetical
('Kan. Stat. Ann. § 21-3516(a)(2) (repealed) (ignore this)',
[law_citation('Kan. Stat. Ann. § 21-3516(a)(2) (repealed)',
reporter='Kan. Stat. Ann.',
metadata={'pin_cite': '(a)(2)', 'parenthetical': 'repealed'},
groups={'section': '21-3516'})]),
# Supp. publisher
('Ohio Rev. Code Ann. § 5739.02(B)(7) (Lexis Supp. 2010)',
[law_citation('Ohio Rev. Code Ann. § 5739.02(B)(7) (Lexis Supp. 2010)',
reporter='Ohio Rev. Code Ann.',
metadata={'pin_cite': '(B)(7)', 'publisher': 'Lexis Supp.'},
groups={'section': '5739.02'},
year=2010)]),
# Year range
('Wis. Stat. § 655.002(2)(c) (2005-06)',
[law_citation('Wis. Stat. § 655.002(2)(c) (2005-06)',
reporter='Wis. Stat.',
metadata={'pin_cite': '(2)(c)'},
groups={'section': '655.002'},
year=2005)]),
# 'and' pin cite
('Ark. Code Ann. § 23-3-119(a)(2) and (d) (1987)',
[law_citation('Ark. Code Ann. § 23-3-119(a)(2) and (d) (1987)',
reporter='Ark. Code Ann.',
metadata={'pin_cite': '(a)(2) and (d)'},
groups={'section': '23-3-119'},
year=1987)]),
# Cite to multiple sections
('Mass. Gen. Laws ch. 1, §§ 2-3',
[law_citation('Mass. Gen. Laws ch. 1, §§ 2-3',
reporter='Mass. Gen. Laws',
groups={'chapter': '1', 'section': '2-3'})]),
)
# fmt: on
self.run_test_pairs(test_pairs, "Law citation extraction")
def test_find_journal_citations(self):
"""Can we find citations from journals.json?"""
# fmt: off
test_pairs = (
# Basic test
('1 Minn. L. Rev. 1',
[journal_citation()]),
# Pin cite
('1 Minn. L. Rev. 1, 2-3',
[journal_citation(metadata={'pin_cite': '2-3'})]),
# Year
('1 Minn. L. Rev. 1 (2007)',
[journal_citation(year=2007)]),
# Pin cite and year
('1 Minn. L. Rev. 1, 2-3 (2007)',
[journal_citation(metadata={'pin_cite': '2-3'}, year=2007)]),
# Pin cite and year and parenthetical
('1 Minn. L. Rev. 1, 2-3 (2007) (discussing ...) (ignore this)',
[journal_citation(year=2007,
metadata={'pin_cite': '2-3', 'parenthetical': 'discussing ...'})]),
# Year range
('77 Marq. L. Rev. 475 (1993-94)',
[journal_citation(volume='77', reporter='Marq. L. Rev.',
page='475', year=1993)]),
)
# fmt: on
self.run_test_pairs(test_pairs, "Journal citation extraction")
def test_find_tc_citations(self):
"""Can we parse tax court citations properly?"""
# fmt: off
test_pairs = (
# Test with atypical formatting for Tax Court Memos
('the 1 T.C. No. 233',
[case_citation(page='233', reporter='T.C. No.')]),
('word T.C. Memo. 2019-233',
[case_citation('T.C. Memo. 2019-233',
page='233', reporter='T.C. Memo.',
volume='2019')]),
('something T.C. Summary Opinion 2019-233',
[case_citation('T.C. Summary Opinion 2019-233',
page='233', reporter='T.C. Summary Opinion',
volume='2019')]),
('T.C. Summary Opinion 2018-133',
[case_citation('T.C. Summary Opinion 2018-133',
page='133', reporter='T.C. Summary Opinion',
volume='2018')]),
('U.S. 1234 1 U.S. 1',
[case_citation(volume='1', reporter='U.S.', page='1')]),
)
# fmt: on
self.run_test_pairs(test_pairs, "Tax court citation extraction")
def test_date_in_editions(self):
test_pairs = [
(EDITIONS_LOOKUP["S.E."], 1886, False),
(EDITIONS_LOOKUP["S.E."], 1887, True),
(EDITIONS_LOOKUP["S.E."], 1940, False),
(EDITIONS_LOOKUP["S.E.2d"], 1940, True),
(EDITIONS_LOOKUP["S.E.2d"], 2012, True),
(EDITIONS_LOOKUP["T.C.M."], 1950, True),
(EDITIONS_LOOKUP["T.C.M."], 1940, False),
(EDITIONS_LOOKUP["T.C.M."], datetime.now().year + 1, False),
]
for edition, year, expected in test_pairs:
date_in_reporter = edition[0].includes_year(year)
self.assertEqual(
date_in_reporter,
expected,
msg="is_date_in_reporter(%s, %s) != "
"%s\nIt's equal to: %s"
% (edition[0], year, expected, date_in_reporter),
)
def test_citation_filtering(self):
"""Ensure citations with overlapping spans are correctly filtered
Imagine a scenario where a bug incorrectly identifies the following
.... at Conley v. Gibson, 355 Mass. 41, 42 (1999) ...
this returns two reference citations Conley, Gibson and the full cite
this shouldn't occur but if it did we would be able to filter these
correcly
"""
citations = [
case_citation(
volume="355",
page="41",
reporter_found="U.S.",
short=False,
span_start=26,
span_end=38,
full_span_start=8,
full_span_end=49,
metadata={"plaintiff": "Conley", "defendant": "Gibson"},
),
reference_citation("Conley", span_start=8, span_end=14),
reference_citation("Gibson", span_start=18, span_end=24),
]
self.assertEqual(len(citations), 3)
filtered_citations = filter_citations(citations)
self.assertEqual(len(filtered_citations), 1)
self.assertEqual(type(filtered_citations[0]), FullCaseCitation)
def test_disambiguate_citations(self):
# fmt: off
test_pairs = [
# 1. P.R.R --> Correct abbreviation for a reporter.
('1 P.R.R. 1',
[case_citation(reporter='P.R.R.')]),
# 2. U. S. --> A simple variant to resolve.
('1 U. S. 1',
[case_citation(reporter_found='U. S.')]),
# 3. A.2d --> Not a variant, but needs to be looked up in the
# EDITIONS variable.
('1 A.2d 1',
[case_citation(reporter='A.2d')]),
# 4. A. 2d --> An unambiguous variant of an edition
('1 A. 2d 1',
[case_citation(reporter='A.2d', reporter_found='A. 2d')]),
# 5. P.R. --> A variant of 'Pen. & W.', 'P.R.R.', or 'P.' that's
# resolvable by year
('1 P.R. 1 (1831)',
# Of the three, only Pen & W. was being published this year.
[case_citation(reporter='Pen. & W.',
year=1831, reporter_found='P.R.')]),
# 5.1: W.2d --> A variant of an edition that either resolves to
# 'Wis. 2d' or 'Wash. 2d' and is resolvable by year.
('1 W.2d 1 (1854)',
# Of the two, only Wis. 2d was being published this year.
[case_citation(reporter='Wis. 2d',
year=1854, reporter_found='W.2d')]),
# 5.2: Wash. --> A non-variant that has more than one reporter for
# the key, but is resolvable by year
('1 Wash. 1 (1890)',
[case_citation(reporter='Wash.', year=1890)]),
# 6. Cr. --> A variant of Cranch, which is ambiguous, except with
# paired with this variation.
('1 Cra. 1',
[case_citation(reporter='Cranch', reporter_found='Cra.',
metadata={'court': 'scotus'})]),
# 7. Cranch. --> Not a variant, but could refer to either Cranch's
# Supreme Court cases or his DC ones. In this case, we cannot
# disambiguate. Years are not known, and we have no further
# clues. We must simply drop Cranch from the results.
('1 Cranch 1 1 U.S. 23',
[case_citation(page='23')]),
# 8. Unsolved problem. In theory, we could use parallel citations
# to resolve this, because Rob is getting cited next to La., but
# we don't currently know the proximity of citations to each
# other, so can't use this.
# - Rob. --> Either:
# 8.1: A variant of Robards (1862-1865) or
# 8.2: Robinson's Louisiana Reports (1841-1846) or
# 8.3: Robinson's Virgina Reports (1842-1865)
# ('1 Rob. 1 1 La. 1',
# [case_citation(volume='1', reporter='Rob.', page='1'),
# case_citation(volume='1', reporter='La.', page='1')]),
# 9. Johnson #1 should pass and identify the citation
('1 Johnson 1 (1890)',
[case_citation(reporter='N.M. (J.)', reporter_found='Johnson',
year=1890,
)]),
# 10. Johnson #2 should fail to disambiguate with year alone
('1 Johnson 1 (1806)', []),
]
# fmt: on
# all tests in this suite require disambiguation:
test_pairs = [
pair + ({"remove_ambiguous": True},) for pair in test_pairs
]
self.run_test_pairs(test_pairs, "Disambiguation")
def test_nominative_reporter_overlaps(self):
"""Can we parse a full citation where a name looks like a nominative
reporter?"""
pairs = [
(
"In re Cooke, 93 Wn. App. 526, 529",
case_citation(volume="93", reporter="Wn. App.", page="526"),
),
(
"Shapiro v. Thompson, 394 U. S. 618",
case_citation(volume="394", reporter="U. S.", page="618"),
),
(
"MacArdell v. Olcott, 82 N.E. 161",
case_citation(volume="82", reporter="N.E.", page="161"),
),
(
"Connecticut v. Holmes, 221 A.3d 407",
case_citation(volume="221", reporter="A.3d", page="407"),
),
(
"Kern v Taney, 11 Pa. D. & C.5th 558 [2010])",
case_citation(
volume="11", reporter="Pa. D. & C.5th", page="558"
),
),
(
"Ellenburg v. Chase, 2004 MT 66",
case_citation(volume="2004", reporter="MT", page="66"),
),
(
"Gilmer, 500 U.S. at 25;",
case_citation(
volume="500", reporter="U. S.", page="25", short=True
),
),
(
"Bison Bee, 778 F. 13 App’x at 73.",
case_citation(volume="778", reporter="F.", page="13"),
),
]
for cite_string, cite_object in pairs:
parsed_cite = get_citations(cite_string)[0]
self.assertEqual(
parsed_cite,
cite_object,
f"Nominative reporters getting in the way of parsing: {parsed_cite}",
)
def test_custom_tokenizer(self):
extractors = []
for e in EXTRACTORS:
e = copy(e)
e.regex = e.regex.replace(r"\.", r"[.,]")
if hasattr(e, "_compiled_regex"):
del e._compiled_regex
extractors.append(e)
tokenizer = Tokenizer(extractors)
# fmt: off
test_pairs = [
('1 U,S, 1',
[case_citation(reporter_found='U,S,')]),
]
# fmt: on
self.run_test_pairs(
test_pairs, "Custom tokenizer", tokenizers=[tokenizer]
)
def test_citation_fullspan(self):
"""Check that the full_span function returns the correct indices."""
# Make sure it works with several citations in one string
combined_example = "citation number one is Wilson v. Mar. Overseas Corp., 150 F.3d 1, 6-7 ( 1st Cir. 1998); This is different from Commonwealth v. Bauer, 604 A.2d 1098 (Pa.Super. 1992), my second example"
extracted = get_citations(combined_example)
# answers format is (citation_index, (full_span_start, full_span_end))
answers = [(0, (23, 86)), (1, (111, 164))]
for cit_idx, (start, end) in answers:
self.assertEqual(
extracted[cit_idx].full_span()[0],
start,
f"full_span start index doesn't match for {extracted[cit_idx]}",
)
self.assertEqual(
extracted[cit_idx].full_span()[1],
end,
f"full_span end index doesn't match for {extracted[cit_idx]}",
)