def test_stretch_multiple_insertions_on_one_syllable(self): sut = phonetics.Syllabification([["p", "m"], ["k", "n"]]) targetSyllabification = phonetics.Syllabification( [["t", "b", "p", "m"], ["k", "n"]]) self.assertEqual( [["''", "''", "p", "m"], ["k", "n"]], sut.stretch(targetSyllabification).toList(), )
def test_stretch_non_first_syllable_initial_pos(self): sut = phonetics.Syllabification([["p", "m"], ["k", "n"]]) targetSyllabification = phonetics.Syllabification([["p", "m"], ["p", "k", "n"]]) self.assertEqual( [["p", "m"], ["''", "k", "n"]], sut.stretch(targetSyllabification).toList(), )
def test_stretch_first_syllable_final_pos(self): # TODO: The intuition from the user is that the first syllable should be stretched # but actually its the second syllable. sut = phonetics.Syllabification([["p", "m"], ["k", "n"]]) targetSyllabification = phonetics.Syllabification([["p", "m", "p"], ["k", "n"]]) self.assertEqual( [["p", "m"], ["''", "k", "n"]], sut.stretch(targetSyllabification).toList(), )
def test_stretch_results_are_meaningless_if_the_targets_syllable_structure_is_very_different( self, ): sut = phonetics.Syllabification([["t", "b"], ["p", "m"]]) targetSyllabification = phonetics.Syllabification( [["a", "t", "b", "v"], ["j", "p", "m", "k"]]) self.assertEqual( [["''", "t", "b"], ["''", "''", "p", "m", "''"]], sut.stretch(targetSyllabification).toList(), )
def test_stretch_when_syllable_structure_differs(self): # Morph considers only the flattened phone list, so the target's # syllable structure doesn't matter sut = phonetics.Syllabification([["p", "m"], ["k", "n"]]) targetSyllabification = phonetics.Syllabification([["t", "b"], ["p", "m"], ["k", "n"]]) self.assertEqual( [["''", "''", "p", "m"], ["k", "n"]], sut.stretch(targetSyllabification).toList(), )
def test_stretch_results_are_meaningless_if_target_alignment_is_poor( self, ): # Source's final syllable matches with the target's first syllable sut = phonetics.Syllabification([["p", "m"], ["k", "n"]]) targetSyllabification = phonetics.Syllabification([["k", "n"], ["z", "v"], ["j", "l"]]) self.assertEqual( [["p", "m"], ["k", "n", "''", "''", "''", "''"]], sut.stretch(targetSyllabification).toList(), )
def test_syllabify_when_phoneme_list_is_smaller(self): # TODO: Should we potentially throw an error if the phone structure doesn't # match perfectly? sut = phonetics.PhonemeList(["r", "ˈai", "t"]) syllabification = phonetics.Syllabification([["ə"], ["t", "ˈoʊ", "n"]]) self.assertEqual([["r"], ["ˈai", "t"]], sut.syllabify(syllabification).toList())
def test_new_will_determine_stress_location(self): sut = phonetics.Syllabification.new([["l", "ˈæ"], ["b", "ɚ"], ["ˌɪ", "n", "ɵ"]]) expectedSyllabification = phonetics.Syllabification( [["l", "ˈæ"], ["b", "ɚ"], ["ˌɪ", "n", "ɵ"]], [0, 2], [1, 0]) self.assertEqual(sut, expectedSyllabification)
def test_syllabify_drops_syllables_when_phoneme_list_is_much_larger(self): sut = phonetics.PhonemeList(["ə", "t", "ˈoʊ", "n", "m", "e", "n", "t"]) syllabification = phonetics.Syllabification([["ˈai"]]) self.assertEqual( [["ə"]], sut.syllabify(syllabification).toList(), )
def test_syllabify_drops_syllables_when_phoneme_list_is_much_smaller(self): # TODO: Should we enforce that the output of syllabification contains valid # syllables? sut = phonetics.PhonemeList(["ˈai", "t"]) syllabification = phonetics.Syllabification([["ə"], ["t", "ˈoʊ", "n"], ["m", "e", "n", "t"]]) self.assertEqual([["ˈai"], ["t"]], sut.syllabify(syllabification).toList())
def test_new_can_take_a_list_of_syllables(self): syllableList = [] for syllable in [["l", "ˈæ"], ["b", "ɚ"], ["ˌɪ", "n", "ɵ"]]: syllableList.append(phonetics.Syllable(syllable)) sut = phonetics.Syllabification.new(syllableList) expectedSyllabification = phonetics.Syllabification( [["l", "ˈæ"], ["b", "ɚ"], ["ˌɪ", "n", "ɵ"]], [0, 2], [1, 0]) self.assertEqual(sut, expectedSyllabification)
def syllabification( syllables: List[List[str]] = None, stressedSyllables: List[int] = None, stressedVowels: List[int] = None, ): syllables = [["k", "a", "t"]] if syllables is None else syllables stressedSyllables = [] if stressedSyllables is None else stressedSyllables stressedVowels = [] if stressedVowels is None else stressedVowels return phonetics.Syllabification(syllables, stressedSyllables, stressedVowels)
def test_syllabify_raises_error_when_phoneme_list_is_much_larger_and_on_size_error_is_error( self, ): sut = phonetics.PhonemeList(["ə", "t", "ˈoʊ", "n", "m", "e", "n", "t"]) syllabification = phonetics.Syllabification([["ˈai"]]) with self.assertRaises(errors.SyllabificationError) as cm: sut.syllabify(syllabification, constants.ErrorReportingMode.ERROR) self.assertEqual( "The target syllabification ([['ˈai']]) is too short for the input " "(['ə', 't', 'ˈoʊ', 'n', 'm', 'e', 'n', 't']); the best fit syllabification output is ([['ə']])", str(cm.exception), )
def test_syllabify_raises_error_when_phoneme_list_is_much_smaller_and_on_size_error_is_error( self, ): sut = phonetics.PhonemeList(["ˈai", "t"]) syllabification = phonetics.Syllabification([["ə"], ["t", "ˈoʊ", "n"], ["m", "e", "n", "t"]]) with self.assertRaises(errors.SyllabificationError) as cm: sut.syllabify(syllabification, constants.ErrorReportingMode.ERROR) self.assertEqual( "The target syllabification ([['ə'], ['t', 'ˈoʊ', 'n'], ['m', 'e', 'n', 't']]) " "is too long for the input (['ˈai', 't']); the output has been truncated ([['ˈai'], ['t']])", str(cm.exception), )
def test_syllabification_instance_if_input_is_malformed(self): with self.assertRaises(AttributeError) as cm: sut = phonetics.Syllabification(["l", "ˈæ"])
def test_syllabify_when_phone_length_is_the_same(self): sut = phonetics.PhonemeList(["ɪ", "n", "ˈei", "t"]) syllabification = phonetics.Syllabification([["ə"], ["t", "ˈoʊ", "n"]]) self.assertEqual([["ɪ"], ["n", "ˈei", "t"]], sut.syllabify(syllabification).toList())
def test_syllabify_when_syllabification_isolates_consonants(self): sut = phonetics.PhonemeList(["f", "r", "ˈei", "t"]) syllabification = phonetics.Syllabification([["ə"], ["t", "ˈoʊ", "n"]]) self.assertEqual([["f"], ["r", "ˈei", "t"]], sut.syllabify(syllabification).toList())