Beispiel #1
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")
Beispiel #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)
Beispiel #3
0
 def test_rule4_utils(self):
     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, a, a)
     self.assertEqual(rule.can_apply(pos), False)
Beispiel #4
0
 def test_rule7_utils(self):
     b = ut.Consonant("bilabial", "stop", True, "b", False)
     th = ut.Consonant("dental", "frictative", False, "θ", False)
     dh = ut.Consonant("dental", "frictative", True, "ð", False)
     rule = ut.Rule(
         ut.AbstractPosition("inner", [ut.AbstractConsonant(voiced=True)],
                             [ut.AbstractConsonant(voiced=True)]), th, dh)
     pos = ut.Position("inner", b, b)
     self.assertEqual(rule.can_apply(pos), True)
Beispiel #5
0
 def test_rule4_utils(self):
     a = ut.Vowel("open", "front", False, "short", "a")
     th = ut.Consonant("dental", "frictative", False, "θ", False)
     dh = ut.Consonant("dental", "frictative", True, "ð", False)
     rule = ut.Rule(
         ut.AbstractPosition("inner", [ut.AbstractConsonant(voiced=True)],
                             [ut.AbstractConsonant(voiced=True)]), th, dh)
     pos = ut.Position("inner", a, a)
     self.assertEqual(rule.can_apply(pos), False)
Beispiel #6
0
 def test_rule2_utils(self):
     k = ut.Consonant("velar", "stop", False, "k", False)
     a = ut.Vowel("open", "front", False, "short", "a")
     th = ut.Consonant("dental", "frictative", False, "θ", False)
     dh = ut.Consonant("dental", "frictative", True, "ð", False)
     rule = ut.Rule(
         ut.AbstractPosition("inner", [ut.AbstractVowel()],
                             [ut.AbstractVowel()]), th, dh)
     pos = ut.Position("inner", k, a)
     self.assertEqual(rule.can_apply(pos), False)
Beispiel #7
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],
     )
Beispiel #8
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)
Beispiel #9
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])ð$")
Beispiel #10
0
    def test_rule_conversion1(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]

        # examples of ipa_to_regular_expression and from_regular_expression methods
        ru1 = ut.Rule(
            ut.AbstractPosition(ut.Rank.inner,
                                [ut.AbstractConsonant(voiced=False)],
                                [ut.AbstractConsonant(voiced=True)]), th, th)
        self.assertEqual(ru1.ipa_to_regular_expression(phonology),
                         "(?<=[fkpstθ])θ(?=[bdgvð])")
Beispiel #11
0
    def test_rule_conversion4(self):
        # Definition of real Vowel and Consonant instances
        a = ut.Vowel("open", "front", False, "short", "a")
        e = ut.Vowel("close-mid", "front", False, "short", "e")
        i = ut.Vowel("close", "front", False, "short", "i")
        o = ut.Vowel("close-mid", "back", True, "short", "o")
        u = ut.Vowel("close", "back", True, "short", "u")

        b = ut.Consonant("bilabial", "stop", True, "b", False)
        d = ut.Consonant("alveolar", "stop", True, "d", False)
        f = ut.Consonant("labio-dental", "frictative", False, "f", False)
        g = ut.Consonant("velar", "stop", True, "g", False)
        k = ut.Consonant("velar", "stop", False, "k", False)
        p = ut.Consonant("bilabial", "stop", False, "p", False)
        s = ut.Consonant("alveolar", "frictative", False, "s", False)
        t = ut.Consonant("alveolar", "stop", False, "t", False)
        v = ut.Consonant("labio-dental", "frictative", True, "v", False)
        th = ut.Consonant("dental", "frictative", False, "θ", False)
        dh = ut.Consonant("dental", "frictative", 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)
Beispiel #12
0
    def test_rule_conversion3(self):
        # Definition of real Vowel and Consonant instances
        a = ut.Vowel("open", "front", False, "short", "a")
        e = ut.Vowel("close-mid", "front", False, "short", "e")
        i = ut.Vowel("close", "front", False, "short", "i")
        o = ut.Vowel("close-mid", "back", True, "short", "o")
        u = ut.Vowel("close", "back", True, "short", "u")

        b = ut.Consonant("bilabial", "stop", True, "b", False)
        d = ut.Consonant("alveolar", "stop", True, "d", False)
        f = ut.Consonant("labio-dental", "frictative", False, "f", False)
        g = ut.Consonant("velar", "stop", True, "g", False)
        k = ut.Consonant("velar", "stop", False, "k", False)
        p = ut.Consonant("bilabial", "stop", False, "p", False)
        s = ut.Consonant("alveolar", "frictative", False, "s", False)
        t = ut.Consonant("alveolar", "stop", False, "t", False)
        v = ut.Consonant("labio-dental", "frictative", True, "v", False)
        th = ut.Consonant("dental", "frictative", False, "θ", False)
        dh = ut.Consonant("dental", "frictative", 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("last", [ut.AbstractConsonant(manner="stop")],
                                None), dh, th)
        self.assertEqual(ru3.ipa_to_regular_expression(PHONOLOGY),
                         "(?<=[bdgkpt])ð$")
Beispiel #13
0
 def test_add_consonants_utils(self):
     # This is how Consonant instances can be added to each other
     k = ut.Consonant("velar", "stop", False, "k", False)
     s = ut.Consonant("alveolar", "frictative", False, "s", False)
     x = k + s
     self.assertEqual(x.ipar, "ks")
Beispiel #14
0
 def test_consonant_utils(self):
     # example of a Consonant
     b = ut.Consonant("bilabial", "stop", True, "b", False)
     self.assertListEqual([b.ipar, b.manner, b.place, b.voiced, b.geminate],
                          ["b", "stop", "bilabial", True, False])