Use of rules to precise pronunciation of a preprocessed list of transcribed words
        :param phonemes: list(Vowel or Consonant)
        :return: str
170569
def phonemes_to_phonetic_representation(self, phonemes: list) -> str:
        
        phonetic_representation = []
        if len(phonemes) >= 2:
            for i in range(len(phonemes)):
                if i == 0:
                    current_pos = Position(Rank.first, None, phonemes[i])
                elif i < len(phonemes) - 1:
                    current_pos = Position(Rank.inner, phonemes[i - 1], phonemes[i + 1])
                else:
                    current_pos = Position(Rank.last, phonemes[i - 1], None)
                found = False
                for rule in self.rules:
                    if rule.temp_sound.ipar == phonemes[i].ipar:
                        if rule.can_apply(current_pos):
                            phonetic_representation.append(rule.estimated_sound.ipar)
                            found = True
                            break
                if not found:
                    phonetic_representation.append(phonemes[i].ipar)
        else:
            phonetic_representation.append(phonemes[0].ipar)
        return "".join(phonetic_representation)
773382
def calc_offset(self, syllables_spaces: List[str]) -> Dict[int, int]:
        
        line = string_utils.flatten(syllables_spaces)
        mydict = {} # type: Dict[int, int]
        # #defaultdict(int) #type: Dict[int, int]
        for idx, syl in enumerate(syllables_spaces):
            target_syllable = syllables_spaces[idx]
            skip_qu = string_utils.starts_with_qu(target_syllable)
            matches = list(self.syllable_matcher.finditer(target_syllable))
            for position, possible in enumerate(matches):
                if skip_qu:
                    skip_qu = False
                    continue
                (start, end) = possible.span()
                if target_syllable[start:end] in \
                        self.constants.VOWELS + self.constants.ACCENTED_VOWELS:
                    part = line[:len("".join(syllables_spaces[:idx]))]
                    offset = len(part) + start
                    if line[offset] not in self.constants.VOWELS + self.constants.ACCENTED_VOWELS:
                        LOG.error("Problem at line {} offset {}".format(line, offset))
                    mydict[idx] = offset
        return mydict
855275
def vowels(self):
        
        return IPAString(ipa_chars=[c for c in self.ipa_chars if c.is_vowel])
1061382
def phonemes(self,set=None):
        """"""
        for layer in self.select(PhonologyLayer):
            for p in layer.select(Phoneme, set):
                yield p
1290124
def _findBestSyllabification(inputIsleWordList, actualPronunciationList):
    '''
    
    '''
    retList = _findBestPronunciation(inputIsleWordList,
                                     actualPronunciationList)
    isleWordList, alignedAPronList, alignedSyllableList, bestIndex = retList
    
    alignedPhoneList = alignedAPronList[bestIndex]
    alignedSyllables = alignedSyllableList[bestIndex]
    syllabification = isleWordList[bestIndex][0]
    stressedSyllableIndexList = isleWordList[bestIndex][1]
    stressedPhoneIndexList = isleWordList[bestIndex][2]
    
    syllableList = _syllabifyPhones(alignedPhoneList, alignedSyllables)
    
    # Get the location of stress in the generated file
    try:
        stressedSyllableI = stressedSyllableIndexList[0]
    except IndexError:
        stressedSyllableI = None
        stressedVowelI = None
    else:
        stressedVowelI = _getSyllableNucleus(syllableList[stressedSyllableI])
    
    # Count the index of the stressed phones, if the stress list has
    # become flattened (no syllable information)
    flattenedStressIndexList = []
    for i, j in zip(stressedSyllableIndexList, stressedPhoneIndexList):
        k = j
        for l in range(i):
            k += len(syllableList[l])
        flattenedStressIndexList.append(k)
    
    return (stressedSyllableI, stressedVowelI, syllableList, syllabification,
            stressedSyllableIndexList, stressedPhoneIndexList,
            flattenedStressIndexList)
1104904
def _parsePronunciation(pronunciationStr):
    '''
    
    '''
    retList = []
    for syllableTxt in pronunciationStr.split("#"):
        if syllableTxt == "":
            continue
        syllableList = [x.split() for x in syllableTxt.split(' . ')]
        
        # Find stress
        stressedSyllableList = []
        stressedPhoneList = []
        for i, syllable in enumerate(syllableList):
            for j, phone in enumerate(syllable):
                if u"ˈ" in phone:
                    stressedSyllableList.insert(0, i)
                    stressedPhoneList.insert(0, j)
                    break
                elif u'ˌ' in phone:
                    stressedSyllableList.append(i)
                    stressedPhoneList.append(j)
        
        retList.append((syllableList, stressedSyllableList, stressedPhoneList))
    
    return retList
414508
def correct(tokens, term_freq):
    
    log = []
    output = []
    for token in tokens:
        corrected = _correct(token, term_freq)
        if corrected != token:
            log.append((token, corrected))
        output.append(corrected)
    return output, log
890848
def apply_T4(word):
    ''''''
    WORD = word.split('.')
    PARTS = [[] for part in range(len(WORD))]

    for i, v in enumerate(WORD):

        # i % 2 != 0 prevents this rule from applying to first, third, etc.
        # syllables, which receive stress (WSP)
        if is_consonant(v[-1]) and i % 2 != 0:
            if i + 1 == len(WORD) or is_consonant(WORD[i + 1][0]):
                vv = u_y_final_diphthongs(v)

                if vv:
                    I = vv.start(1) + 1
                    PARTS[i].append(v[:I] + '.' + v[I:])

        # include original form (non-application of rule)
        PARTS[i].append(v)

    WORDS = [w for w in product(*PARTS)]

    for WORD in WORDS:
        WORD = '.'.join(WORD)
        RULE = ' T4' if word != WORD else ''

        yield WORD, RULE
298841
def _setup(self, word) -> List[str]:
        
        if len(word) == 1:
            return [word]
        for prefix in self.constants.PREFIXES:
            if word.startswith(prefix):
                (first, rest) = string_utils.split_on(word, prefix)
                if self._contains_vowels(rest):
                    return string_utils.remove_blank_spaces(
                        self._process(first) + self._process(rest))
                # a word like pror can happen from ellision
                return string_utils.remove_blank_spaces(self._process(word))
        if word in self.constants.UI_EXCEPTIONS.keys():
            return self.constants.UI_EXCEPTIONS[word]
        return string_utils.remove_blank_spaces(self._process(word))
383431
def find_alliterations(self):
        
        self.n_alliterations = 0
        self.alliterations = []
        for j, sound1 in enumerate(self.first_sounds):
            word1 = normalize(self.tokenized_text[j])
            if j < len(self.first_sounds)-1:
                for k, sound2 in enumerate(self.first_sounds[j+1:]):
                    word2 = normalize(self.tokenized_text[k])
                    if word1 not in STOPS_LIST and sound2 not in STOPS_LIST:
                        if isinstance(sound1, Consonant) and sound1.ipar == sound2.ipar:
                            self.alliterations.append((word1, word2))
                            self.n_alliterations += 1
                        elif isinstance(sound1, Vowel) and isinstance(sound2, Vowel):
                            self.alliterations.append((word1, word2))
                            self.n_alliterations += 1
        return self.alliterations, self.n_alliterations
1258015
function consonantString(tokens, i) { // strings, int
	var out = [];
	var t = '';
	while (tokens[i] != null) {
		t = tokens[i++];
		if (t == '+' || t == '^') continue;
		if (consonant(t) == null) break;
		out.push(t);
	}
	return out.join("+");
}
1254492
def apply_T1(word):
    ''''''
    # split consonants and vowels: 'balloon' -> ['b', 'a', 'll', 'oo', 'n']
    WORD = [w for w in re.split('([ieAyOauo]+)', word) if w]
    count = 0

    for i, v in enumerate(WORD):

        if i == 0 and is_consonant(v[0]):
            continue

        elif is_consonant(v[0]) and i + 1 != len(WORD):
            if is_cluster(v):  # WSP
                if count % 2 == 0:
                    WORD[i] = v[0] + '.' + v[1:]  # CC > C.C, CCC > C.CC

                else:
                    WORD[i] = '.' + v  # CC > .CC, CCC > .CCC

            # elif is_sonorant(v[0]) and is_cluster(v[1:]):  # NEW
            #     if count % 2 == 0:
            #         WORD[i] = v[0:2] + '.' + v[2:]

            #     else:
            #         WORD[i] = v[0] + '.' + v[1:]

            else:
                WORD[i] = v[:-1] + '.' + v[-1]  # CC > C.C, CCC > CC.C

            count += 1

    WORD = ''.join(WORD)
    RULE = ' T1' if word != WORD else ''

    return WORD, RULE
1311018
def _position_phonemes(self, phonemes):
		'''
		
		'''
		for i in range(len(phonemes)):
			phonemes[i] = PositionedPhoneme(phonemes[i])
			phonemes[i].syllable_initial = self.is_syllable_initial(phonemes, i)
			phonemes[i].syllable_final = self.is_syllable_final(phonemes, i)

		return phonemes
481980
def get_precomposed_chars():
	
	return set([
		letter for letter in chart.consonants
		if unicodedata.normalize('NFD', letter) != letter ])
488566
def transform_i_to_j(self, line: str) -> str:
        

        words = line.split(" ")
        space_list = string_utils.space_list(line)
        corrected_words = []
        for word in words:
            found = False
            for prefix in self.constants.PREFIXES:
                if word.startswith(prefix) and word != prefix:
                    corrected_words.append(self.syllabifier.convert_consonantal_i(prefix))
                    corrected_words.append(
                        self.syllabifier.convert_consonantal_i(word[len(prefix):]))
                    found = True
                    break
            if not found:
                corrected_words.append(self.syllabifier.convert_consonantal_i(word))
        new_line = string_utils.join_syllables_spaces(corrected_words, space_list)
        char_list = string_utils.overwrite(list(new_line),
                                          r"\b[iī][{}]".format(
                                              self.constants.VOWELS + self.constants.ACCENTED_VOWELS),
                                          "j")
        char_list = string_utils.overwrite(char_list,
                                          r"\b[I][{}]".format(self.constants.VOWELS_WO_I),
                                          "J")
        char_list = string_utils.overwrite(char_list, r"[{}][i][{}]".format(
            self.constants.VOWELS_WO_I, self.constants.VOWELS),
                                          "j", 1)
        return "".join(char_list)
614879
def _find_consonant_cluster(self, letters: List[str]) -> List[int]:
        
        for idx, letter_group in enumerate(letters):
            if self._contains_consonants(letter_group) and not self._contains_vowels(letter_group):
                return [idx]
        return []
58260
def convert_to_wav(files):
    ''''''
    converted = []
    for f in files:
        new_name = f + '.temp.wav'
        print(new_name)
        if (os.path.exists(f + '.transcription.txt') is False) and (os.path.exists(new_name) is False):
            subprocess.call(['ffmpeg', '-y', '-i', f, '-acodec', 'pcm_s16le', '-ac', '1', '-ar', '16000', new_name])
        converted.append(new_name)
    return converted