Пример #1
0
 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)
Пример #2
0
 def test_rule7_utils(self):
     b = ut.Consonant(ut.Place.bilabial, ut.Manner.stop, True, "b", False)
     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, b, b)
     self.assertEqual(rule.can_apply(pos), True)
Пример #3
0
 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)
Пример #4
0
 def test_consonant_utils(self):
     # example of a Consonant
     b = ut.Consonant(ut.Place.bilabial, ut.Manner.stop, True, "b", False)
     self.assertListEqual(
         [b.ipar, b.manner, b.place, b.voiced, b.geminate],
         ["b", ut.Manner.stop, ut.Place.bilabial, True, False],
     )
Пример #5
0
    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)
Пример #6
0
    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])ð$")
Пример #7
0
 def test_add_consonants_utils(self):
     # This is how Consonant instances can be added to each other
     k = ut.Consonant(ut.Place.velar, ut.Manner.stop, False, "k", False)
     s = ut.Consonant(ut.Place.alveolar, ut.Manner.fricative, False, "s", False)
     x = k + s
     self.assertEqual(x.ipar, "ks")