-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert_to_rhythm.py
34 lines (30 loc) · 938 Bytes
/
convert_to_rhythm.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
def get_metadata_and_text(line):
txt = line.split('\n')[-1]
metadata, _ = line.split(txt)
return metadata, txt
def replace_letter(s):
if s[0].isalpha():
return 'X'
else:
return s
def replace_letters(txt):
toks = txt.split(' ')
new_toks = [replace_letter(t) for t in toks]
return ' '.join(new_toks)
def rhythm_only(line):
metadata, txt = get_metadata_and_text(line)
txt = txt.strip()
txt = replace_letters(txt)
return "".join([metadata, txt])
for f in ["output_folkrnnv2.txt", "original_data.txt"]:
lines = open(f).read().split('\n\n')[0:-1]
rhythm_lines = []
for i,l in enumerate(lines):
try:
rhythm_lines.append(rhythm_only(l))
except:
print(i)
big_str = "\n\n".join(rhythm_lines)
filename = f.split(".txt")[0] + "_rhythm_only" + ".txt"
with open(filename, "w") as outfile:
outfile.write(big_str)