-
Notifications
You must be signed in to change notification settings - Fork 17
/
clean_list.py
33 lines (27 loc) · 992 Bytes
/
clean_list.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
import os
import re
new_annos = []
cleaned_new_annos = []
if os.path.exists("./barbara.list"):
with open("./barbara.list", 'r', encoding='utf-8') as f:
long_character_anno = f.readlines()
new_annos += long_character_anno
else:
print('barbara.list cannot be found, please confirm that the path is correct')
exit()
for line in new_annos:
path, name, lang, text = line.split("|")
text += "\n" if not text.endswith("\n") else ""
if len(text) >= 5:
my_re = re.compile(r'[A-Za-z]', re.S)
res = re.findall(my_re, text)
if len(res):
print(f'Skip non-kanji text : {text}')
else:
cleaned_new_annos.append(path + "|" + name + "|" + lang+ "|" + text)
else:
print(f'skip too short wav : {text}')
with open("./clean_barbara.list", 'w', encoding='utf-8') as f:
for line in cleaned_new_annos:
f.write(line)
print('Done! save as clean_barbara.list')