-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample2.py
40 lines (34 loc) · 1.15 KB
/
sample2.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
import re
import os
txt_files = os.listdir("samples/stories/test/")
# print(txt_files)
# dictionary for one row keyboard
one_row = {"q": 1, "a": 1, "z": 1,
"w": 2, "s": 2, "x": 2,
"e": 3, "d": 3, "c": 3,
"r": 4, "f": 4, "v": 4,
"t": 5, "g": 5, "b": 5,
"y": 6, "h": 6, "n": 6,
"u": 7, "j": 7, "m": 7,
"i": 8, "k": 8,
"o": 9, "l": 9,
"p": 0}
output = list([])
for txt_file in txt_files:
with open("samples/stories/test/"+txt_file, "r", encoding='utf-8') as f:
for line in f:
w_list = line.split()
for w in w_list:
w = re.sub(r"[^a-zA-Z]", "", w)
word_to_num = ""
for c in w:
try:
word_to_num += str(one_row[c.lower()])
except KeyError:
break
if len(word_to_num) > 0:
output.append(word_to_num+"/"+w)
# print(output)
with open("output6.txt", "w") as f2:
for line in output:
f2.write(line+"\n")