Skip to content

Commit

Permalink
test: add coverage for xsampa mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Mar 25, 2024
1 parent d8c8d6d commit 205b2b7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions g2p/tests/test_create_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,31 @@ def setUp(self):
{"in": "ɡ", "out": "G"},
{"in": "ʒ", "out": "ZH"},
]
self.mappings_xsampa = [
{"in": "A", "out": "AA"},
{"in": "e:", "out": "EY"},
{"in": "i", "out": "IY"},
{"in": "u", "out": "UW"},
{"in": "tS", "out": "CH"},
{"in": "p", "out": "P"},
{"in": "t", "out": "T"},
{"in": "k", "out": "K"},
{"in": "w", "out": "W"},
{"in": "g", "out": "G"},
{"in": "Z", "out": "ZH"},
]
self.target_mapping = Mapping(
rules=self.mappings,
in_lang="eng-ipa",
out_lang="eng-arpabet",
out_delimiter=" ",
)
self.target_mapping_xsampa = Mapping(
rules=self.mappings_xsampa,
in_lang="eng-xsampa",
out_lang="eng-arpabet",
out_delimiter=" ",
)

def test_unigram_mappings(self):
src_mappings = [
Expand Down Expand Up @@ -77,6 +96,19 @@ def test_trigram_mappings(self):
self.assertEqual(transducer("t͡ʃu").output_string, "tʃu")
self.assertEqual(transducer("t͡ʃa").output_string, "tʃɑ")

def test_trigram_mappings_xsampa(self):
src_mappings = [
{"in": "ᒋ", "out": "tSi"},
{"in": "ᒍ", "out": "tSu"},
{"in": "ᒐ", "out": "tSa"},
]
src_mapping = Mapping(rules=src_mappings, in_lang="crj", out_lang="crj-xsampa")
mapping = create_mapping(src_mapping, self.target_mapping_xsampa, quiet=True)
transducer = Transducer(mapping)
self.assertEqual(transducer("tSi").output_string, "tSi")
self.assertEqual(transducer("tSu").output_string, "tSu")
self.assertEqual(transducer("tSa").output_string, "tSA")

def test_long_mappings(self):
src_mappings = [
{"in": "ᐧᐯ", "out": "pʷeː"},
Expand Down

0 comments on commit 205b2b7

Please sign in to comment.