-
Notifications
You must be signed in to change notification settings - Fork 2
/
conftest.py
1615 lines (1486 loc) · 61.4 KB
/
conftest.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
from copy import deepcopy
import datetime
import json
import os
import pathlib
from typing import Any, Dict, List, Text, Tuple
from anchorpoint.textselectors import TextQuoteSelector
from dotenv import load_dotenv
from legislice.download import Client
from legislice.yaml_schemas import ExpandableEnactmentSchema as EnactmentSchema
from nettlesome.terms import ContextRegister
from nettlesome.entities import Entity
from nettlesome.predicates import Predicate
from nettlesome.quantities import Comparison, Q_
import pytest
from authorityspoke.evidence import Evidence, Exhibit
from nettlesome.factors import Factor
from authorityspoke.facts import Fact, build_fact
from authorityspoke.holdings import Holding
from authorityspoke.opinions import Opinion
from authorityspoke.pleadings import Pleading, Allegation
from authorityspoke.rules import Procedure, Rule
from authorityspoke.io import loaders, readers
from authorityspoke.io.fake_enactments import FakeClient
from authorityspoke.io.schemas_json import RawFactor, RawHolding
load_dotenv()
TOKEN = os.getenv("LEGISLICE_API_TOKEN")
API_ROOT = "https://authorityspoke.com/api/v1"
legislice_client = Client(api_token=TOKEN)
@pytest.fixture(scope="module")
def vcr_config():
return {
# Replace the Authorization request header with "DUMMY" in cassettes
"filter_headers": [("authorization", "DUMMY")],
}
@pytest.fixture(scope="class")
def test_client() -> Client:
client = Client(api_token=TOKEN, api_root=API_ROOT)
client.coverage["/us/usc"] = {
"latest_heading": "United States Code (USC)",
"first_published": datetime.date(1926, 6, 30),
"earliest_in_db": datetime.date(2013, 7, 18),
"latest_in_db": datetime.date(2020, 8, 8),
}
client.coverage["/test/acts"] = {
"latest_heading": "Test Acts",
"first_published": datetime.date(1935, 4, 1),
"earliest_in_db": datetime.date(1935, 4, 1),
"latest_in_db": datetime.date(2013, 7, 18),
}
return client
@pytest.fixture(scope="class")
def section6d():
return {
"heading": "Waiver of beard tax in special circumstances",
"content": "",
"children": [
{
"heading": "",
"content": "The Department of Beards shall waive the collection of beard tax upon issuance of beardcoin under Section 6C where the reason the maintainer wears a beard is due to bona fide religious, cultural, or medical reasons.",
"children": [],
"end_date": None,
"node": "/test/acts/47/6D/1",
"start_date": "2013-07-18",
"url": "http://127.0.0.1:8000/api/v1/test/acts/47/6D/1@2018-03-11/",
},
{
"heading": "",
"content": "The determination of the Department of Beards as to what constitutes bona fide religious or cultural reasons shall be final and no right of appeal shall exist.",
"children": [],
"end_date": None,
"node": "/test/acts/47/6D/2",
"start_date": "1935-04-01",
"url": "http://127.0.0.1:8000/api/v1/test/acts/47/6D/2@2018-03-11/",
},
],
"end_date": None,
"node": "/test/acts/47/6D",
"start_date": "1935-04-01",
"url": "http://127.0.0.1:8000/api/v1/test/acts/47/6D@2018-03-11/",
"parent": "http://127.0.0.1:8000/api/v1/test/acts/47@2018-03-11/",
}
@pytest.fixture(scope="function")
def section_11_subdivided():
return {
"heading": "Licensed repurchasers of beardcoin",
"start_date": "2013-07-18",
"node": "/test/acts/47/11",
"text_version": {
"id": 1142710,
"url": "https://authorityspoke.com/api/v1/textversions/1142710/",
"content": "The Department of Beards may issue licenses to such",
},
"url": "https://authorityspoke.com/api/v1/test/acts/47/11/",
"end_date": None,
"children": [
{
"heading": "",
"start_date": "2013-07-18",
"node": "/test/acts/47/11/i",
"text_version": {
"id": 1142704,
"url": "https://authorityspoke.com/api/v1/textversions/1142704/",
"content": "barbers,",
},
"url": "https://authorityspoke.com/api/v1/test/acts/47/11/i/",
"end_date": None,
"children": [],
"citations": [],
},
{
"heading": "",
"start_date": "2013-07-18",
"node": "/test/acts/47/11/ii",
"text_version": {
"id": 1142705,
"url": "https://authorityspoke.com/api/v1/textversions/1142705/",
"content": "hairdressers, or",
},
"url": "https://authorityspoke.com/api/v1/test/acts/47/11/ii/",
"end_date": None,
"children": [],
"citations": [],
},
{
"heading": "",
"start_date": "2013-07-18",
"node": "/test/acts/47/11/iii",
"text_version": {
"id": 1142706,
"url": "https://authorityspoke.com/api/v1/textversions/1142706/",
"content": "other male grooming professionals",
},
"url": "https://authorityspoke.com/api/v1/test/acts/47/11/iii/",
"end_date": None,
"children": [],
"citations": [],
},
{
"heading": "",
"start_date": "2013-07-18",
"node": "/test/acts/47/11/iii-con",
"text_version": {
"id": 1142707,
"url": "https://authorityspoke.com/api/v1/textversions/1142707/",
"content": "as they see fit to purchase a beardcoin from a customer",
},
"url": "https://authorityspoke.com/api/v1/test/acts/47/11/iii-con/",
"end_date": None,
"children": [],
"citations": [],
},
{
"heading": "",
"start_date": "2013-07-18",
"node": "/test/acts/47/11/iv",
"text_version": {
"id": 1142708,
"url": "https://authorityspoke.com/api/v1/textversions/1142708/",
"content": "whose beard they have removed,",
},
"url": "https://authorityspoke.com/api/v1/test/acts/47/11/iv/",
"end_date": None,
"children": [],
"citations": [],
},
{
"heading": "",
"start_date": "2013-07-18",
"node": "/test/acts/47/11/iv-con",
"text_version": {
"id": 1142709,
"url": "https://authorityspoke.com/api/v1/textversions/1142709/",
"content": "and to resell those beardcoins to the Department of Beards.",
},
"url": "https://authorityspoke.com/api/v1/test/acts/47/11/iv-con/",
"end_date": None,
"children": [],
"citations": [],
},
],
"citations": [],
"parent": "https://authorityspoke.com/api/v1/test/acts/47/",
}
@pytest.fixture(scope="module")
def fifth_a():
return {
"heading": "AMENDMENT V.",
"content": "No person shall be held to answer for a capital, or otherwise infamous crime, unless on a presentment or indictment of a Grand Jury, except in cases arising in the land or naval forces, or in the Militia, when in actual service in time of War or public danger; nor shall any person be subject for the same offence to be twice put in jeopardy of life or limb; nor shall be compelled in any Criminal Case to be a witness against himself; nor be deprived of life, liberty, or property, without due process of law; nor shall private property be taken for public use, without just compensation.",
"children": [],
"end_date": None,
"node": "/us/const/amendment/V",
"start_date": "1791-12-15",
"url": "https://authorityspoke.com/api/v1/us/const/amendment/V/",
"parent": "https://authorityspoke.com/api/v1/us/const/amendment/",
"selection": True,
}
@pytest.fixture(scope="class")
def make_entity() -> Dict[str, Entity]:
return {
"motel": Entity("Hideaway Lodge"),
"motel_specific": Entity("Hideaway Lodge", generic=False),
"watt": Entity("Wattenburg"),
"trees": Entity("the stockpile of trees"),
"trees_specific": Entity("the stockpile of trees", generic=False),
"tree_search": Entity("officers' search of the stockpile of trees"),
"tree_search_specific": Entity(
"officers' search of the stockpile of trees", generic=False
),
"alice": Entity("Alice"),
"bob": Entity("Bob"),
"craig": Entity("Craig"),
"dan": Entity("Dan"),
"circus": Entity("circus"),
}
@pytest.fixture(scope="class")
def make_predicate() -> Dict[str, Predicate]:
return {
"p1": Predicate("$place was a motel"),
"p1_again": Predicate("$place was a motel"),
"p2": Predicate("$person operated and lived at $place"),
"p2_reflexive": Predicate("$person operated and lived at $person"),
"p2_no_truth": Predicate("$person operated and lived at $place", truth=None),
"p2_false": Predicate("$person operated and lived at $place", truth=False),
"p3": Predicate("$place was ${person}’s abode"),
"p3_false": Predicate("$place was ${person}’s abode", truth=False),
"p4": Predicate("$thing was on the premises of $place"),
"p5": Predicate("$thing was a stockpile of Christmas trees"),
"p6": Predicate("$thing was among some standing trees"),
"p7": Comparison(
"the distance between $place1 and $place2 was",
truth=False,
sign=">",
expression=Q_("35 feet"),
),
"p7_obverse": Comparison(
"the distance between $place1 and $place2 was",
truth=True,
sign="<=",
expression=Q_("35 feet"),
),
"p7_opposite": Comparison(
"the distance between $place1 and $place2 was",
truth=True,
sign=">",
expression=Q_("35 feet"),
),
"p7_not_equal": Comparison(
"the distance between $place1 and $place2 was",
truth=True,
sign="<>",
expression=Q_("35 feet"),
),
"p7_true": Comparison(
"the distance between $place1 and $place2 was",
truth=True,
sign="<",
expression=Q_("35 feet"),
),
"p8": Comparison(
"the distance between $place1 and $place2 was",
sign=">=",
expression=Q_("20 feet"),
),
"p8_no_truth": Comparison(
"the distance between $place1 and $place2 was",
truth=None,
sign=">=",
expression=Q_("20 feet"),
),
"p8_exact": Comparison(
"the distance between $place1 and $place2 was",
sign="==",
expression=Q_("25 feet"),
),
"p8_less": Comparison(
"the distance between $place1 and $place2 was",
sign="<=",
expression=Q_("20 feet"),
),
"p8_meters": Comparison(
"the distance between $place1 and $place2 was",
sign=">=",
expression=Q_("10 meters"),
),
"p8_int": Comparison(
"the distance between $place1 and $place2 was",
sign=">=",
expression=20,
),
"p8_float": Comparison(
"the distance between $place1 and $place2 was",
sign=">=",
expression=20.0,
),
"p8_higher_int": Comparison(
"the distance between $place1 and $place2 was",
sign=">=",
expression=30,
),
"p9": Comparison(
"the distance between $thing and a parking area used by personnel and patrons of $place was",
sign="<=",
expression=Q_("5 feet"),
),
"p9_exact": Comparison(
"the distance between $thing and a parking area used by personnel and patrons of $place was",
sign="=",
expression=Q_("5 feet"),
),
"p9_miles": Comparison(
"the distance between $thing and a parking area used by personnel and patrons of $place was",
sign="<=",
expression=Q_("5 miles"),
),
"p9_more": Comparison(
"the distance between $thing and a parking area used by personnel and patrons of $place was",
sign=">",
expression=Q_("5 feet"),
),
"p9_acres": Comparison(
"the distance between $thing and a parking area used by personnel and patrons of $place was",
sign="<=",
expression=Q_("5 acres"),
),
"p10": Predicate("$thing was within the curtilage of $place"),
"p10_false": Predicate(
"$thing was within the curtilage of $place", truth=False
),
"p11": Predicate("$act was a warrantless search and seizure"),
"p12": Predicate("$act was performed by federal law enforcement officers"),
"p13": Predicate("$act constituted an intrusion upon $place"),
"p14": Predicate("$person sought to preserve $thing as private"),
"p15": Predicate("$thing was in an area adjacent to $place"),
"p16": Predicate("$thing was in an area accessible to the public"),
"p17": Predicate(
"In $act, several law enforcement officials meticulously went through $thing"
),
"p18": Comparison(
"the length of time that $act continued was",
sign=">=",
expression=Q_("385 minutes"),
),
"p19": Predicate("$act continued after night fell"),
# Use the irrelevant predicates/factors to make sure they don't affect an outcome.
"p_irrelevant_0": Predicate("$person was a clown"),
"p_irrelevant_1": Predicate("$person was a bear"),
"p_irrelevant_2": Predicate("$place was a circus"),
"p_irrelevant_3": Predicate("$person performed at $place"),
"p_crime": Predicate("$person committed a crime"),
"p_murder": Predicate("$shooter murdered $victim"),
"p_murder_whether": Predicate("$shooter murdered $victim", truth=None),
"p_murder_false": Predicate("$shooter murdered $victim", truth=False),
"p_irrelevant": Predicate("$evidence is relevant to show $fact", truth=False),
"p_relevant": Predicate("$evidence is relevant to show $fact"),
"p_relevant_whether": Predicate(
"$evidence is relevant to show $fact", truth=None
),
"p_shooting": Predicate("$shooter shot $victim"),
"p_shooting_self": Predicate("$shooter shot $shooter"),
"p_no_shooting": Predicate("$shooter shot $victim", truth=False),
"p_shooting_whether": Predicate("$shooter shot $victim", truth=None),
"p_no_crime": Predicate("$person1 committed a crime", truth=False),
"p_three_entities": Predicate("$planner told $intermediary to hire $shooter"),
"p_small_weight": Comparison(
"the amount of gold $person possessed was",
sign=">=",
expression=Q_("1 gram"),
),
"p_large_weight": Comparison(
"the amount of gold $person possessed was",
sign=">=",
expression=Q_("100 kilograms"),
),
"p_friends": Predicate("$person1 and $person2 were friends"),
"p_reliable": Predicate("$evidence was reliable"),
"p_quantity=3": Comparison("The number of mice was", sign="==", expression=3),
"p_quantity>=4": Comparison("The number of mice was", sign=">=", expression=4),
"p_quantity>5": Comparison("The number of mice was", sign=">", expression=5),
"p_no_context": Predicate("context was included", truth=False),
}
@pytest.fixture(scope="class")
def watt_mentioned(make_entity) -> Tuple[Entity, ...]:
e = make_entity
return (e["motel"], e["watt"], e["trees"], e["tree_search"], e["motel_specific"])
@pytest.fixture(scope="class")
def watt_factor(make_predicate, make_entity, watt_mentioned) -> Dict[str, Factor]:
p = make_predicate
c = watt_mentioned
return {
"f1": build_fact(p["p1"], case_factors=c),
"f2": build_fact(p["p2"], (1, 0), case_factors=c),
"f3": build_fact(p["p3"], case_factors=c),
"f4": build_fact(p["p4"], (2, 0), case_factors=c),
"f5": build_fact(p["p5"], 2, case_factors=c),
"f6": build_fact(p["p6"], 2, case_factors=c),
"f7": build_fact(p["p7"], (0, 2), case_factors=c),
"f8": build_fact(p["p8"], (0, 2), case_factors=c),
"f9": build_fact(p["p9"], (2, 0), case_factors=c),
"f10": build_fact(p["p10"], (2, 0), case_factors=c),
"f1_entity_order": build_fact(p["p1"], (1,), case_factors=c),
"f1_different_entity": build_fact(p["p1"], (2,), case_factors=c),
"f1_specific": build_fact(p["p1"], (4,), case_factors=c),
"f1b": build_fact(p["p1"], case_factors=c),
"f1c": build_fact(p["p1_again"], case_factors=c),
"f2_preponderance_of_evidence": build_fact(
p["p2"],
(1, 0),
standard_of_proof="preponderance of evidence",
case_factors=c,
),
"f2_clear_and_convincing": build_fact(
p["p2"], (1, 0), standard_of_proof="clear and convincing", case_factors=c
),
"f2_beyond_reasonable_doubt": build_fact(
p["p2"], (1, 0), standard_of_proof="beyond reasonable doubt", case_factors=c
),
"f2_different_entity": build_fact(p["p2"], (1, 2), case_factors=c),
"f2_entity_order": build_fact(p["p2"], case_factors=c),
"f2_no_truth": build_fact(p["p2_no_truth"], (1, 0), case_factors=c),
"f2_false": build_fact(p["p2_false"], case_factors=c),
"f2_false_absent": build_fact(p["p2_false"], absent=True, case_factors=c),
"f2_reflexive": build_fact(p["p2_reflexive"], case_factors=c),
"f2_generic": build_fact(p["p2"], generic=True, case_factors=c),
"f2_false_generic": build_fact(p["p2_false"], generic=True, case_factors=c),
"f3_generic": build_fact(p["p3"], generic=True, case_factors=c),
"f3_different_entity": build_fact(p["p3"], (2, 1), case_factors=c),
"f3_entity_order": build_fact(p["p3"], (1, 0), case_factors=c),
"f3_absent": build_fact(p["p3"], absent=True, case_factors=c),
"f4_h4": build_fact(p["p4"], (3, 0), case_factors=c),
"f4_swap_entities": build_fact(p["p4"], (0, 2), case_factors=c),
"f4_swap_entities_4": build_fact(p["p4"], (1, 4), case_factors=c),
"f5_h4": build_fact(p["p5"], (3,), case_factors=c),
"f5_swap_entities": build_fact(p["p5"], (0,), case_factors=c),
"f6_swap_entities": build_fact(p["p6"], (0,), case_factors=c),
"f7_opposite": build_fact(p["p7_opposite"], (0, 2), case_factors=c),
"f7_swap_entities": build_fact(p["p7"], (2, 0), case_factors=c),
"f7_swap_entities_4": build_fact(p["p7"], (1, 4), case_factors=c),
"f7_true": build_fact(p["p7_true"], (0, 2), case_factors=c),
"f8_absent": build_fact(p["p8"], (0, 2), absent=True, case_factors=c),
"f8_exact": build_fact(p["p8_exact"], (0, 2), case_factors=c),
"f8_exact_swap_entities": build_fact(p["p8_exact"], (2, 0), case_factors=c),
"f8_float": build_fact(p["p8_float"], (0, 2), case_factors=c),
"f8_higher_int": build_fact(p["p8_higher_int"], (0, 2), case_factors=c),
"f8_int": build_fact(p["p8_int"], (0, 2), case_factors=c),
"f8_less": build_fact(p["p8_less"], (0, 2), case_factors=c),
"f8_less_absent": build_fact(p["p8_less"], (0, 2), absent=True, case_factors=c),
"f8_meters": build_fact(p["p8_meters"], (0, 2), case_factors=c),
"f8_no_truth": build_fact(p["p8_no_truth"], (0, 2), case_factors=c),
"f9_absent": build_fact(p["p9"], (2, 0), absent=True, case_factors=c),
"f9_miles": build_fact(p["p9_miles"], (2, 0), case_factors=c),
"f9_absent_miles": build_fact(
p["p9_miles"], (2, 0), absent=True, case_factors=c
),
"f9_more_different_entity": Fact(
p["p9_more"], (make_entity["circus"], make_entity["motel"])
),
"f9_swap_entities": build_fact(p["p9"], (0, 2), case_factors=c),
"f9_swap_entities_4": build_fact(p["p9"], (1, 4), case_factors=c),
"f10_absent": build_fact(p["p10"], (2, 0), absent=True, case_factors=c),
"f10_false": build_fact(p["p10_false"], (2, 0), case_factors=c),
"f10_absent_false": build_fact(p["p10_false"], absent=True, case_factors=c),
"f10_swap_entities": build_fact(p["p10"], (0, 2), case_factors=c),
"f10_swap_entities_4": build_fact(p["p10"], (1, 4), case_factors=c),
"f11": build_fact(p["p11"], 3, case_factors=c),
"f12": build_fact(p["p12"], 3, case_factors=c),
"f13": build_fact(p["p13"], (3, 2), case_factors=c),
"f14": build_fact(p["p14"], (1, 2), case_factors=c),
"f15": build_fact(p["p15"], (2, 0), case_factors=c),
"f16": build_fact(p["p16"], 2, case_factors=c),
"f17": build_fact(p["p17"], (2, 3), case_factors=c),
"f18": build_fact(p["p18"], 2, case_factors=c),
"f19": build_fact(p["p19"], 2, case_factors=c),
}
@pytest.fixture(scope="class")
def make_factor(make_predicate, make_entity) -> Dict[str, Factor]:
p = make_predicate
e = make_entity
c = (e["alice"], e["bob"], e["craig"], e["dan"], e["circus"])
return {
"f_irrelevant_0": build_fact(p["p_irrelevant_0"], (2,), case_factors=c),
"f_irrelevant_1": build_fact(p["p_irrelevant_1"], (3,), case_factors=c),
"f_irrelevant_2": build_fact(p["p_irrelevant_2"], (4,), case_factors=c),
"f_irrelevant_3": build_fact(p["p_irrelevant_3"], (2, 4), case_factors=c),
"f_irrelevant_3_new_context": build_fact(
p["p_irrelevant_3"], (3, 4), case_factors=c
),
"f_irrelevant_3_context_0": build_fact(
p["p_irrelevant_3"], (3, 0), case_factors=c
),
"f_crime": build_fact(p["p_crime"], case_factors=c),
"f_crime_craig_poe": Fact(
p["p_crime"],
terms=e["craig"],
standard_of_proof="preponderance of evidence",
),
"f_watt_crime": build_fact(p["p_crime"], case_factors=make_entity["watt"]),
"f_no_crime": build_fact(p["p_no_crime"], case_factors=c),
"f_no_crime_entity_order": build_fact(p["p_no_crime"], (1,), case_factors=c),
"f_murder": build_fact(p["p_murder"], case_factors=c),
"f_no_murder": build_fact(p["p_murder_false"], case_factors=c),
"f_murder_entity_swap": build_fact(p["p_murder"], (1, 0), case_factors=c),
"f_murder_craig": build_fact(p["p_murder"], (2, 3), case_factors=c),
"f_murder_whether": build_fact(p["p_murder_whether"], case_factors=c),
"f_shooting": build_fact(p["p_shooting"], case_factors=c),
"f_shooting_self": build_fact(p["p_shooting_self"], case_factors=c),
"f_shooting_craig": build_fact(p["p_shooting"], (2, 3), case_factors=c),
"f_shooting_craig_poe": build_fact(
p["p_shooting"],
(2, 3),
case_factors=c,
standard_of_proof="preponderance of evidence",
),
"f_shooting_craig_brd": build_fact(
p["p_shooting"],
(2, 3),
case_factors=c,
standard_of_proof="beyond reasonable doubt",
),
"f_shooting_entity_order": build_fact(p["p_shooting"], (1, 0), case_factors=c),
"f_no_shooting": build_fact(p["p_no_shooting"], case_factors=c),
"f_shooting_whether": build_fact(p["p_shooting_whether"], case_factors=c),
"f_no_shooting_entity_order": build_fact(
p["p_no_shooting"], (1, 0), case_factors=c
),
"f_three_entities": build_fact(
p["p_three_entities"], (0, 1, 2), case_factors=c
),
"f_large_weight": build_fact(p["p_large_weight"], (0,), case_factors=c),
"f_small_weight": build_fact(p["p_small_weight"], (0,), case_factors=c),
"f_friends": build_fact(p["p_friends"], (0, 1), case_factors=c),
"f_no_context": build_fact(p["p_no_context"], case_factors=c),
}
@pytest.fixture(scope="class")
def make_exhibit(
make_entity, make_predicate, make_factor, watt_factor, make_complex_fact
) -> Dict[str, Exhibit]:
e = make_entity
f = make_factor
w = watt_factor
c = make_complex_fact
return {
"shooting_affidavit": Exhibit(
form="affidavit",
statement=f["f_shooting"],
statement_attribution=e["alice"],
),
"shooting_testimony": Exhibit(
form="testimony",
statement=f["f_shooting"],
statement_attribution=e["alice"],
),
"no_shooting_testimony": Exhibit(
form="testimony",
statement=f["f_no_shooting"],
statement_attribution=e["alice"],
),
"no_shooting_entity_order_testimony": Exhibit(
form="testimony",
statement=f["f_no_shooting_entity_order"],
statement_attribution=e["bob"],
),
"no_shooting_witness_unknown_testimony": Exhibit(
form="testimony", statement=f["f_no_shooting"]
),
"no_shooting_witness_unknown_absent_testimony": Exhibit(
form="testimony", statement=f["f_no_shooting"], absent=True
),
"no_shooting_different_witness_testimony": Exhibit(
form="testimony",
statement=f["f_no_shooting"],
statement_attribution=e["bob"],
),
"reciprocal_testimony": Exhibit(
form="testimony", statement=w["f8"], statement_attribution=e["craig"]
),
"reciprocal_declaration": Exhibit(
form="declaration", statement=w["f8"], statement_attribution=e["craig"]
),
"reciprocal_testimony_absent": Exhibit(
form="testimony",
statement=w["f8"],
statement_attribution=e["craig"],
absent=True,
),
"reciprocal_testimony_less": Exhibit(
form="testimony", statement=w["f8_less"], statement_attribution=e["craig"]
),
"reciprocal_testimony_specific": Exhibit(
form="testimony", statement=w["f8_meters"], statement_attribution=e["craig"]
),
"reciprocal_testimony_specific_absent": Exhibit(
form="testimony",
statement=w["f8_meters"],
statement_attribution=e["craig"],
absent=True,
),
"relevant_murder_testimony": Exhibit(
form="testimony",
statement=c["f_relevant_murder"],
statement_attribution=e["alice"],
),
"relevant_murder_nested_swap_testimony": Exhibit(
form="testimony",
statement=c["f_relevant_murder_nested_swap"],
statement_attribution=e["bob"],
),
"relevant_murder_alice_craig_testimony": Exhibit(
form="testimony",
statement=c["f_relevant_murder_alice_craig"],
statement_attribution=e["alice"],
),
"large_weight_testimony": Exhibit(
form="testimony",
statement=f["f_large_weight"],
statement_attribution=e["bob"],
),
"small_weight_testimony": Exhibit(
form="testimony",
statement=f["f_small_weight"],
statement_attribution=e["bob"],
),
"generic_exhibit": Exhibit(generic=True),
"specific_but_featureless": Exhibit(),
"testimony_no_statement": Exhibit(form="testimony"),
}
@pytest.fixture(scope="class")
def make_complex_fact(make_predicate, make_factor) -> Dict[str, Fact]:
p = make_predicate
f = make_factor
return {
"f_irrelevant_murder": Fact(
p["p_irrelevant"], (f["f_shooting"], f["f_murder"])
),
"f_relevant_murder": Fact(p["p_relevant"], (f["f_shooting"], f["f_murder"])),
"f_relevant_murder_swap_entities": Fact(
p["p_relevant"], (f["f_shooting"], f["f_murder"])
),
"f_relevant_murder_nested_swap": Fact(
p["p_relevant"], (f["f_shooting_entity_order"], f["f_murder_entity_swap"])
),
"f_relevant_murder_whether": Fact(
p["p_relevant"], (f["f_shooting"], f["f_murder_whether"])
),
"f_whether_relevant_murder_whether": Fact(
p["p_relevant"], (f["f_shooting_whether"], f["f_murder_whether"])
),
"f_relevant_murder_swap": Fact(
p["p_relevant"], (f["f_shooting"], f["f_murder_entity_swap"])
),
"f_relevant_murder_craig": Fact(
p["p_relevant"], (f["f_shooting_craig"], f["f_murder_craig"])
),
"f_relevant_murder_alice_craig": Fact(
p["p_relevant"], (f["f_shooting"], f["f_murder_craig"])
),
}
@pytest.fixture(scope="class")
def make_fact_about_exhibit(make_predicate, make_exhibit) -> Dict[str, Evidence]:
p = make_predicate
e = make_exhibit
return {
"f_reliable_large_weight": Fact(
p["p_reliable"], (e["large_weight_testimony"],)
),
"f_reliable_small_weight": Fact(
p["p_reliable"], (e["small_weight_testimony"],)
),
}
@pytest.fixture(scope="class")
def make_complex_rule(
make_factor, make_exhibit, make_complex_fact, make_fact_about_exhibit
) -> Dict[str, Rule]:
return {
"accept_relevance_testimony": Rule(
Procedure(
inputs=make_exhibit["relevant_murder_testimony"],
outputs=make_complex_fact["f_relevant_murder"],
)
),
"accept_relevance_testimony_ALL": Rule(
Procedure(
inputs=make_exhibit["relevant_murder_testimony"],
outputs=make_complex_fact["f_relevant_murder"],
),
universal=True,
),
"accept_murder_fact_from_relevance": Rule(
Procedure(
inputs=make_complex_fact["f_relevant_murder"],
outputs=make_factor["f_murder"],
)
),
"accept_murder_fact_from_relevance_and_shooting": Rule(
Procedure(
inputs=[
make_complex_fact["f_relevant_murder"],
make_factor["f_shooting"],
],
outputs=make_factor["f_murder"],
)
),
"accept_murder_fact_from_relevance_and_shooting_craig": Rule(
Procedure(
inputs=[
make_complex_fact["f_relevant_murder_craig"],
make_factor["f_shooting_craig"],
],
outputs=make_factor["f_murder_craig"],
)
),
"accept_small_weight_reliable": Rule(
Procedure(
inputs=[make_factor["f_small_weight"], make_factor["f_friends"]],
outputs=make_fact_about_exhibit["f_reliable_small_weight"],
),
universal=True,
),
"accept_small_weight_reliable_more_evidence": Rule(
Procedure(
inputs=[make_factor["f_large_weight"], make_factor["f_friends"]],
outputs=make_fact_about_exhibit["f_reliable_small_weight"],
),
universal=True,
),
"accept_large_weight_reliable": Rule(
Procedure(
inputs=[make_factor["f_small_weight"], make_factor["f_friends"]],
outputs=make_fact_about_exhibit["f_reliable_large_weight"],
),
universal=True,
),
}
@pytest.fixture(scope="class")
def make_evidence(
make_predicate, make_factor, watt_factor, make_exhibit
) -> Dict[str, Evidence]:
p = make_predicate
f = make_factor
w = watt_factor
x = make_exhibit
return {
"shooting": Evidence(x["shooting_testimony"], to_effect=f["f_crime"]),
"shooting_no_effect": Evidence(x["shooting_testimony"]),
"no_shooting": Evidence(x["no_shooting_testimony"], to_effect=f["f_no_crime"]),
"no_shooting_absent": Evidence(
x["no_shooting_testimony"], to_effect=f["f_no_crime"], absent=True
),
"no_shooting_entity_order": Evidence(
x["no_shooting_entity_order_testimony"],
to_effect=f["f_no_crime_entity_order"],
),
"no_shooting_witness_unknown": Evidence(
x["no_shooting_witness_unknown_testimony"], to_effect=f["f_no_crime"]
),
"no_shooting_witness_unknown_absent": Evidence(
x["no_shooting_witness_unknown_testimony"],
to_effect=f["f_no_crime"],
absent=True,
),
# Here the Exhibit is absent, not the Evidence. Pointless distinction?
"no_shooting_witness_unknown_absent_exhibit": Evidence(
x["no_shooting_witness_unknown_absent_testimony"], to_effect=f["f_no_crime"]
),
"no_shooting_no_effect_entity_order": Evidence(
x["no_shooting_entity_order_testimony"]
),
"no_shooting_different_witness": Evidence(
x["no_shooting_different_witness_testimony"], to_effect=f["f_no_crime"]
),
"reciprocal": Evidence(x["reciprocal_testimony"], to_effect=f["f_no_crime"]),
"crime": Evidence(
x["generic_exhibit"], to_effect=f["f_watt_crime"], generic=True
),
"crime_absent": Evidence(
x["generic_exhibit"], to_effect=f["f_watt_crime"], absent=True, generic=True
),
"generic": Evidence(x["generic_exhibit"], generic=True),
"generic_absent": Evidence(x["generic_exhibit"], absent=True, generic=True),
}
@pytest.fixture(scope="class")
def make_pleading(make_entity) -> Dict[str, Dict[str, Pleading]]:
return {"craig": Pleading(filer=make_entity["craig"])}
@pytest.fixture(scope="class")
def make_allegation(make_pleading, make_factor) -> Dict[str, Dict[str, Allegation]]:
return {
"shooting": Allegation(
statement=make_factor["f_shooting"], pleading=make_pleading["craig"]
)
}
@pytest.fixture(scope="module")
def make_selector() -> Dict[str, TextQuoteSelector]:
return {
"bad_selector": TextQuoteSelector(exact="text that doesn't exist in the code"),
"preexisting material": TextQuoteSelector(
exact=(
"protection for a work employing preexisting material in which "
+ "copyright subsists does not extend to any part of the work in "
+ "which such material has been used unlawfully."
)
),
"copyright": TextQuoteSelector(suffix="idea, procedure,"),
"copyright_requires_originality": TextQuoteSelector(
suffix="fixed in any tangible"
),
}
@pytest.fixture(scope="module")
def make_response() -> Dict[str, Dict]:
"""Mock api responses"""
this_directory = os.path.dirname(os.path.abspath(__file__))
parent_directory = os.path.dirname(this_directory)
responses_filepath = parent_directory + "/example_data/responses/usc.json"
with open(responses_filepath, "r") as f:
responses = json.load(f)
return responses
@pytest.fixture(scope="module")
def fake_usc_client() -> FakeClient:
return FakeClient.from_file("usc.json")
@pytest.fixture(scope="module")
def beard_response() -> Dict[str, Dict]:
"""Mock api responses"""
this_directory = os.path.dirname(os.path.abspath(__file__))
parent_directory = os.path.dirname(this_directory)
responses_filepath = parent_directory + "/example_data/responses/beard_act.json"
with open(responses_filepath, "r") as f:
responses = json.load(f)
return responses
@pytest.fixture(scope="module")
def fake_beard_client() -> FakeClient:
return FakeClient.from_file("beard_act.json")
@pytest.fixture(scope="module")
def e_fourth_a(make_response):
schema = EnactmentSchema()
enactment = schema.load(make_response["/us/const/amendment/IV"]["1791-12-15"])
enactment.select_all()
return enactment
@pytest.fixture(scope="module")
def e_search_clause(make_response):
schema = EnactmentSchema()
enactment = schema.load(make_response["/us/const/amendment/IV"]["1791-12-15"])
selector = TextQuoteSelector(suffix=", and no Warrants shall issue")
enactment.select(selector)
return enactment
@pytest.fixture(scope="module")
def e_warrants_clause(make_response):
schema = EnactmentSchema()
enactment = schema.load(make_response["/us/const/amendment/IV"]["1791-12-15"])
enactment.select("shall not be violated, and no Warrants shall issue,")
return enactment
@pytest.fixture(scope="module")
def e_due_process_5(make_response):
schema = EnactmentSchema()
enactment = schema.load(make_response["/us/const/amendment/V"]["1791-12-15"])
enactment.select("life, liberty, or property, without due process of law")
return enactment
@pytest.fixture(scope="module")
def e_due_process_14(make_response):
schema = EnactmentSchema()
fourteenth = make_response["/us/const/amendment/XIV"]["1868-07-28"]
enactment = schema.load(fourteenth["children"][0])
enactment.select("life, liberty, or property, without due process of law")
return enactment
@pytest.fixture(scope="module")
def e_securing_for_authors(make_response):
schema = EnactmentSchema()
enactment = schema.load(make_response["/us/const/article/I/8/8"]["1788-09-13"])
selector = TextQuoteSelector(
exact=(
"To promote the Progress of Science and "
+ "useful Arts, by securing for limited Times to Authors"
)
)
enactment.select(selector)
return enactment
@pytest.fixture(scope="module")
def e_securing_exclusive_right_to_writings(make_response):
schema = EnactmentSchema()
enactment = schema.load(make_response["/us/const/article/I/8/8"]["1788-09-13"])
enactment.select(
"To promote the Progress of Science and useful Arts, by securing for limited Times to Authors"
)
enactment.select_more("the exclusive Right to their respective Writings")
return enactment
@pytest.fixture(scope="module")
def e_and_inventors(make_response):
schema = EnactmentSchema()
enactment = schema.load(make_response["/us/const/article/I/8/8"]["1788-09-13"])
enactment.select("and Inventors")
return enactment
@pytest.fixture(scope="module")
def e_right_to_writings(make_response):
schema = EnactmentSchema()
enactment = schema.load(make_response["/us/const/article/I/8/8"]["1788-09-13"])
enactment.select("the exclusive Right to their respective Writings")
return enactment
@pytest.fixture(scope="module")
def e_copyright_protection(make_response, make_selector):
schema = EnactmentSchema()
enactment = schema.load(make_response["/us/usc/t17/s102/a"]["2013-07-18"])
enactment.select(TextQuoteSelector(suffix="Works of authorship include"))
return enactment
@pytest.fixture(scope="module")
def e_copyright_requires_originality(make_response, make_selector):
schema = EnactmentSchema()
enactment = schema.load(make_response["/us/usc/t17/s102/a"]["2013-07-18"])
enactment.select(make_selector["copyright_requires_originality"])
return enactment
@pytest.fixture(scope="module")
def e_copyright(make_response, make_selector):
schema = EnactmentSchema()
enactment = schema.load(make_response["/us/usc/t17/s102/b"]["2013-07-18"])
enactment.select(make_selector["copyright"])
return enactment
@pytest.fixture(scope="module")
def e_copyright_exceptions(make_response):
schema = EnactmentSchema()
enactment = schema.load(make_response["/us/usc/t17/s102/b"]["2013-07-18"])