Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'grapheme to phoneme file not found: {}'.format(language))
# load the mapping grapheme -> phoneme from the file, make sure all
# lines are well formatted
g2p = {}
for n, line in enumerate(codecs.open(language, 'r', encoding='utf8')):
elts = line.strip().split()
if not len(elts) == 2:
raise RuntimeError(
'grapheme to phoneme file, line {} must have 2 rows '
'but have {}: {}'.format(n+1, len(elts), language))
g2p[elts[0]] = elts[1]
# build the segments profile from the g2p mapping
return segments.Profile(
*[{'Grapheme': k, 'mapping': v} for k, v in g2p.items()])