Example #1
0
def i2a(ipastring):
    """Convert an IPA string to an arpabet string.

    Args:
        ipastring: A string representing ipa using utf-8 encoding.
    Returns:
        arpabetstring: A list representing the corresponding arpabet.

    """
    amapper = ARPABETMapper()
    arpastring = amapper.map_unicode_string(ipastring,
                                            ignore=True,
                                            return_as_list=True)
    return arpastring
Example #2
0
 def test_map_ipa_string(self):
     mapper = ARPABETMapper()
     values = [
         (u"", u""),
         (u"p", u"P"),
         (u"p\u03B8", u"PTH"),
         (u"\u027E", u"DX"),
         (u"p\u0258\u026A", u"PEY"),
         (u"p\u0258\u026Aw", u"PEYW"),
         (u"p\u0258\u026A\u0258\u026Aw", u"PEYEYW"),
         (u"p\u0258\u026A\u0251w", u"PEYAAW"),
         (u"\u006A\u0075", u"YUW"),
     ]
     for v, e in values:
         self.assertEqual(mapper.map_ipa_string(IPAString(unicode_string=v)), e)
Example #3
0
 def test_map_unicode_string_single(self):
     mapper = ARPABETMapper()
     values = [
         (u"", u""),
         (u"p", u"P"),
         (u"p\u03B8", u"PTH"),
         (u"\u027E", u"DX"),
         (u"p\u0258\u026A", u"PEY"),
         (u"p\u0258\u026Aw", u"PEYW"),
         (u"p\u0258\u026A\u0258\u026Aw", u"PEYEYW"),
         (u"p\u0258\u026A\u0251w", u"PEYAAW"),
         (u"\u006A\u0075", u"YUW"),
     ]
     for v, e in values:
         self.assertEqual(mapper.map_unicode_string(v, single_char_parsing=True), e)
Example #4
0
 def test_map_ipa_string(self):
     mapper = ARPABETMapper()
     values = [
         (u"", u""),
         (u"p", u"P"),
         (u"p\u03B8", u"PTH"),
         (u"\u027E", u"DX"),
         (u"p\u0258\u026A", u"PEY"),
         (u"p\u0258\u026Aw", u"PEYW"),
         (u"p\u0258\u026A\u0258\u026Aw", u"PEYEYW"),
         (u"p\u0258\u026A\u0251w", u"PEYAAW"),
         (u"\u006A\u0075", u"YUW"),
     ]
     for v, e in values:
         self.assertEqual(
             mapper.map_ipa_string(IPAString(unicode_string=v)), e)
Example #5
0
 def test_map_unicode_string_single(self):
     mapper = ARPABETMapper()
     values = [
         (u"", u""),
         (u"p", u"P"),
         (u"p\u03B8", u"PTH"),
         (u"\u027E", u"DX"),
         (u"p\u0258\u026A", u"PEY"),
         (u"p\u0258\u026Aw", u"PEYW"),
         (u"p\u0258\u026A\u0258\u026Aw", u"PEYEYW"),
         (u"p\u0258\u026A\u0251w", u"PEYAAW"),
         (u"\u006A\u0075", u"YUW"),
     ]
     for v, e in values:
         self.assertEqual(
             mapper.map_unicode_string(v, single_char_parsing=True), e)
Example #6
0
 def test_can_map_ipa_string(self):
     mapper = ARPABETMapper()
     values = [
         (u"", True),
         (u"p", True),
         (u"p\u03B8", True),
         (u"\u027E", True),
         (u"\u0258\u026A", True),
         (u"p\u0258\u026A", True),
         (u"p\u0258\u026Aw", True),
         (u"p\u0258\u026A\u0258\u026Aw", True),
         (u"p\u0258\u026A\u0251w", True),
         (u"\u006A\u0075", True),
         (u"\u1DC6", False),   # valid IPA char, unmapped in Kirshenbaum
         (u"p\u1DC6b", False), # valid IPA char, unmapped in Kirshenbaum
     ]
     for v, e in values:
         self.assertEqual(mapper.can_map_ipa_string(IPAString(unicode_string=v)), e)
Example #7
0
 def test_can_map_ipa_string(self):
     mapper = ARPABETMapper()
     values = [
         (u"", True),
         (u"p", True),
         (u"p\u03B8", True),
         (u"\u027E", True),
         (u"\u0258\u026A", True),
         (u"p\u0258\u026A", True),
         (u"p\u0258\u026Aw", True),
         (u"p\u0258\u026A\u0258\u026Aw", True),
         (u"p\u0258\u026A\u0251w", True),
         (u"\u006A\u0075", True),
         (u"\u1DC6", False),  # valid IPA char, unmapped in Kirshenbaum
         (u"p\u1DC6b", False),  # valid IPA char, unmapped in Kirshenbaum
     ]
     for v, e in values:
         self.assertEqual(
             mapper.can_map_ipa_string(IPAString(unicode_string=v)), e)
Example #8
0
 def test_map_unicode_string_ignore(self):
     mapper = ARPABETMapper()
     values = [
         (None, None),
         (u"", u""),
         (u"p", u"P"),
         (u"p\u03B8", u"PTH"),
         (u"\u027E", u"DX"),
         (u"p\u0258\u026A", u"PEY"),
         (u"p\u0258\u026Aw", u"PEYW"),
         (u"p\u0258\u026A\u0258\u026Aw", u"PEYEYW"),
         (u"p\u0258\u026A\u0251w", u"PEYAAW"),
         (u"\u006A\u0075", u"YUW"),
         (u"a\u006A\u0075", u"AEYUW"),
         (u"o\u006A\u0075", u"OHYUW"),
         (u"S\u006A\u0075", u"YUW"),
         (u"S\u006A\u0075\u02C8be", u"YUWBEH"),
     ]
     for v, e in values:
         self.assertEqual(mapper.map_unicode_string(v, ignore=True), e)
Example #9
0
 def test_map_unicode_string_ignore(self):
     mapper = ARPABETMapper()
     values = [
         (None, None),
         (u"", u""),
         (u"p", u"P"),
         (u"p\u03B8", u"PTH"),
         (u"\u027E", u"DX"),
         (u"p\u0258\u026A", u"PEY"),
         (u"p\u0258\u026Aw", u"PEYW"),
         (u"p\u0258\u026A\u0258\u026Aw", u"PEYEYW"),
         (u"p\u0258\u026A\u0251w", u"PEYAAW"),
         (u"\u006A\u0075", u"YUW"),
         (u"a\u006A\u0075", u"AEYUW"),
         (u"o\u006A\u0075", u"OHYUW"),
         (u"S\u006A\u0075", u"YUW"),
         (u"S\u006A\u0075\u02C8be", u"YUWBEH"),
     ]
     for v, e in values:
         self.assertEqual(mapper.map_unicode_string(v, ignore=True), e)
Example #10
0
def command_u2a(string, vargs):
    """
    Print the ARPABEY ASCII string corresponding to the given Unicode IPA string. 

    :param str string: the string to act upon
    :param dict vargs: the command line arguments
    """
    try:
        l = ARPABETMapper().map_unicode_string(
            unicode_string=string,
            ignore=vargs["ignore"],
            single_char_parsing=vargs["single_char_parsing"],
            return_as_list=True)
        print(vargs["separator"].join(l))
    except ValueError as exc:
        print_error(str(exc))