-
Notifications
You must be signed in to change notification settings - Fork 0
/
stress_indices.py
54 lines (36 loc) · 1.24 KB
/
stress_indices.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
# coding: utf-8
import ast, glob, os, argparse
from itertools import chain
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
def stress_indicator(f, **kwargs):
"""
Returns a txt-file with the indices of stressed syllables
(indices for each line)
Parameters:
f is the txt-file with the stressed/not stressed syllables.
"""
# input file - txt with lists of accentized syllables
file_input = open(f, 'r', encoding = 'utf-8')
lines = file_input.readlines()
# output file - txt with lists of indices of stressed syllables
name = f.split('.')[0] + '_ind.txt'
f_out = open(os.path.join(dname, name), 'w')
# read and process input file
ll = list()
for i in range(0, len(lines)):
ll.append(ast.literal_eval(lines[i]))
for l in ll:
indices = list()
for s in l:
if s.isupper():
indices.append(l.index(s))
f_out.write(str(indices))
f_out.write('\n')
f_out.close()
file_input.close()
parser = argparse.ArgumentParser()
parser.set_defaults(method = stress_indicator)
parser.add_argument('f', action = 'store')
args = parser.parse_args()
args.method(**vars(args))