-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsentence_boundary.py
54 lines (45 loc) · 1.16 KB
/
sentence_boundary.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
import re
# data = input()
with open("input.txt", "r") as f:
data = f.readlines()
data = [i.strip("\n") for i in data][0]
def que_ex(data):
"""
Handles full sentences in between quotes
Handles question and exclamation marks as sentence boundaries.
Does not handle the abbreviations or salutations (Dr./Ms. etc)
"""
ndata = []
st = []
for i in data:
if i == '"':
if not st:
st.append(i)
else:
st.pop(-1)
ndata.append('"')
else:
bound = ""
if st:
bound = st.pop(-1)
if not bound:
if i == ".":
ndata.append(".|")
elif i == "?":
ndata.append("?|")
elif i == "!":
ndata.append("!|")
else:
ndata.append(i)
else:
ndata.append(i)
st.append(bound)
return "".join(ndata)
# def standardise(data):
# data = re.sub()
# print(data)
# print()
data = que_ex(data)
# print(data)
for i in data.split("|"):
print(i.strip())