-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.py
More file actions
59 lines (54 loc) · 1.56 KB
/
parse.py
File metadata and controls
59 lines (54 loc) · 1.56 KB
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
import re
def parse(filename):
# filename = raw_input("file: ")
# filename = "ender_tmp.txt"
file = open(filename, "r")
filestr = ""
fileall = ""
for line in file:
fileall += line
filestr += line.replace("\n", " ")
# everything, punctuation and all
count = 0
quote = 0
temp = ""
everything = []
ender = ".", "?", "!" # in case delimiters changes
for count in range(0, len(fileall)):
char = fileall[count]
# quote starting
if char == "\"":
temp += char
if quote == 0:
quote = 1
else:
# quote ending, nothing following
if fileall[count + 1] == "\n":
temp += " "
everything.append(temp)
temp = ""
count += 1
quote = 0
else:
temp += " "
quote = 0
else:
# in quote, continue no matter what
if quote == 1:
if char != "\n":
temp += char
else:
temp += " "
# out of quote, sentence ended
elif char in ender:
temp += char + " "
everything.append(temp)
temp = ""
else:
if char != "\n":
temp += char
else:
temp += " "
return everything
if __name__ == "__main__":
everything = parse("ender_tmp.txt")