def test_rule_conversion3(self): # Definition of real Vowel and Consonant instances a = ut.Vowel(ut.Height.open, ut.Backness.front, False, ut.Length.short, "a") e = ut.Vowel( ut.Height.close_mid, ut.Backness.front, False, ut.Length.short, "e" ) i = ut.Vowel(ut.Height.close, ut.Backness.front, False, ut.Length.short, "i") o = ut.Vowel(ut.Height.close_mid, ut.Backness.back, True, ut.Length.short, "o") u = ut.Vowel(ut.Height.close, ut.Backness.back, True, ut.Length.short, "u") b = ut.Consonant(ut.Place.bilabial, ut.Manner.stop, True, "b", False) d = ut.Consonant(ut.Place.alveolar, ut.Manner.stop, True, "d", False) f = ut.Consonant(ut.Place.labio_dental, ut.Manner.fricative, False, "f", False) g = ut.Consonant(ut.Place.velar, ut.Manner.stop, True, "g", False) k = ut.Consonant(ut.Place.velar, ut.Manner.stop, False, "k", False) p = ut.Consonant(ut.Place.bilabial, ut.Manner.stop, False, "p", False) s = ut.Consonant(ut.Place.alveolar, ut.Manner.fricative, False, "s", False) t = ut.Consonant(ut.Place.alveolar, ut.Manner.stop, False, "t", False) v = ut.Consonant(ut.Place.labio_dental, ut.Manner.fricative, True, "v", False) th = ut.Consonant(ut.Place.dental, ut.Manner.fricative, False, "θ", False) dh = ut.Consonant(ut.Place.dental, ut.Manner.fricative, True, "ð", False) # examples of phonology and ipa_class phonology = [a, e, i, o, u, b, d, f, g, k, p, s, t, v, th, dh] ru3 = ut.Rule( ut.AbstractPosition( ut.Rank.last, [ut.AbstractConsonant(manner=ut.Manner.stop)], None ), dh, th, ) self.assertEqual(ru3.ipa_to_regular_expression(phonology), "(?<=[bdgkpt])ð$")
def test_utils(self): # definition of a Vowel a = ut.Vowel(ut.Height.open, ut.Backness.front, False, ut.Length.short, "a") self.assertListEqual( [a.ipar, a.backness, a.height, a.length, a.rounded], ["a", ut.Backness.front, ut.Height.open, ut.Length.short, False], )
def test_rule_conversion4(self): # Definition of real Vowel and Consonant instances a = ut.Vowel(ut.Height.open, ut.Backness.front, False, ut.Length.short, "a") e = ut.Vowel( ut.Height.close_mid, ut.Backness.front, False, ut.Length.short, "e" ) i = ut.Vowel(ut.Height.close, ut.Backness.front, False, ut.Length.short, "i") o = ut.Vowel(ut.Height.close_mid, ut.Backness.back, True, ut.Length.short, "o") u = ut.Vowel(ut.Height.close, ut.Backness.back, True, ut.Length.short, "u") b = ut.Consonant(ut.Place.bilabial, ut.Manner.stop, True, "b", False) d = ut.Consonant(ut.Place.alveolar, ut.Manner.stop, True, "d", False) f = ut.Consonant(ut.Place.labio_dental, ut.Manner.fricative, False, "f", False) g = ut.Consonant(ut.Place.velar, ut.Manner.stop, True, "g", False) k = ut.Consonant(ut.Place.velar, ut.Manner.stop, False, "k", False) p = ut.Consonant(ut.Place.bilabial, ut.Manner.stop, False, "p", False) s = ut.Consonant(ut.Place.alveolar, ut.Manner.fricative, False, "s", False) t = ut.Consonant(ut.Place.alveolar, ut.Manner.stop, False, "t", False) v = ut.Consonant(ut.Place.labio_dental, ut.Manner.fricative, True, "v", False) th = ut.Consonant(ut.Place.dental, ut.Manner.fricative, False, "θ", False) dh = ut.Consonant(ut.Place.dental, ut.Manner.fricative, True, "ð", False) # examples of phonology and ipa_class phonology = [a, e, i, o, u, b, d, f, g, k, p, s, t, v, th, dh] ipa_class = { "a": a, "e": e, "i": i, "o": o, "u": u, "b": b, "d": d, "f": f, "g": g, "k": k, "p": p, "s": s, "t": t, "v": v, "þ": th, "ð": dh, } # from regular expression to Rule example = r"(?<=[aeiou])f(?=[aeiou])" ru4 = ut.Rule.from_regular_expression(example, "v", ipa_class) self.assertEqual(ru4.ipa_to_regular_expression(phonology), example)
def test_rule3_utils(self): s = ut.Consonant(ut.Place.alveolar, ut.Manner.fricative, False, "s", False) a = ut.Vowel(ut.Height.open, ut.Backness.front, False, ut.Length.short, "a") th = ut.Consonant(ut.Place.dental, ut.Manner.fricative, False, "θ", False) dh = ut.Consonant(ut.Place.dental, ut.Manner.fricative, True, "ð", False) rule = ut.Rule( ut.AbstractPosition( ut.Rank.inner, [ut.AbstractVowel()], [ut.AbstractVowel()] ), th, dh, ) pos = ut.Position(ut.Rank.inner, a, s) self.assertEqual(rule.can_apply(pos), False)
def test_rule5_utils(self): k = ut.Consonant(ut.Place.velar, ut.Manner.stop, False, "k", False) a = ut.Vowel(ut.Height.open, ut.Backness.front, False, ut.Length.short, "a") th = ut.Consonant(ut.Place.dental, ut.Manner.fricative, False, "θ", False) dh = ut.Consonant(ut.Place.dental, ut.Manner.fricative, True, "ð", False) rule = ut.Rule( ut.AbstractPosition( ut.Rank.inner, [ut.AbstractConsonant(voiced=True)], [ut.AbstractConsonant(voiced=True)], ), th, dh, ) pos = ut.Position(ut.Rank.inner, k, a) self.assertEqual(rule.can_apply(pos), False)
def test_vowel_lengthening_utils(self): # how lengthen works a = ut.Vowel(ut.Height.open, ut.Backness.front, False, ut.Length.short, "a") aa = a.lengthen() self.assertEqual(aa.ipar, "aː")