-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegementJudgement.py
45 lines (31 loc) · 1.21 KB
/
segementJudgement.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
from typing import List
class segmentJ(object):
"""
Segment the judgement as per the human sections or the digit paragraphs
"""
def __init__(self, doc: List[str], paragraphs: bool = False):
"""
:param doc: cleaned judgement list of strings
:param paragraphs: whether to segement per paragraph or per section
"""
self.doc = doc
self.paragraphs= paragraphs
def paras(self):
"""Method to segment the judgement by paragraph"""
if self.paragraphs:
segments = [line for line in self.doc if line[0].isdigit()]
return segments
def sections(self, sections):
"""Method to segment the judgement by section
param sections: a hard-coded section list extracted from judgement
"""
inds = []
segments = []
for line in self.doc:
for sec in sections:
if sec in line:
inds.append(self.doc.index(line))
for i in range(len(inds)-1):
segments.append(self.doc[inds[i]:inds[i+1]])
segments.append(self.doc[inds[-1]:])
return segments