def syllabify(self, phonemes: list) -> list:
"""Return the key boundaries of a sequence of phonemes.
Perform the segmentation of the sequence of phonemes into the
syllables-structure of the Cued Speech coding scheme.
A syllable structure is CV, or V or C.
:exemple:
>>> phonemes = ['b', 'O~', 'Z', 'u', 'R']
>>> CuedSpeechKeys("fra-config-file").syllabify(phonemes)
>>> [ (0, 1), (2, 3), (4, 4) ]
:exemple:
>>> phonemes = ['E', 'n', 'i:', 'h', 'w', 'E', 'r\\\\']
>>> CuedSpeechKeys("eng-config-file").syllabify(phonemes)
>>> [ (0, 0), (1, 2), (3, 5), (6, 6) ]
:param phonemes: (list of str) List of phonemes
:returns: list of tuples (begin index, end index)
"""
classes = [self.get_class(p) for p in phonemes]
syll = list()
spans = CuedSpeechKeys.compute_phonmerge_spans(phonemes, self)
def _effective_class_and_len(index: int) -> tuple:
span = spans.get(index, None)
if span is None:
return (classes[index], 1)
return (span[1], span[0])
i = 0
while i < len(phonemes):
(c, span_len) = _effective_class_and_len(i)
if c in ('W', 'V', 'C'):
if c in ('V', 'W') or i + span_len >= len(phonemes):
syll.append((i, i + span_len - 1))
else:
i_next = i + span_len
(c_next, span_len_next) = _effective_class_and_len(i_next)
if c_next in ('V', 'W'):
syll.append((i, i_next + span_len_next - 1))
i += span_len + span_len_next
continue
else:
syll.append((i, i + span_len - 1))
i += span_len
return syll