示例#1
0
    def test_pinyin_tone_numbers(self):
        self.assertEqual(
            bopomofo(['ni3', 'ne5', 'ru2guo3 zhu4yin1']),
            ['ㄋㄧˇ', 'ㄋㄜ˙', 'ㄖㄨˊ ㄍㄨㄛˇ ㄓㄨˋ ㄧㄣ'],
        )

        self.assertEqual(bopomofo(['mei2 you3']), ['ㄇㄟˊ ㄧㄡˇ'])
 def test_pinyin_syllables_yin(self):
     self.assertEqual(bopomofo(['bin']), ['ㄅㄧㄣ˙'])
     self.assertEqual(bopomofo(['pin']), ['ㄆㄧㄣ˙'])
     self.assertEqual(bopomofo(['min']), ['ㄇㄧㄣ˙'])
     self.assertEqual(bopomofo(['nin']), ['ㄋㄧㄣ˙'])
     self.assertEqual(bopomofo(['lin']), ['ㄌㄧㄣ˙'])
     self.assertEqual(bopomofo(['jin']), ['ㄐㄧㄣ˙'])
     self.assertEqual(bopomofo(['qin']), ['ㄑㄧㄣ˙'])
     self.assertEqual(bopomofo(['xin']), ['ㄒㄧㄣ˙'])
     self.assertEqual(bopomofo(['yin']), ['ㄧㄣ˙'])
 def test_pinyin_syllables_you(self):
     self.assertEqual(bopomofo(['miu']), ['ㄇㄧㄡ˙'])
     self.assertEqual(bopomofo(['diu']), ['ㄉㄧㄡ˙'])
     self.assertEqual(bopomofo(['niu']), ['ㄋㄧㄡ˙'])
     self.assertEqual(bopomofo(['liu']), ['ㄌㄧㄡ˙'])
     self.assertEqual(bopomofo(['jiu']), ['ㄐㄧㄡ˙'])
     self.assertEqual(bopomofo(['qiu']), ['ㄑㄧㄡ˙'])
     self.assertEqual(bopomofo(['xiu']), ['ㄒㄧㄡ˙'])
     self.assertEqual(bopomofo(['you']), ['ㄧㄡ˙'])
 def test_pinyin_syllables_syllabic_consonant(self):
     self.assertEqual(bopomofo(['zi']), ['ㄗ˙'])
     self.assertEqual(bopomofo(['ci']), ['ㄘ˙'])
     self.assertEqual(bopomofo(['si']), ['ㄙ˙'])
     self.assertEqual(bopomofo(['zhi']), ['ㄓ˙'])
     self.assertEqual(bopomofo(['chi']), ['ㄔ˙'])
     self.assertEqual(bopomofo(['shi']), ['ㄕ˙'])
     self.assertEqual(bopomofo(['ri']), ['ㄖ˙'])
 def test_pinyin_syllables_syllabic_consonant(self):
     self.assertEqual(bopomofo(['zi']), ['ㄗ'])
     self.assertEqual(bopomofo(['ci']), ['ㄘ'])
     self.assertEqual(bopomofo(['si']), ['ㄙ'])
     self.assertEqual(bopomofo(['zhi']), ['ㄓ'])
     self.assertEqual(bopomofo(['chi']), ['ㄔ'])
     self.assertEqual(bopomofo(['shi']), ['ㄕ'])
     self.assertEqual(bopomofo(['ri']), ['ㄖ'])
 def test_pinyin_syllables_wang(self):
     self.assertEqual(bopomofo(['zhuang']), ['ㄓㄨㄤ˙'])
     self.assertEqual(bopomofo(['chuang']), ['ㄔㄨㄤ˙'])
     self.assertEqual(bopomofo(['shuang']), ['ㄕㄨㄤ˙'])
     self.assertEqual(bopomofo(['guang']), ['ㄍㄨㄤ˙'])
     self.assertEqual(bopomofo(['kuang']), ['ㄎㄨㄤ˙'])
     self.assertEqual(bopomofo(['huang']), ['ㄏㄨㄤ˙'])
     self.assertEqual(bopomofo(['wang']), ['ㄨㄤ˙'])
 def test_pinyin_syllables_wa(self):
     self.assertEqual(bopomofo(['zhua']), ['ㄓㄨㄚ˙'])
     self.assertEqual(bopomofo(['chua']), ['ㄔㄨㄚ˙'])
     self.assertEqual(bopomofo(['shua']), ['ㄕㄨㄚ˙'])
     self.assertEqual(bopomofo(['gua']), ['ㄍㄨㄚ˙'])
     self.assertEqual(bopomofo(['kua']), ['ㄎㄨㄚ˙'])
     self.assertEqual(bopomofo(['hua']), ['ㄏㄨㄚ˙'])
     self.assertEqual(bopomofo(['wa']), ['ㄨㄚ˙'])
 def test_pinyin_syllables_wai(self):
     self.assertEqual(bopomofo(['zhuai']), ['ㄓㄨㄞ˙'])
     self.assertEqual(bopomofo(['chuai']), ['ㄔㄨㄞ˙'])
     self.assertEqual(bopomofo(['shuai']), ['ㄕㄨㄞ˙'])
     self.assertEqual(bopomofo(['guai']), ['ㄍㄨㄞ˙'])
     self.assertEqual(bopomofo(['kuai']), ['ㄎㄨㄞ˙'])
     self.assertEqual(bopomofo(['huai']), ['ㄏㄨㄞ˙'])
     self.assertEqual(bopomofo(['wai']), ['ㄨㄞ˙'])
 def test_pinyin_syllables_yang(self):
     self.assertEqual(bopomofo(['niang']), ['ㄋㄧㄤ˙'])
     self.assertEqual(bopomofo(['liang']), ['ㄌㄧㄤ˙'])
     self.assertEqual(bopomofo(['jiang']), ['ㄐㄧㄤ˙'])
     self.assertEqual(bopomofo(['qiang']), ['ㄑㄧㄤ˙'])
     self.assertEqual(bopomofo(['xiang']), ['ㄒㄧㄤ˙'])
     self.assertEqual(bopomofo(['yang']), ['ㄧㄤ˙'])
 def test_pinyin_syllables_yu(self):
     self.assertEqual(bopomofo(['nü']), ['ㄋㄩ˙'])
     self.assertEqual(bopomofo(['lü']), ['ㄌㄩ˙'])
     self.assertEqual(bopomofo(['ju']), ['ㄐㄩ˙'])
     self.assertEqual(bopomofo(['qu']), ['ㄑㄩ˙'])
     self.assertEqual(bopomofo(['xu']), ['ㄒㄩ˙'])
     self.assertEqual(bopomofo(['yu']), ['ㄩ˙'])
 def test_pinyin_syllables_yue(self):
     self.assertEqual(bopomofo(['nüe']), ['ㄋㄩㄝ˙'])
     self.assertEqual(bopomofo(['lüe']), ['ㄌㄩㄝ˙'])
     self.assertEqual(bopomofo(['jue']), ['ㄐㄩㄝ˙'])
     self.assertEqual(bopomofo(['que']), ['ㄑㄩㄝ˙'])
     self.assertEqual(bopomofo(['xue']), ['ㄒㄩㄝ˙'])
     self.assertEqual(bopomofo(['yue']), ['ㄩㄝ˙'])
 def test_pinyin_syllables_wo(self):
     self.assertEqual(bopomofo(['duo']), ['ㄉㄨㄛ˙'])
     self.assertEqual(bopomofo(['tuo']), ['ㄊㄨㄛ˙'])
     self.assertEqual(bopomofo(['nuo']), ['ㄋㄨㄛ˙'])
     self.assertEqual(bopomofo(['luo']), ['ㄌㄨㄛ˙'])
     self.assertEqual(bopomofo(['zuo']), ['ㄗㄨㄛ˙'])
     self.assertEqual(bopomofo(['cuo']), ['ㄘㄨㄛ˙'])
     self.assertEqual(bopomofo(['suo']), ['ㄙㄨㄛ˙'])
     self.assertEqual(bopomofo(['zhuo']), ['ㄓㄨㄛ˙'])
     self.assertEqual(bopomofo(['chuo']), ['ㄔㄨㄛ˙'])
     self.assertEqual(bopomofo(['shuo']), ['ㄕㄨㄛ˙'])
     self.assertEqual(bopomofo(['ruo']), ['ㄖㄨㄛ˙'])
     self.assertEqual(bopomofo(['guo']), ['ㄍㄨㄛ˙'])
     self.assertEqual(bopomofo(['kuo']), ['ㄎㄨㄛ˙'])
     self.assertEqual(bopomofo(['huo']), ['ㄏㄨㄛ˙'])
     self.assertEqual(bopomofo(['wo']), ['ㄨㄛ˙'])
 def test_pinyin_syllable_weng(self):
     self.assertEqual(bopomofo(['weng']), ['ㄨㄥ˙'])
 def test_pinyin_syllables_ying(self):
     self.assertEqual(bopomofo(['bing']), ['ㄅㄧㄥ˙'])
     self.assertEqual(bopomofo(['ping']), ['ㄆㄧㄥ˙'])
     self.assertEqual(bopomofo(['ming']), ['ㄇㄧㄥ˙'])
     self.assertEqual(bopomofo(['ding']), ['ㄉㄧㄥ˙'])
     self.assertEqual(bopomofo(['ting']), ['ㄊㄧㄥ˙'])
     self.assertEqual(bopomofo(['ning']), ['ㄋㄧㄥ˙'])
     self.assertEqual(bopomofo(['ling']), ['ㄌㄧㄥ˙'])
     self.assertEqual(bopomofo(['jing']), ['ㄐㄧㄥ˙'])
     self.assertEqual(bopomofo(['qing']), ['ㄑㄧㄥ˙'])
     self.assertEqual(bopomofo(['xing']), ['ㄒㄧㄥ˙'])
     self.assertEqual(bopomofo(['ying']), ['ㄧㄥ˙'])
 def test_pinyin_syllables_a(self):
     self.assertEqual(bopomofo(['ba']), ['ㄅㄚ˙'])
     self.assertEqual(bopomofo(['pa']), ['ㄆㄚ˙'])
     self.assertEqual(bopomofo(['ma']), ['ㄇㄚ˙'])
     self.assertEqual(bopomofo(['fa']), ['ㄈㄚ˙'])
     self.assertEqual(bopomofo(['da']), ['ㄉㄚ˙'])
     self.assertEqual(bopomofo(['ta']), ['ㄊㄚ˙'])
     self.assertEqual(bopomofo(['na']), ['ㄋㄚ˙'])
     self.assertEqual(bopomofo(['la']), ['ㄌㄚ˙'])
     self.assertEqual(bopomofo(['za']), ['ㄗㄚ˙'])
     self.assertEqual(bopomofo(['ca']), ['ㄘㄚ˙'])
     self.assertEqual(bopomofo(['sa']), ['ㄙㄚ˙'])
     self.assertEqual(bopomofo(['zha']), ['ㄓㄚ˙'])
     self.assertEqual(bopomofo(['cha']), ['ㄔㄚ˙'])
     self.assertEqual(bopomofo(['sha']), ['ㄕㄚ˙'])
     self.assertEqual(bopomofo(['ga']), ['ㄍㄚ˙'])
     self.assertEqual(bopomofo(['ka']), ['ㄎㄚ˙'])
     self.assertEqual(bopomofo(['ha']), ['ㄏㄚ˙'])
     self.assertEqual(bopomofo(['a']), ['ㄚ˙'])
 def test_pinyin_syllables_wen(self):
     self.assertEqual(bopomofo(['dun']), ['ㄉㄨㄣ˙'])
     self.assertEqual(bopomofo(['tun']), ['ㄊㄨㄣ˙'])
     self.assertEqual(bopomofo(['lun']), ['ㄌㄨㄣ˙'])
     self.assertEqual(bopomofo(['zun']), ['ㄗㄨㄣ˙'])
     self.assertEqual(bopomofo(['cun']), ['ㄘㄨㄣ˙'])
     self.assertEqual(bopomofo(['sun']), ['ㄙㄨㄣ˙'])
     self.assertEqual(bopomofo(['zhun']), ['ㄓㄨㄣ˙'])
     self.assertEqual(bopomofo(['chun']), ['ㄔㄨㄣ˙'])
     self.assertEqual(bopomofo(['shun']), ['ㄕㄨㄣ˙'])
     self.assertEqual(bopomofo(['run']), ['ㄖㄨㄣ˙'])
     self.assertEqual(bopomofo(['gun']), ['ㄍㄨㄣ˙'])
     self.assertEqual(bopomofo(['kun']), ['ㄎㄨㄣ˙'])
     self.assertEqual(bopomofo(['hun']), ['ㄏㄨㄣ˙'])
     self.assertEqual(bopomofo(['wen']), ['ㄨㄣ˙'])
 def test_pinyin_syllables_wan(self):
     self.assertEqual(bopomofo(['duan']), ['ㄉㄨㄢ˙'])
     self.assertEqual(bopomofo(['tuan']), ['ㄊㄨㄢ˙'])
     self.assertEqual(bopomofo(['nuan']), ['ㄋㄨㄢ˙'])
     self.assertEqual(bopomofo(['luan']), ['ㄌㄨㄢ˙'])
     self.assertEqual(bopomofo(['zuan']), ['ㄗㄨㄢ˙'])
     self.assertEqual(bopomofo(['cuan']), ['ㄘㄨㄢ˙'])
     self.assertEqual(bopomofo(['suan']), ['ㄙㄨㄢ˙'])
     self.assertEqual(bopomofo(['zhuan']), ['ㄓㄨㄢ˙'])
     self.assertEqual(bopomofo(['chuan']), ['ㄔㄨㄢ˙'])
     self.assertEqual(bopomofo(['shuan']), ['ㄕㄨㄢ˙'])
     self.assertEqual(bopomofo(['ruan']), ['ㄖㄨㄢ˙'])
     self.assertEqual(bopomofo(['guan']), ['ㄍㄨㄢ˙'])
     self.assertEqual(bopomofo(['kuan']), ['ㄎㄨㄢ˙'])
     self.assertEqual(bopomofo(['huan']), ['ㄏㄨㄢ˙'])
     self.assertEqual(bopomofo(['wan']), ['ㄨㄢ˙'])
 def test_pinyin_syllables_yan(self):
     self.assertEqual(bopomofo(['bian']), ['ㄅㄧㄢ˙'])
     self.assertEqual(bopomofo(['pian']), ['ㄆㄧㄢ˙'])
     self.assertEqual(bopomofo(['mian']), ['ㄇㄧㄢ˙'])
     self.assertEqual(bopomofo(['dian']), ['ㄉㄧㄢ˙'])
     self.assertEqual(bopomofo(['tian']), ['ㄊㄧㄢ˙'])
     self.assertEqual(bopomofo(['nian']), ['ㄋㄧㄢ˙'])
     self.assertEqual(bopomofo(['lian']), ['ㄌㄧㄢ˙'])
     self.assertEqual(bopomofo(['jian']), ['ㄐㄧㄢ˙'])
     self.assertEqual(bopomofo(['qian']), ['ㄑㄧㄢ˙'])
     self.assertEqual(bopomofo(['xian']), ['ㄒㄧㄢ˙'])
     self.assertEqual(bopomofo(['yan']), ['ㄧㄢ˙'])
 def test_pinyin_syllables_e(self):
     self.assertEqual(bopomofo(['me']), ['ㄇㄜ˙'])
     self.assertEqual(bopomofo(['de']), ['ㄉㄜ˙'])
     self.assertEqual(bopomofo(['te']), ['ㄊㄜ˙'])
     self.assertEqual(bopomofo(['ne']), ['ㄋㄜ˙'])
     self.assertEqual(bopomofo(['le']), ['ㄌㄜ˙'])
     self.assertEqual(bopomofo(['ze']), ['ㄗㄜ˙'])
     self.assertEqual(bopomofo(['ce']), ['ㄘㄜ˙'])
     self.assertEqual(bopomofo(['se']), ['ㄙㄜ˙'])
     self.assertEqual(bopomofo(['zhe']), ['ㄓㄜ˙'])
     self.assertEqual(bopomofo(['che']), ['ㄔㄜ˙'])
     self.assertEqual(bopomofo(['she']), ['ㄕㄜ˙'])
     self.assertEqual(bopomofo(['re']), ['ㄖㄜ˙'])
     self.assertEqual(bopomofo(['ge']), ['ㄍㄜ˙'])
     self.assertEqual(bopomofo(['ke']), ['ㄎㄜ˙'])
     self.assertEqual(bopomofo(['he']), ['ㄏㄜ˙'])
     self.assertEqual(bopomofo(['e']), ['ㄜ˙'])
 def test_pinyin_syllables_yun(self):
     self.assertEqual(bopomofo(['jun']), ['ㄐㄩㄣ˙'])
     self.assertEqual(bopomofo(['qun']), ['ㄑㄩㄣ˙'])
     self.assertEqual(bopomofo(['xun']), ['ㄒㄩㄣ˙'])
     self.assertEqual(bopomofo(['yun']), ['ㄩㄣ˙'])
 def test_tone_numbers_unsegmented_separated(self):
     self.assertEqual(bopomofo(['mei2 you3']), ['ㄇㄟˊ ㄧㄡˇ'])
 def test_tone_marks_segmented(self):
     self.assertEqual(bopomofo(['zhù', 'yīn']), ['ㄓㄨˋ', 'ㄧㄣ'])
 def test_pinyin_syllables_wu(self):
     self.assertEqual(bopomofo(['bu']), ['ㄅㄨ˙'])
     self.assertEqual(bopomofo(['pu']), ['ㄆㄨ˙'])
     self.assertEqual(bopomofo(['mu']), ['ㄇㄨ˙'])
     self.assertEqual(bopomofo(['fu']), ['ㄈㄨ˙'])
     self.assertEqual(bopomofo(['du']), ['ㄉㄨ˙'])
     self.assertEqual(bopomofo(['tu']), ['ㄊㄨ˙'])
     self.assertEqual(bopomofo(['nu']), ['ㄋㄨ˙'])
     self.assertEqual(bopomofo(['lu']), ['ㄌㄨ˙'])
     self.assertEqual(bopomofo(['zu']), ['ㄗㄨ˙'])
     self.assertEqual(bopomofo(['cu']), ['ㄘㄨ˙'])
     self.assertEqual(bopomofo(['su']), ['ㄙㄨ˙'])
     self.assertEqual(bopomofo(['zhu']), ['ㄓㄨ˙'])
     self.assertEqual(bopomofo(['chu']), ['ㄔㄨ˙'])
     self.assertEqual(bopomofo(['shu']), ['ㄕㄨ˙'])
     self.assertEqual(bopomofo(['ru']), ['ㄖㄨ˙'])
     self.assertEqual(bopomofo(['gu']), ['ㄍㄨ˙'])
     self.assertEqual(bopomofo(['ku']), ['ㄎㄨ˙'])
     self.assertEqual(bopomofo(['hu']), ['ㄏㄨ˙'])
     self.assertEqual(bopomofo(['wu']), ['ㄨ˙'])
 def test_pinyin_syllables_yong(self):
     self.assertEqual(bopomofo(['jiong']), ['ㄐㄩㄥ˙'])
     self.assertEqual(bopomofo(['qiong']), ['ㄑㄩㄥ˙'])
     self.assertEqual(bopomofo(['xiong']), ['ㄒㄩㄥ˙'])
     self.assertEqual(bopomofo(['yong']), ['ㄩㄥ˙'])
 def test_pinyin_syllables_yuan(self):
     self.assertEqual(bopomofo(['juan']), ['ㄐㄩㄢ˙'])
     self.assertEqual(bopomofo(['quan']), ['ㄑㄩㄢ˙'])
     self.assertEqual(bopomofo(['xuan']), ['ㄒㄩㄢ˙'])
     self.assertEqual(bopomofo(['yuan']), ['ㄩㄢ˙'])
 def test_pinyin_syllables_yao(self):
     self.assertEqual(bopomofo(['biao']), ['ㄅㄧㄠ˙'])
     self.assertEqual(bopomofo(['piao']), ['ㄆㄧㄠ˙'])
     self.assertEqual(bopomofo(['miao']), ['ㄇㄧㄠ˙'])
     self.assertEqual(bopomofo(['diao']), ['ㄉㄧㄠ˙'])
     self.assertEqual(bopomofo(['tiao']), ['ㄊㄧㄠ˙'])
     self.assertEqual(bopomofo(['niao']), ['ㄋㄧㄠ˙'])
     self.assertEqual(bopomofo(['liao']), ['ㄌㄧㄠ˙'])
     self.assertEqual(bopomofo(['jiao']), ['ㄐㄧㄠ˙'])
     self.assertEqual(bopomofo(['qiao']), ['ㄑㄧㄠ˙'])
     self.assertEqual(bopomofo(['xiao']), ['ㄒㄧㄠ˙'])
     self.assertEqual(bopomofo(['yao']), ['ㄧㄠ˙'])
 def test_pinyin_syllables_o(self):
     self.assertEqual(bopomofo(['bo']), ['ㄅㄛ˙'])
     self.assertEqual(bopomofo(['po']), ['ㄆㄛ˙'])
     self.assertEqual(bopomofo(['mo']), ['ㄇㄛ˙'])
     self.assertEqual(bopomofo(['fo']), ['ㄈㄛ˙'])
     self.assertEqual(bopomofo(['o']), ['ㄛ˙'])
 def test_pinyin_syllables_wei(self):
     self.assertEqual(bopomofo(['dui']), ['ㄉㄨㄟ˙'])
     self.assertEqual(bopomofo(['tui']), ['ㄊㄨㄟ˙'])
     self.assertEqual(bopomofo(['zui']), ['ㄗㄨㄟ˙'])
     self.assertEqual(bopomofo(['cui']), ['ㄘㄨㄟ˙'])
     self.assertEqual(bopomofo(['sui']), ['ㄙㄨㄟ˙'])
     self.assertEqual(bopomofo(['zhui']), ['ㄓㄨㄟ˙'])
     self.assertEqual(bopomofo(['chui']), ['ㄔㄨㄟ˙'])
     self.assertEqual(bopomofo(['shui']), ['ㄕㄨㄟ˙'])
     self.assertEqual(bopomofo(['rui']), ['ㄖㄨㄟ˙'])
     self.assertEqual(bopomofo(['gui']), ['ㄍㄨㄟ˙'])
     self.assertEqual(bopomofo(['kui']), ['ㄎㄨㄟ˙'])
     self.assertEqual(bopomofo(['hui']), ['ㄏㄨㄟ˙'])
     self.assertEqual(bopomofo(['wei']), ['ㄨㄟ˙'])
 def test_tone_marks_unsegmented_joined(self):
     self.assertEqual(bopomofo(['zhùyīn']), ['ㄓㄨˋ ㄧㄣ'])
     # Regession test for Issue #81
     self.assertEqual(bopomofo(['bùyánéryù']), ['ㄅㄨˋ ㄧㄢˊ ㄦˊ ㄩˋ'])
 def test_tone_numbers_unsegmented_joined(self):
     self.assertEqual(bopomofo(['bu4yan2er2yu4']), ['ㄅㄨˋ ㄧㄢˊ ㄦˊ ㄩˋ'])