-
Notifications
You must be signed in to change notification settings - Fork 2
/
netapp_test2.py
507 lines (423 loc) · 12.4 KB
/
netapp_test2.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
import regex as re
import nltk
nltk.download('averaged_perceptron_tagger')
nltk.download('punkt')
"""Retrieve date of case"""
def date_check(line):
words=line.split()
length=len(line.split())
if(length>=3):
word=words[length-3]
words[length-3]=word[1:]
word=words[length-1]
words[length-1]=word[:-1]
return (words[length-3]+' '+words[length-2]+' '+words[length-1])
else:
return " "
def retrieve_firstdate(filename):
if(filename=="No more Files"):
return "-1"
start='Prior_Cases/prior_case_'
try:
f=open(start+filename+'.txt','r')
lines = f.read()
line=lines.splitlines()
except:
return None
return date_check(line[0])
"""Retrieve Citatation line"""
def citation_check(lines):
lines2=lines.splitlines()
String='CITATION:'
for x in lines2:
ResSearch = re.search(String, x)
if ResSearch:
return (re.sub(r'^\W*\w+\W*', '', x))
return None
def retrieve_citation(filename):
start='Prior_Cases/'
f=open(start+filename+'.txt','r')
lines = f.read()
return citation_check(lines)
"""Retrieve all the information under Held"""
def held_check(lines):
lines2=lines.splitlines()
flag=0
String='HELD :'
for x in lines2:
ResSearch = re.search(String, x)
if (ResSearch and flag==0):
held = (re.sub(r'^\W*\w+\W*', '', x))
flag = 1
String = ' : '
elif (ResSearch and flag==1):
return held
elif (flag==1):
held = held + '\n' + x
return None
def retrieve_held(filename):
start='Prior_Cases/'
f=open(start+filename+'.txt','r')
lines = f.read()
return held_check(lines)
"""If there is an appellate jurisdiction, return whether it is a civil or criminal appellate jurisdiction"""
def aj_check(lines):
lines2=lines.splitlines()
flag=0
str1=""
for line in lines2:
if(flag==1):
match=re.search(r'\d+', line)
return str1 , match.group()
String='CIVIL APPELLATE JURISDICTION'
ResSearch = re.search(String, line)
if ResSearch:
str1=line.split()
str1=str1[4:]
str1=' '.join(str1)
if(bool(re.search(r'\d', str1))):
match=re.search(r'\d+', str1)
return "CIVIL", match.group()
else:
str1="CIVIL"
flag=1
else:
String='CRIMINAL APPELLATE JURISDICTION'
ResSearch = re.search(String, line)
if ResSearch:
str1=line.split()
str1=str1[4:]
str1=' '.join(str1)
if(bool(re.search(r'\d', str1))):
match=re.search(r'\d+', str1)
return "CRIMINAL", match.group()
else:
str1="CRIMINAL"
flag=1
return None,None
def retrieve_AppellateJurisdiction(filename):
if(filename=="No more Files"):
return "-1","-1"
start='Prior_Cases/prior_case_'
try:
f=open(start+filename+'.txt','r')
lines = f.read()
appellate_jurisdiction, appeal_no = aj_check(lines)
except:
return None, None
return appellate_jurisdiction, appeal_no
""" Retrieve everything under the heading 'CITATOR' """
def citatorInfo_check(lines):
lines2=lines.splitlines()
flag=0
String='CITATOR INFO :'
for x in lines2:
ResSearch = re.search(String, x)
if (ResSearch and flag==0):
str1=x.split()
str1=str1[3:]
cinfo=' '.join(str1)
flag = 1
String = ' : '
elif (ResSearch and flag==1):
return cinfo
elif (flag==1):
cinfo = cinfo + '\n' + x
return None
def retrieve_citatorInfo(filename):
start='Prior_Cases/'
f=open(start+filename+'.txt','r')
lines = f.read()
return citatorInfo_check(lines)
"""If there was an appeal, check whether it was allowed or dismissed"""
def appeal_allowedOrDismissed(lines):
lines2=lines.splitlines()
for i in range(0,len(lines2)):
lines2[i]= lines2[i].lower()
for line in range((len(lines2)-1),-1,-1):
String='appeal'
ResSearch = re.search(String, lines2[line])
if (ResSearch):
if(re.search('allowed', lines2[line])):
return 'allowed'
elif(re.search('dismissed', lines2[line])):
return 'dismissed'
def retrieve_appealAllowedOrDismissed(filename):
start='Prior_Cases/'
f=open(start+filename+'.txt','r')
lines = f.read()
return appeal_allowedOrDismissed(lines)
"""Retrieve the name of the judge"""
def judge_check(lines):
match = re.search(r'Judgment of the Court was delivered by (\S+)', lines)
if match:
judge = match.group(1)
judge = re.sub(r'[^\w\s]','',judge)
return format(judge)
def retrieve_judge(filename):
start='Prior_Cases/'
f=open(start+filename+'.txt','r')
lines = f.read()
return judge_check(lines)
"""Retrieve the names of the appellants"""
def appellant_check(lines):
lines2=lines.splitlines()
ResSearch=0
appellant=[]
for line in lines2:
if('for appellant.' in line):
ResSearch = 1
if('for Appellant.' in line):
ResSearch = 1
if('for the appellant.' in line):
ResSearch = 1
if('for the Appellant.' in line):
ResSearch = 1
if('for appellant No.' in line):
ResSearch = 1
if('for Appellant No.' in line):
ResSearch = 1
if('for the appellant No.' in line):
ResSearch = 1
if('for the Appellant No.' in line):
ResSearch = 1
if(ResSearch):
ResSearch=0
words=re.split(',', line)
words2=re.split(' and ', words[-1])
if words:
words=words[:((len(words))-1)]
else:
continue
for x in words2:
words.append(x)
words2=re.split(' for ', words[-1])
if words:
words=words[:((len(words))-1)]
else:
continue
if words2[0]:
words.append(words2[0])
else:
continue
tagged=nltk.pos_tag(words)
for i in range ( 0, len(tagged)):
if(tagged[i][1]=='NNP'):
appellant.append(tagged[i][0])
if appellant:
return appellant
else:
return None
def retrieve_appellant(filename):
start='Prior_Cases/'
f=open(start+filename+'.txt','r')
lines = f.read()
return appellant_check(lines)
"""Retrieve names of respondents"""
def respondent_check(lines):
lines2=lines.splitlines()
respondent=[]
ResSearch=0
for line in lines2:
if('for respondent.' in line):
ResSearch = 1
if('for Respondent.' in line):
ResSearch = 1
if('for the respondent.' in line):
ResSearch = 1
if('for the Respondent.' in line):
ResSearch = 1
if('for respondent No.' in line):
ResSearch = 1
if('for Respondent No.' in line):
ResSearch = 1
if('for the respondent No.' in line):
ResSearch = 1
if('for the Respondent No.' in line):
ResSearch = 1
if(ResSearch):
ResSearch=0
words=re.split(',', line)
words2=re.split(' and ', words[-1])
if words:
words=words[:((len(words))-1)]
else:
continue
for x in words2:
words.append(x)
words2=re.split(' for ', words[-1])
if words:
words=words[:((len(words))-1)]
else:
continue
if words2[0]:
words.append(words2[0])
else:
continue
tagged=nltk.pos_tag(words)
for i in range ( 0, len(words)):
if(tagged[i][1]=='NNP'):
respondent.append(tagged[i][0])
if respondent:
return respondent
else:
return None
def retrieve_respondents(filename):
start='Prior_Cases/'
f=open(start+filename+'.txt','r')
lines = f.read()
return respondent_check(lines)
"""Retrieve order as to costs line """
def order_to_costs_check(lines):
lines2=lines.splitlines()
for line in range((len(lines2)-1),-1,-1):
String='order as to cost'
ResSearch = re.search(String, lines2[line])
if (ResSearch):
ResSearch2 = nltk.tokenize.sent_tokenize(lines2[line])
for i in range(0,len(ResSearch2)):
ResSearch = re.search(String, ResSearch2[i])
if(ResSearch):
return ResSearch2[i]
return None
def retrieve_orderAsToCosts(filename):
start='Prior_Cases/'
f=open(start+filename+'.txt','r')
lines = f.read()
order_to_costs = order_to_costs_check(lines)
return order_to_costs
"""Retrieve final judgement"""
def final_judgement(lines):
lines2=lines.split(". ")
return lines2[-5] + ". " + lines2[-4]+ ". " + lines2[-3]+ ". " + lines2[-2]
def retrieve_finalJudgement(filename):
start='Prior_Cases/prior_case_'
try:
f=open(start+filename+'.txt','r')
lines = f.read()
judgement=final_judgement(lines)
except:
judgement=None
return judgement
"""Retrieve IPCs"""
def checker_code(codeno,codestr):
if codestr=='Indian Penal Code':
if (codeno>511):
return None
else:
return 1
else:
return 1
def ipc_cpc_check(lines):
lines2=lines.splitlines()
pc=[]
ResSearch=0
for line in lines2:
code=[]
nltk_tokens = nltk.word_tokenize(line)
bigramsl=list(nltk.bigrams(nltk_tokens))
for term in bigramsl:
if(re.search('ipc' , term[0].lower())):
ResSearch = 1
code.append('Indian Penal Code')
if(re.search('indian' , term[0].lower())):
if(re.search('penal' , term[1].lower())):
ResSearch = 1
code.append('Indian Penal Code')
if(re.search('cpc' , term[0].lower())):
ResSearch = 2
code.append('Criminal Procedure Code')
if(re.search('criminal' , term[0].lower())):
if(re.search('procedure' , term[1].lower())):
ResSearch = 2
code.append('Criminal Procedure Code')
if(re.search('civil' , term[0].lower())):
if(re.search('procedure' , term[1].lower())):
ResSearch = 3
code.append('Civil Procedure Code')
if(ResSearch):
codecount=0
for term in bigramsl:
if ((term[0].lower()=='s.') or (term[0].lower()=='section')):
if (re.search(r'\d+', term[1])):
match=re.search(r'\d+', term[1])
if(checker_code(int(match.group()),code[codecount]) is not None):
pc.append(('s. '+match.group(),code[codecount]))
if (codecount+1 != len(code) ):
codecount+=1
ResSearch=0
pc = list(dict.fromkeys(pc))
return pc
def retrieve_penalCodes(filename):
start='Prior_Cases/prior_case_'
try:
f=open(start+filename+'.txt','r')
lines = f.read()
codes = ipc_cpc_check(lines)
except:
return None
return codes
def getchapter(ipcno):
if ipcno>=1 and ipcno<=5:
return("Chapter I")
elif ipcno>=6 and ipcno<=52:
return("Chapter II")
elif ipcno>=53 and ipcno<=75:
return("Chapter III")
elif ipcno>=76 and ipcno<=106:
return("Chapter IV")
elif ipcno>=107 and ipcno<=120:
return("Chapter V")
elif ipcno>=120 and ipcno<=120:
return("Chapter VA")
elif ipcno>=121 and ipcno<=130:
return("Chapter VI")
elif ipcno>=131 and ipcno<=140:
return("Chapter VII")
elif ipcno>=141 and ipcno<=160:
return("Chapter VIII")
elif ipcno>=161 and ipcno<=170:
return("Chapter IX")
elif ipcno>=171 and ipcno<=171:
return("Chapter IXA")
elif ipcno>=172 and ipcno<=190:
return("Chapter X")
elif ipcno>=191 and ipcno<=229:
return("Chapter XI")
elif ipcno>=230 and ipcno<=263:
return("Chapter XII")
elif ipcno>=264 and ipcno<=267:
return("Chapter XIII")
elif ipcno>=268 and ipcno<=294:
return("Chapter XIV")
elif ipcno>=295 and ipcno<=298:
return("Chapter XV")
elif ipcno>=299 and ipcno<=377:
return("Chapter XVI")
elif ipcno>=378 and ipcno<=462:
return("Chapter XVII")
elif ipcno>=463 and ipcno<=489:
return("Chapter XVIII")
elif ipcno>=490 and ipcno<=492:
return("Chapter XIX")
elif ipcno>=493 and ipcno<=498:
return("Chapter XX")
elif ipcno>=499 and ipcno<=502:
return("Chapter XXI")
elif ipcno>=503 and ipcno<=510:
return("Chapter XXII")
elif ipcno==511:
return("Chapter XXIII")
else:
return(None)
def retrieve_ipcs(filename):
newfile=[]
pc=retrieve_penalCodes(filename)
if pc is None:
return None
for ipc, codename in pc:
if codename == 'Indian Penal Code':
newfile.append(ipc)
if len(newfile)==0:
return None
return newfile