-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch.php
1320 lines (1141 loc) · 45.5 KB
/
batch.php
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
<?php
# This is a tool for batch processing United States Supreme Court
# cases
#
# Last updated 8/15/2010
require_once("config.php");
require_once("citations.php");
require_once("wikifycite.php");
require_once("authorbyname.php");
require_once("catlist.php");
/**
* Check if a wikipediaor wikisource article exists for a given page title
*
* @param $title string Title of the page you want to check
* @param $wiki string Either "wikipedia"
* @return string If exists, {{subst:BASEPAGENAME}}, otherwise no
*/
function wikiCheckPageExistence($title, $wiki){
$title = str_replace(" ","_",$title);
switch($wiki) {
case "wikipedia":
$url = "http://en.wikipedia.org/w/api.php?action=query&titles=".$title."&format=php";
break;
case "wikisource":
$url = "http://en.wikisource.org/w/api.php?action=query&titles=".$title."&format=php";
break;
}
$ch = curl_init();
$timeout = 7;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: wikiCheckPageExistence/1 [email protected]');
if(curl_exec($ch) == false) {
print "\nError: Unable to connect to ".$wiki."\n";
}else{
$data = curl_exec($ch);
curl_close($ch);
$data = unserialize($data);
$arr = array_keys($data["query"]["pages"]);
if($arr[0] >= 1) {
$page = "{{subst:BASEPAGENAME}}"; // want to set the wikipedia link to anything?
} else {
$page = "no";
}
return $page;
}
}
/**
* Split a citation into volume, reporter, and page
*
* @param $fullCitation string Full citation
* @return array ["Volume"], ["Reporter"], ["Page"]
*/
function explodeCaseName($FirstCitation = "none", $SecondCitation = "none", $ThirdCitation = "none"){
global $reporter;
$citations = array ($FirstCitation, $SecondCitation, $ThirdCitation);
foreach($citations as $fullCitation) {
$explodedCitation = explode(" ",$fullCitation);
foreach($explodedCitation as $key => $citationPart){
if($citationPart==$reporter){
$citation["Volume"] = $explodedCitation[$key-1];
$citation["Reporter"] = $explodedCitation[$key];
$citation["Page"] = $explodedCitation[$key+1];
}
}
}
return $citation;
}
/**
* Trim the left side of each line
*
* @param $txt string Text to be trimmed
* @return string Now you don't have to worry about wiki-indentations
*/
function trimLine($txt){
$lines = explode("\n",$txt);
foreach($lines as $k=>$line){
$lines[$k] = ltrim($line);
}
return implode("\n",$lines);
}
/**
* Check a case's year against the author's year on court
*
* Necessary to determine the author when you only know the last name and there
* are multiple authors with the same last name
*
* @param $year string Year of the case
* @param $year string Name of the author
* @return string The true author
*/
function multiAuthorName($year, $name){
if(is_array($name)){
$upper = $name["1_end"];
$lower = $name["1_start"];
if($upper > $year && $lower < $year) {
$caseAuthor = $name[1];
} else {
$caseAuthor = $name[0];
}
} else {
$caseAuthor = $name;
}
return $caseAuthor;
}
/**
* Apply categories by matching words or phrases in the syllabus
*
* @param $txt string
* @param $list string
* @return array Categories
*/
function categoryGuess($txt, $list){
$categories = array();
foreach($list as $key => $cat) {
if(preg_match("/$key/",$txt)){
if(!in_array($cat,$categories)) {
$categories[] = $cat;
}
}
}
if($categories == array()){
$categories[] = "[[Category:Uncategorized United States Supreme Court decision]]";
} else {
$categories[] = "[[Category:Automated categorization]]";
}
return $categories;
}
/**
* Split the case name into the parties' names
*
* @param $unformattedName string Full name
* @return array [0] => full name, [1] => first party
* [2] => second party
*/
function formatCaseName($unformattedName){
$unformattedname = str_replace("Mc","MC",$unformattedName);
$splitPartyName = explode("v.", $unformattedName);
$party = $splitPartyName;
$party[0] = trim(ucwords(strtolower(preg_replace("/[a-z]|\,|((!?[A-Z])[a-z])|\.|([A-Z]\.[A-Z]\.)|([A-Z]\.\s)/","",$splitPartyName[0]))));
$party[1] = trim(ucwords(strtolower(preg_replace("/[a-z]|\,|((!?[A-Z])[a-z])|\.|([A-Z]\.[A-Z]\.)|([A-Z]\.\s)/","",$splitPartyName[1]))));
$party[0] = trim(str_replace("/","",$party[0]));
$party[1] = trim(str_replace("/","",$party[1]));
$party[1] = str_replace(">>","",$party[1]);
$name = $party[0]." v. ".$party[1];
$name = str_replace(" "," ",$name);
$name = rtrim($name);
return array($name, $splitPartyName[0], $splitPartyName[1]);
}
function removeOddCharacters($txt){
$txt = trim($txt);
$txt = str_replace("Â "," ",$txt);
$txt = str_replace("§","§",$txt);
$txt = str_replace("’","'",$txt);
$txt = str_replace("“","\"",$txt);
$txt = str_replace("â€","\"",$txt);
$txt = str_replace("''","\"",$txt);
$txt = str_replace(" ","",$txt);
$txt = str_replace("—","-",$txt);
$txt = str_replace("—","-",$txt);
return $txt;
}
function strstr_after($haystack, $needle, $case_insensitive = false) {
$strpos = ($case_insensitive) ? 'stripos' : 'strpos';
$pos = $strpos($haystack, $needle);
if (is_int($pos)) {
return substr($haystack, $pos + strlen($needle));
}
return $pos;
}
/**
* Match footnotes and return them as a string
*
* @param $paragraph string A paragraph of text
* @param $arr array Footnotes
* @return string Group of footnotes
*/
function opinionFootnotesFormat($paragraph,$arr){
if(!isset($footnoteGroup)) { $footnoteGroup = ""; }
preg_match_all("/([#-_a-z0-9]*) \<ref\> ([0-9\*]+) \<\/ref\>/",$paragraph,$matches, PREG_SET_ORDER);
foreach($matches as $match){
$foundFoot = $arr[$match[1]."_ref"][1];
$footnoteGroup = $footnoteGroup . "\n" . $foundFoot;
}
return $footnoteGroup;
}
/**
* preg_replace to change to footnote template
*/
function opinionParagraphRefs($paragraph){
return preg_replace("/([#-_a-z0-9]*) \<ref\> (\<nowiki\>)*([0-9\*]+)(\<\/nowiki\>)* \<\/ref\>/","{{ref|$3}}",$paragraph);
}
/**
* puts together the page for each opinion
*
*/
function buildPage($Section, $caseName, $authorLastName, $TemplateHeaderValues, $TemplateUSSCcaseValues, $TemplateCaseCaptionValues, $body, $ParallelCites) {
$USSCcaseNo = "2"; // ever page except syllabus uses {{USSCcase2}}
$authorLastName = trim($authorLastName);
switch($Section){
case "Syllabus":
$pageTitle = $caseName[0];
$ParallelCiteString = $ParallelCites[0].$ParallelCites[1];
$USSCcaseNo = ""; // no number for syllabus; otherwise, it's "2"
break;
case "Opinion of the Court":
$pageTitle = $caseName[0]."/Opinion of the Court";
/**
* Prevents ParallelCite and Categories from being printed on
* this subpage.
*/
$ParallelCiteString = "";
$body["Cats"] = "";
break;
case "Dissent":
$pageTitle = $caseName[0]."/Dissent ".$authorLastName;
$ParallelCiteString = "";
$body["Cats"] = "";
break;
case "Concurrence":
$pageTitle = $caseName[0]."/Concurrence ".$authorLastName;
$ParallelCiteString = "";
$body["Cats"] = "";
break;
default:
$pageTitle = $caseName[0]."/Opinion ".$authorLastName;
$ParallelCiteString = "";
$body["Cats"] = "";
break;
}
$page = "{{-start-}}
'''".$pageTitle."'''
".$ParallelCiteString."
{{header
| title = {{subst:PAGENAME}}
| author = ".$TemplateHeaderValues["AuthorFullName"]."
| section = ".$Section."
| previous = [[wikisource:Supreme Court of the United States|United States Supreme Court]]
| next =
| notes =
}}
{{USSCcase".$USSCcaseNo."
|percuriam = ".$TemplateUSSCcaseValues["perCuriam"]."
|concurrence_author1 = ".$TemplateUSSCcaseValues["concurrenceAuthorLastName"][0]."
|concurrence_author2 = ".$TemplateUSSCcaseValues["concurrenceAuthorLastName"][1]."
|concurrence_author3 = ".$TemplateUSSCcaseValues["concurrenceAuthorLastName"][2]."
|concurrence_author4 = ".$TemplateUSSCcaseValues["concurrenceAuthorLastName"][3]."
|concurrence_author5 = ".$TemplateUSSCcaseValues["concurrenceAuthorLastName"][4]."
|concurrence_author6 = ".$TemplateUSSCcaseValues["concurrenceAuthorLastName"][5]."
|concurrence_author7 = ".$TemplateUSSCcaseValues["concurrenceAuthorLastName"][6]."
|concurrence_author8 = ".$TemplateUSSCcaseValues["concurrenceAuthorLastName"][7]."
|concurrence-dissent_author1 =
|concurrence-dissent_author2 =
|concurrence-dissent_author3 =
|concurrence-dissent_author4 =
|dissent_author1 = ".$TemplateUSSCcaseValues["dissentAuthorLastName"][0]."
|dissent_author2 = ".$TemplateUSSCcaseValues["dissentAuthorLastName"][1]."
|dissent_author3 = ".$TemplateUSSCcaseValues["dissentAuthorLastName"][2]."
|dissent_author4 = ".$TemplateUSSCcaseValues["dissentAuthorLastName"][3]."
|separate_author1 =
|separate_author2 =
|separate_author3 =
|separate_author4 =
|linked_cases =
|wikipedia = ".$TemplateUSSCcaseValues["wpiwl"]."
}}
{{CaseCaption
| court = ".$TemplateCaseCaptionValues["court"]."
| volume = ".$TemplateCaseCaptionValues["arrCite"]['Volume']."
| reporter = ".$TemplateCaseCaptionValues["arrCite"]['Reporter']."
| page = ".$TemplateCaseCaptionValues["arrCite"]['Page']."
| party1 = ".$TemplateCaseCaptionValues["name"][1]."
| party2 = ".$TemplateCaseCaptionValues["name"][2]."
| casename = ".$TemplateCaseCaptionValues["name"][0]."
| lowercourt = ".$TemplateCaseCaptionValues["courtbelow"]."
| argued = ".$TemplateCaseCaptionValues["argdate"]."
| decided = ".$TemplateCaseCaptionValues["decdate"]."
| case no = ".$TemplateCaseCaptionValues["docket"]."
}}
<div class='courtopinion'>
".$body["mainText"]."
==Notes==
".$body["notes"]."
</div>
".$body["Cats"]."
{{PD-USGov}}
{{-stop-}}";
return $page;
}
function buildTalkPage($Section, $name, $authorLastName, $contributor, $decdate, $arrCite) {
$authorLastName = trim($authorLastName);
switch($Section) {
case "Syllabus":
$talkpageTitle = "Talk:".$name[0];
break;
case "Opinion of the Court":
$talkpageTitle = "Talk:".$name[0]."/Opinion of the Court";
break;
case "Dissent":
$talkpageTitle = "Talk:".$name[0]."/Dissent ".$authorLastName;
break;
case "Concurrence":
$talkpageTitle = "Talk:".$name[0]."/Concurrence ".$authorLastName;
break;
default:
$talkpageTitle = "Talk:".$name[0]."/Opinion ".$authorLastName;
break;
}
$talkpage = "{{-start-}}
'''".$talkpageTitle."'''
{{Template:WikiProject USSC}}
{{textinfo
| edition = ''".$name[0]."'', ".$decdate." .
| source = ''".$name[0]." '' from http://bulk.resource.org/courts.gov/c/US/".$arrCite['Volume']."
| contributors = ".$contributor."
| progress = Text being edited [[Image:25%.png]]
| notes = Gathered and wikified using an automated tool. See this [[user:slaporte/slaw|documentation]] for more information.
| proofreaders =
}}
{{-stop-}}";
return $talkpage;
}
/**
* Main function
*
* @param $url string URL of the case to process
*/
function batchWikify($url) {
global $contributor, $xpathCourt, $xpathTitle, $xpathName, $xpathAuthor, $xpathCasecite, $xpathCite2, $xpathCite3, $xpathCourtbelow, $xpathDate1, $xpathDate2, $xpathDocket, $xpathParty1, $xpathParty2, $xpathFoots, $xpathParagraph, $xpathSyllabus, $namesVol, $dupList, $reporter, $authorByName, $catlist;
$dissent = 0;
$dissentNo = 1;
$dissentAuthor = array();
$concurrenceAuthor = array();
$perCuriam = false;
$Syllabus = $OpinionOfCourt = $missing = $notices = $courtbelow = $arr = "";
$concurrenceCount = false;
$dissentCount = false;
$ConcurText = array();
$lastNameArray = $lastNamed = "";
$SyllabusNotes = $Syllabus = "";
$Con = $Con2 = $Con3 = $Con4 = $Con5 = $Con6 = $Con7 = $Con8 = false;
$Dis = $Dis2 = $Dis3 = $Dis4 = false;
$date1 = $date2 = $docket = false;
$OpinionOfCourt_Notes = $DisNotes = $Dis2Notes = $Dis3Notes = $Dis4Notes = "";
$ConNotes = $Con2Notes = $Con3Notes = $Con3Notes = $Con4Notes = $Con5Notes = $Con6Notes = $Con7Notes = $Con8Notes = "";
$missingDissent = $missingConcurrence = "";
/**
* array of justices with their full name, and years for those justices that share their last name
*/
$citebank = array();
$target_url = $url;
$URLserAgent = '';
/**
* make the cURL request to $target_url
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $URLserAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
if(curl_exec($ch) == false){
print "\nError: unable to open ".$url."\n";
return;
}else{
$html= curl_exec($ch);
if (!$html) {
print "<br />cURL error number:" .curl_errno($ch);
print "<br />cURL error:" . curl_error($ch);
exit;
}
}
/**
* Make adjustment to html
*/
$html = removeOddCharacters($html);
$html = preg_replace('/<a class="footnote" href="([^"]*)" [^>]*>([0-9a-z\*]+)<\/a>/',' $1 <ref> $2 </ref>',$html);
$html = preg_replace('/<a class="footnote" href="([^"]*)">([0-9a-z\*]+)<\/a>/',' $1 <ref> $2 </ref>',$html);
$html = str_replace('<p>',"\n",$html);
$html = str_replace('<p class="indent">',"<p class='indent'> \n",$html);
$html = str_replace('It is so ordered.',"It is so ordered. \n",$html);
$html = str_replace('U. S. C.','U.S.C.',$html);
$html = str_replace('U. S.','U.S.',$html);
$html = str_replace('ordered.
</i> Justice ','ordered.</i></p></div><div class="num"><p class="indent">Justice ',$html);
//$html = preg_replace("/<i>(.*)<\/i>/","''$1''",$html);
$html = str_replace("<i>","''",$html);
$html = str_replace("</i>","''",$html);
/**
* parse the html into DOMDocument
*/
$caseDOM = new DOMDocument();
@$caseDOM->loadHTML($html);
$xpath = new DOMXPath($caseDOM);
$pg_title = $xpath->query($xpathTitle)->item(0)->nodeValue;
/**
* gather info from xpath
*/
isset($xpath->query($xpathCourt)->item(0)->nodeValue) ? $court = $xpath->query($xpathCourt)->item(0)->nodeValue : "";
isset($xpath->query($xpathName)->item(0)->nodeValue) ? $name = $xpath->query($xpathName)->item(0)->nodeValue : "";
isset($xpath->query($xpathAuthor)->item(0)->nodeValue) ? $author = $xpath->query($xpathAuthor)->item(0)->nodeValue : "";
isset($xpath->query($xpathCasecite)->item(0)->nodeValue) ? $casecite = $xpath->query($xpathCasecite)->item(0)->nodeValue : "";
isset($xpath->query($xpathCourtbelow)->item(0)->nodeValue) ? $courtbelow = $xpath->query($xpathCourtbelow)->item(0)->nodeValue : "";
isset($xpath->query($xpathDate1)->item(1)->nodeValue) ? $date1 = $xpath->query($xpathDate1)->item(1)->nodeValue : "";
isset($xpath->query($xpathDate2)->item(0)->nodeValue) ? $date2 = $xpath->query($xpathDate2)->item(0)->nodeValue : "";
isset($xpath->query($xpathDocket)->item(0)->nodeValue) ? $docket = $xpath->query($xpathDocket)->item(0)->nodeValue : "";
isset($xpath->query($xpathParty1)->item(0)->nodeValue) ? $party1 = $xpath->query($xpathParty1)->item(0)->nodeValue : "";
isset($xpath->query($xpathParty2)->item(0)->nodeValue) ? $party2 = $xpath->query($xpathParty2)->item(0)->nodeValue : "";
isset($xpath->query($xpathCite2)->item(1)->nodeValue) ? $casecite2 = $xpath->query($xpathCite2)->item(1)->nodeValue : "";
isset($xpath->query($xpathCite3)->item(2)->nodeValue) ? $casecite3 = $xpath->query($xpathCite3)->item(2)->nodeValue : "";
$decdate = strstr_after($date1, "ed");
if(!isset($decdate)){
$decdate = "";
}
$argdate = strstr_after($date2, "ed");
if(!isset($argdate)){
$argdate = "";
}
/**
* year?
*/
$year = str_replace(".","",trim(strstr($date2,","),", "));
if(!is_numeric($year)){
$year = trim(strstr($date1,","),", ");
}
$arrCite = explodeCaseName($casecite, $casecite2, $casecite3);
/**
* determine file name
*/
if(preg_match("/([0-9]{3})\.html/",$url,$match)) {
$caseno = preg_replace("/(^000)|(^00)|(^0)|/","",$match[1]);
}else{
$caseno = false;
}
/**
* Get the case name
* - By default, the case is named according to caseName()
* - If available, it will take a case name from a formatted list:
* --Save an array of case names with citations as ./input/[volume number].php
* --Name the (case) input files sequentially
* --If the file number and citation match, it will use the name from the list
*
* This is useful for importing volumes at a time, especially if you want to check
* the case names against a list.
* - $completeName preserves the name from the source file. Unfortunately, it is often
* too poorly formatted to use...
*/
$completeName = formatCaseName($name);
if(file_exists("./input/".$arrCite['Volume'].".php")){
require_once("./input/".$arrCite['Volume'].".php");
if($caseno == false){
$name = formatCaseName($name);
} else {
$caseno = $caseno - 1;
$casearray = $namesVol[$arrCite['Volume']."-".$caseno];
if($casearray[1] == $arrCite['Volume']." ".$arrCite['Reporter']." ".$arrCite['Page']." "){
$name = $casearray;
$name[3] = $name[1];
$splitCaseName = explode("v.", $name[0]);
$name[1] = $splitCaseName[0];
$name[2] = $splitCaseName[1];
} else {
$name = formatCaseName($name);
}
}
} else {
$name = formatCaseName($name);
}
/**
* check if a case with that name is already up
*/
if(wikiCheckPageExistence($name[0], "wikisource") == "{{subst:BASEPAGENAME}}"){
$name[0] = $name[0]." (".$arrCite['Volume']." ".$arrCite['Reporter']."*** ".$arrCite['Page'].")";
$dupList[] = $name[0]." (".$arrCite['Volume']." ".$arrCite['Reporter']."*** ".$arrCite['Page'].")";
$Cats = $Cats . "[[Category:Automated disambiguation]] ";
}
/**
* gather the footnote text
*/
foreach ($xpath->query($xpathFoots) as $foot){
if(trim($foot->nodeValue) != "Notes:"){
if(preg_match ("/([#-_a-z0-9]*) \<ref\> ([0-9a-z\*]+) \<\/ref\>/",$foot->nodeValue,$match)) {
if(!isset($arr["$match[1]"])) {
$arr["$match[1]"] = array($match[2], ltrim(preg_replace("/([#-_a-z0-9]*) \<ref\> ([0-9a-z\*]+) \<\/ref\>[\n\t]*/","\n{{note|$2|$2}}",$foot->nodeValue)));
}
}
}
}
if($arrCite["Reporter"] == "U.S.") {
$court = "United States Supreme Court";
}
/**
* gather syllabus
*/
$txts = $xpath->query($xpathSyllabus);
foreach ($txts as $txt) {
$syll = trim($txt->nodeValue);
$p1 = $name[1];
$p2 = $name[2];
if(isset($name[1][0])){
preg_match("/([#-_a-z0-9]*) Ref ([0-9\*]+) Ref/",$p1,$matches);
if(isset($matches[1])){
$name[1][0] = trim(preg_replace("/([#-_a-z0-9]*) Ref ([0-9a-z\*]+) Ref/","\n{{note|$2|$2}}",$p1));
$offset = $matches[1]."_ref";
if(is_array($arr[$offset])){
$foundFoot = $arr[$offset][1];
$SyllabusNotes = $SyllabusNotes . "\n" . ltrim($foundFoot);
}
}
}
if(isset($name[1][1])){
preg_match("/([#-_a-z0-9]*) Ref ([0-9a-z\*]+) Ref/",$p2,$matches);
if(isset($matches)){
//$name[1][1] = trim(preg_replace("/([#-_a-z0-9]*) Ref ([0-9a-z\*]+) Ref/","\n{{note|$2|$2}}",$p2));
if(isset($matches[1])){
$offset = $matches[1]."_ref";
if(isset($arr[$offset])){
$foundFoot = $arr[$matches[1]."_ref"][1];
}
$SyllabusNotes = $SyllabusNotes . "\n" . ltrim($foundFoot);
}
}
}
preg_match_all("/([#-_a-z0-9]*) \<ref\> ([0-9a-z\*]+) \<\/ref\>/",$syll,$matches, PREG_SET_ORDER);
foreach($matches as $match){
$foundFoot = $arr[$match[1]."_ref"][1];
$syll = trim(preg_replace("/([#-_a-z0-9]*) \<ref\> ([0-9a-z\*]+) \<\/ref\>/","{{ref|$2}}",$syll));
$SyllabusNotes = $SyllabusNotes . "\n" . ltrim($foundFoot);
}
$Syllabus = $Syllabus . $syll;
}
foreach(categoryGuess($Syllabus,$catlist) as $cat) {
if(!isset($Cats)){
$Cats = "";
}
$Cats = $Cats . $cat . " ";
}
$txts = $xpath->query($xpathParagraph);
$cite_list = array();
/**
* gather opinions
*
* Opinions are split into the Opinion of the Court, Dissents, and Concurrences
* according to regular expressions. The phrases are pretty consistent, but
* unfortunately not all the same.
* Concurrences:
* ^justice ([a-z']+)\, concurring
* ^justice ([a-z']+)\, with .* concurring( in the judgment)*
* Dissents:
* ^mr\. justice ([a-z]+), with .* dissenting
* ^justice ([a-z']+)\, dissenting\.
* ^justice ([a-z']+),* with .* dissenting\.
* ^justice ([a-z]+)\, joined .* dissenting\.$
*
*/
foreach ($txts as $txt) {
$paragraph = $txt->nodeValue;
/**
* get rid of paragraph numbers
*/
$paragraph = preg_replace("/[0-9]+\n/","",$paragraph);
$paragraph = preg_replace("/[0-9]+\n\n/","",$paragraph);
$paragraphlower = strtolower($paragraph);
$paragraphLowerCase = strtolower($paragraph);
/**
* clean up potential miswikification
*/
$paragraph = preg_replace('/[\n]*\*/','<nowiki>*</nowiki>',$paragraph);
/**
* Count each concurrence by matching the start of each line against
* an expression in $concurrenceExpressionArray
*
* in a nine person court, there may be up to eight concurrences...
*/
$concurrenceExpressionsArray = array(
"/^justice ([a-z']+)\, concurring/",
"/^mr\. justice ([a-z']+) concurs/",
"/^justice ([a-z']+)\, with .* concurring( in the judgment)*/",
"/^mr\. [chief ]*justice ([A-Za-z]+)[,]* concurring/",
"/^mr\. justice ([a-z]+) and [a-z\s,\.]* concurring\./"
);
foreach($concurrenceExpressionsArray as $concurrenceExpression){
if(preg_match($concurrenceExpression,ltrim($paragraphLowerCase),$matchedNames)){
foreach($matchedNames as $lastName){
if(!preg_match("/JUSTICE|justice/",$lastName)){
$lastNameArray[] = $lastName;
}
}
$concurrenceCount = $concurrenceCount +1;
}
}
/**
* When no concurrence or dissent is counted, the paragraph
* belongs to the opinion
*/
if($concurrenceCount == 0&&$dissentCount == 0) {
$OpinionOfCourt_Notes = $OpinionOfCourt_Notes . opinionFootnotesFormat($paragraph,$arr);
$OpinionOfCourt = $OpinionOfCourt ."\n\n". trim(opinionParagraphRefs($paragraph));
}
/**
* add each paragraph to the proper concurrence
*/
switch($concurrenceCount){
case 1:
$ConNotes = $ConNotes . opinionFootnotesFormat($paragraph,$arr);
$Con = $Con ."\n\n". trim(opinionParagraphRefs($paragraph));
$ConAuthorFullName = multiAuthorName($year,$authorByName[strtolower($lastNameArray[0])]);
break;
case 2:
$Con2Notes = $Con2Notes . opinionFootnotesFormat($paragraph,$arr);
$Con2 = $Con2 ."\n\n". trim(opinionParagraphRefs($paragraph));
$Con2AuthorFullName = multiAuthorName($year,$authorByName[strtolower($lastNameArray[1])]);
break;
case 3:
$Con3Notes = $Con3Notes . opinionFootnotesFormat($paragraph,$arr);
$Con3 = $Con3 ."\n\n". trim(opinionParagraphRefs($paragraph));
$Con3AuthorFullName = multiAuthorName($year,$authorByName[strtolower($lastNameArray[2])]);
break;
case 4:
$Con4Notes = $Con4Notes . opinionFootnotesFormat($paragraph,$arr);
$Con4 = $Con4 ."\n\n". trim(opinionParagraphRefs($paragraph));
$Con4AuthorFullName = multiAuthorName($year,$authorByName[strtolower($lastNameArray[3])]);
break;
case 5:
$Con5Notes = $Con5Notes . opinionFootnotesFormat($paragraph,$arr);
$Con5 = $Con5 ."\n\n". trim(opinionParagraphRefs($paragraph));
$Con5AuthorFullName = multiAuthorName($year,$authorByName[strtolower($lastNameArray[4])]);
break;
case 6:
$Con6Notes = $Con6Notes . opinionFootnotesFormat($paragraph,$arr);
$Con6 = $Con6 ."\n\n". trim(opinionParagraphRefs($paragraph));
$Con6AuthorFullName = multiAuthorName($year,$authorByName[strtolower($lastNameArray[5])]);
break;
case 7:
$Con7Notes = $Con7Notes . opinionFootnotesFormat($paragraph,$arr);
$Con7 = $Con7 ."\n\n". trim(opinionParagraphRefs($paragraph));
$Con7AuthorFullName = multiAuthorName($year,$authorByName[strtolower($lastNameArray[6])]);
break;
case 8:
$Con8Notes = $Con8Notes . opinionFootnotesFormat($paragraph,$arr);
$Con8 = $Con8 ."\n\n". trim(opinionParagraphRefs($paragraph));
$Con8AuthorFullName = multiAuthorName($year,$authorByName[strtolower($lastNameArray[7])]);
break;
}
/**
* Count each dissent by matching the start of each line against
* an expression in $dissentExpressionArray
*
* there are only four possible dissents.
*/
$dissentExpressionsArray = array(
"/^mr\. justice ([a-z]+)[,]* dissenting/",
"/^mr\. justice ([a-z]+), with .* dissenting/",
"/^justice ([a-z']+)\, dissenting\./",
"/^justice ([a-z']+),* with .* dissenting\./",
"/^chief justice ([a-z']+)[,]* with .* dissenting\./",
"/^justice ([a-z]+)\, joined .* dissenting\.$/",
"/^[the ]*separate opinion of mr\. justice ([A-Za-z]+)/",
"/^mr\. justice ([a-z]+) \(dissenting\)/",
"/^mr\. chief justice ([a-z]+), dissenting/"
);
foreach($dissentExpressionsArray as $dissentExpression){
if(preg_match($dissentExpression,ltrim($paragraphLowerCase),$match)){
foreach($match as $E){
if(!preg_match("/JUSTICE|justice/",$E)){
$lastNamed[] = $E;
}
}
$dissentCount = $dissentCount +1;
$concurrenceCount = 0;
}
}
switch($dissentCount){
case 1:
$DisNotes = $DisNotes . opinionFootnotesFormat($paragraph,$arr);
$Dis = $Dis ."\n\n". trim(opinionParagraphRefs($paragraph));
$DissentAuthor = multiAuthorName($year,$authorByName[strtolower($lastNamed[0])]);
break;
case 2:
$Dis2Notes = $Dis2Notes . opinionFootnotesFormat($paragraph,$arr);
$Dis2 = $Dis2 ."\n\n". trim(opinionParagraphRefs($paragraph));
$Dissent2Author = multiAuthorName($year,$authorByName[strtolower($lastNamed[1])]);
break;
case 3:
$Dis3Notes = $Dis3Notes . opinionFootnotesFormat($paragraph,$arr);
$Dis3 = $Dis3 ."\n\n". trim(opinionParagraphRefs($paragraph));
$Dissent3Author = multiAuthorName($year,$authorByName[strtolower($lastNamed[2])]);
break;
case 4:
$Dis4Notes = $Dis4Notes . opinionFootnotesFormat($paragraph,$arr);
$Dis4 = $Dis4 ."\n\n". trim(opinionParagraphRefs($paragraph));
$Dissent4Author = multiAuthorName($year,$authorByName[strtolower($lastNamed[3])]);
break;
}
}
$OpName = $name[0];
/**
* wpiwl: Wikipedia Interwiki Link
*/
$TemplateUSSCcaseValues["wpiwl"] = wikiCheckPageExistence($OpName, "wikipedia");
/**
* attempt to determine the author of each opinion
*/
$lowersyll = strtolower($Syllabus);
/**
* use $caseAuthorExpressionArray/$dissentAuthorExpressionArray/
* $concurrenceAuthorExpressionArray to match an author in the
* syllabus
*/
$caseAuthorExpressionArray = array(
"/[Jj]ustice ([a-zA-Z]+) delivered/",
"/[Jj]ustice ([a-zA-Z]+), after stating/",
"/([A-Z']+), J., delivered the opinion/",
"/([A-Z]+), J./"
);
foreach($caseAuthorExpressionArray as $caseAuthorExpression){
preg_match($caseAuthorExpression,$Syllabus,$match);
if(isset($match[1])) {
$CaseAuthorFullName = multiAuthorName($year,$authorByName[strtolower($match[1])]);
}
}
if(!isset($CaseAuthorFullName)) { $CaseAuthorFullName = ""; }
$dissentAuthorExpressionArray = array(
"/([a-z']+), j., filed a dissenting/",
"/([a-z]+), c.j., filed a dissenting/"
);
foreach($dissentAuthorExpressionArray as $dissentAuthorExpression){
preg_match_all($dissentAuthorExpression,$lowersyll,$authorArray);
foreach($authorArray[1] as $author){
$dissentAuthor[] = ucfirst(strtolower(trim($author)));
$TemplateUSSCcaseValues["dissentAuthorLastName"][] = ucfirst(strtolower(trim($author)));
}
}
$concurrenceAuthorExpressionArray = array(
"/([A-Za-z']+), J., filed a concurring/",
"/([A-Za-z']+), J., filed an opinion concurring/",
"/Mr\. Justice ([A-Za-z']+), concurring/"
);
foreach($concurrenceAuthorExpressionArray as $concurrenceAuthorExpression){
preg_match_all($concurrenceAuthorExpression,$lowersyll,$authorArray);
foreach($authorArray[1] as $author){
$concurrenceAuthor[] = ucfirst(strtolower(trim($author)));
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][] = ucfirst(strtolower(trim($author)));
}
}
if(preg_match("/per curiam/",strtolower($syll))&&!isset($CaseAuthorFullName)){
$perCuriam = "yes";
$TemplateUSSCcaseValues["perCuriam"] = "yes";
}else{
$perCuriam = "";
$TemplateUSSCcaseValues["perCuriam"] = "";
}
/**
* if we found an opinion but couldn't determine the author from the syllabus,
* determine the author from the first line of the opinion.
*/
if($Dis != ""&&!isset($dissentAuthor[0])){
$missingDissent = 1;
$dissentAuthor[0] = strrchr($DissentAuthor," ");
$TemplateUSSCcaseValues["dissentAuthorLastName"][0] = $dissentAuthor[0];
}elseif($Dis == ""){
$TemplateUSSCcaseValues["dissentAuthorLastName"][0] = "";
}
if($Dis2 != ""&&!isset($dissentAuthor[1])){
$missingDissent = 1;
$dissentAuthor[1] = strrchr($Dissent2Author," ");
$TemplateUSSCcaseValues["dissentAuthorLastName"][1] = $dissentAuthor[1];
}elseif($Dis2 == ""){
$TemplateUSSCcaseValues["dissentAuthorLastName"][1] = "";
}
if($Dis3 != ""&&!isset($dissentAuthor[2])){
$missingDissent = 1;
$dissentAuthor[2] = strrchr($Dissent3Author," ");
$TemplateUSSCcaseValues["dissentAuthorLastName"][2] = $dissentAuthor[2];
}elseif($Dis3 == ""){
$TemplateUSSCcaseValues["dissentAuthorLastName"][2] = "";
}
if($Dis4 != ""&&!isset($dissentAuthor[3])){
$missingDissent = 1;
$dissentAuthor[3] = strrchr($Dis4Author," ");
$TemplateUSSCcaseValues["dissentAuthorLastName"][3] = $dissentAuthor[3];
}elseif($Dis4 == ""){
$TemplateUSSCcaseValues["dissentAuthorLastName"][3] = "";
}
if($Con != ""&&!isset($concurrenceAuthor[0])){
$concurrenceAuthor[0] = ucfirst(strtolower($lastNameArray[0]));
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][0] = $concurrenceAuthor[0];
}elseif($Con == ""){
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][0] = "";
}
if($Con2 != ""&&!isset($concurrenceAuthor[1])){
$concurrenceAuthor[1] = ucfirst(strtolower($lastNameArray[1]));
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][1] = $concurrenceAuthor[1];
}elseif($Con2 == ""){
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][1] = "";
}
if($Con3 != ""&&!isset($concurrenceAuthor[2])){
$concurrenceAuthor[2] = ucfirst(strtolower($lastNameArray[2]));
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][2] = $concurrenceAuthor[2];
}elseif($Con3 == ""){
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][2] = "";
}
if($Con4 != ""&&!isset($concurrenceAuthor[3])){
$missingConcurrence = 1;
$concurrenceAuthor[3] = ucfirst(strtolower($lastNameArray[3]));
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][3] = $concurrenceAuthor[3];
}elseif($Con4 == ""){
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][3] = "";
}
if($Con5 != ""&&!isset($concurrenceAuthor[4])){
$missingConcurrence = 1;
$concurrenceAuthor[4] = ucfirst(strtolower($lastNameArray[4]));
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][4] = $concurrenceAuthor[4];
}elseif($Con5 == ""){
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][4] = "";
}
if($Con6 != ""&&!isset($concurrenceAuthor[5])){
$missingConcurrence = 1;
$concurrenceAuthor[5] = ucfirst(strtolower($lastNameArray[5]));
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][5] = $concurrenceAuthor[5];
}elseif($Con6 == ""){
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][5] = "";
}
if($Con7 != ""&&!isset($concurrenceAuthor[6])){
$missingConcurrence = 1;
$concurrenceAuthor[6] = ucfirst(strtolower($lastNameArray[6]));
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][6] = $concurrenceAuthor[6];
}elseif($Con7 == ""){
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][6] = "";
}
if($Con8 != ""&&!isset($concurrenceAuthor[7])){
$missingConcurrence = 1;
$concurrenceAuthor[7] = ucfirst(strtolower($lastNameArray[7]));
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][7] = $concurrenceAuthor[7];
}elseif($Con8 == ""){
$TemplateUSSCcaseValues["concurrenceAuthorLastName"][7] = "";
}
/**
* clean up openjurist cites
*/
$decdate = str_replace("Decided ","",$decdate);
$decdate = str_replace(".","",$decdate);
$docket = str_replace("No. ","",$docket);
$docket = str_replace(".","",$docket);
$court = str_replace(".","",$court);
/**
* let's see if there is a cite in the title
*/
$cite = strstr($pg_title,",");
if(isset($s)){
$s = explode(" ",$cite);
if ($s[1]!=""){
$ctvol = $s[1];
$ctrep = $s[2];
$ctpg = $s[3];
}
}
/**
* what is missing from the metadata?
*/
if(!isset($court)){$missing=$missing . "<li>court</li>";}
if(!isset($arrCite["Volume"])){$missing=$missing . "<li>volume</li>";}
if(!isset($arrCite["Reporter"])){$missing=$missing . "<li>reporter</li>";}
if(!isset($arrCite["Page"])){$missing=$missing . "<li>page</li>";}
if(!isset($name)){$missing=$missing . "<li>case name</li>";}
if(!isset($courtbelow)){$missing=$missing . "<li>lower court</li>";}
if(!isset($argdate)){$missing=$missing . "<li>date argued</li>";}
if(!isset($decdate)){$missing=$missing . "<li>date decided</li>";}
if(!isset($docket)){$missing=$missing . "<li>docket</li>";}
if(!isset($CaseAuthorFullName)&&$perCuriam==false){$missing=$missing . "<li>author of the opinion of the court</li>";}
// if(!isset($arr)){$missing=$missing . "<li>no footnotes?</li>";}
if(isset($idhunter)){$missing=$missing . "<li>Identified some id. links. Note: This can only figure out links referring to citations in the same paragraph.</li>";}
if(!isset($concurrenceCount)){$missing=$missing . "<li>No dissent/concurrence?</li>";}
if($dissent == 1) {$notices = $notices."<li>The syllabus mentions a dissenting opinion</li>";}
if($perCuriam == 1) {$notices = $notices."<li>The opinion of the court was decided per curiam</li>";}
if($missingDissent == true) {$notices = $notices."<li>Unknown Dissent Author; is there a dissent mentioned in the syllabus?</li>";}
if($missingConcurrence == true) {$notices = $notices."<li>Unknown Dissent Author; is there a concurrence mentioned in the syllabus?</li>";}
$name = str_replace("/>","",$name);
$name = str_replace("v."," v. ",$name);
$arrCite['Volume'] = str_replace("[[","",$arrCite['Volume']);
$arrCite['Page'] = str_replace("]]","",$arrCite['Page']);
$articlesList[] = $OpName;
$articlesList[] = "Talk:".$OpName;
$articlesList[] = $OpName."/Opinion of the Court";
$articlesList[] = "Talk:".$OpName."/Opinion of the Court";
if(isset($casecite) && !preg_match("/U\.S\./", $casecite, $m)){
$ParallelCites[0] = "{{Parallel reporter|".$casecite."}}\n";
}
if(isset($casecite2) && !preg_match("/U\.S\./", $casecite2, $m)){
$ParallelCites[0] = "{{Parallel reporter|".$casecite2."}}\n";
}