How to use the pypinyin.FIRST_LETTER function in pypinyin

To help you get started, we’ve selected a few pypinyin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozillazg / python-pinyin / tests / test_pinyin.py View on Github external
['取', {'style': FINALS_TONE}, ['ǚ']],
    ['取', {'style': FINALS_TONE2}, ['v3']],
    ['取', {'style': FINALS}, ['v']],
    ['取', {'style': BOPOMOFO}, ['ㄑㄩˇ']],
    ['取', {'style': CYRILLIC}, ['цюй3']],
    ['徐', {'style': FINALS_TONE}, ['ǘ']],
    ['徐', {'style': FINALS_TONE2}, ['v2']],
    ['徐', {'style': FINALS}, ['v']],
    ['徐', {'style': BOPOMOFO}, ['ㄒㄩˊ']],
    ['徐', {'style': CYRILLIC}, ['сюй2']],
    # ń
    ['嗯', {'style': NORMAL}, ['n']],
    ['嗯', {'style': TONE}, ['ń']],
    ['嗯', {'style': TONE2}, ['n2']],
    ['嗯', {'style': INITIALS}, ['']],
    ['嗯', {'style': FIRST_LETTER}, ['n']],
    ['嗯', {'style': FINALS}, ['n']],
    ['嗯', {'style': FINALS_TONE}, ['ń']],
    ['嗯', {'style': FINALS_TONE2}, ['n2']],
    ['嗯', {'style': BOPOMOFO}, ['ㄣˊ']],
    ['嗯', {'style': CYRILLIC}, ['н2']],
    # ḿ  \u1e3f  U+1E3F
    ['呣', {'style': NORMAL}, ['m']],
    ['呣', {'style': TONE}, ['ḿ']],
    ['呣', {'style': TONE2}, ['m2']],
    ['呣', {'style': INITIALS}, ['']],
    ['呣', {'style': FIRST_LETTER}, ['m']],
    ['呣', {'style': FINALS}, ['m']],
    ['呣', {'style': FINALS_TONE}, ['ḿ']],
    ['呣', {'style': FINALS_TONE2}, ['m2']],
    ['呣', {'style': BOPOMOFO}, ['ㄇㄨˊ']],
    ['呣', {'style': CYRILLIC}, ['м2']],
github mozillazg / python-pinyin / tests / test_pinyin.py View on Github external
assert pinyin(hans, NORMAL) == [['zhong'], ['xin']]
    assert pinyin(hans, NORMAL, strict=False) == [['zhong'], ['xin']]
    # 声调风格,拼音声调在韵母第一个字母上
    assert pinyin(hans, TONE) == [['zh\u014dng'], ['x\u012bn']]
    assert pinyin(hans, TONE, strict=False) == [['zh\u014dng'], ['x\u012bn']]
    # 声调风格2,即拼音声调在各个声母之后,用数字 [1-4] 进行表示
    assert pinyin(hans, TONE2) == [['zho1ng'], ['xi1n']]
    assert pinyin(hans, TONE2, strict=False) == [['zho1ng'], ['xi1n']]
    # 声调风格3,即拼音声调在各个拼音之后,用数字 [1-4] 进行表示
    assert pinyin(hans, TONE3) == [['zhong1'], ['xin1']]
    assert pinyin(hans, TONE3, strict=False) == [['zhong1'], ['xin1']]
    # 声母风格,只返回各个拼音的声母部分
    assert pinyin(hans, INITIALS) == [['zh'], ['x']]
    assert pinyin(hans, INITIALS, strict=False) == [['zh'], ['x']]
    # 首字母风格,只返回拼音的首字母部分
    assert pinyin(hans, FIRST_LETTER) == [['z'], ['x']]
    assert pinyin(hans, FIRST_LETTER, strict=False) == [['z'], ['x']]
    # 注音风格,带声调
    assert pinyin(hans, BOPOMOFO) == [['ㄓㄨㄥ'], ['ㄒㄧㄣ']]
    assert pinyin(hans, BOPOMOFO, strict=False) == [['ㄓㄨㄥ'], ['ㄒㄧㄣ']]
    # 注音风格,首字母
    assert pinyin(hans, BOPOMOFO_FIRST) == [['ㄓ'], ['ㄒ']]
    assert pinyin(hans, BOPOMOFO_FIRST, strict=False) == [['ㄓ'], ['ㄒ']]
    # test CYRILLIC style
    assert pinyin(hans, CYRILLIC) == [['чжун1'], ['синь1']]
    assert pinyin(hans, CYRILLIC, strict=False) == [['чжун1'], ['синь1']]
    # CYRILLIC_FIRST style return only first letters
    assert pinyin(hans, CYRILLIC_FIRST) == [['ч'], ['с']]
    assert pinyin(hans, CYRILLIC_FIRST, strict=False) == [['ч'], ['с']]
    # 启用多音字模式
    assert pinyin(hans, heteronym=True) == [['zh\u014dng', 'zh\xf2ng'],
                                            ['x\u012bn']]
github mozillazg / python-pinyin / tests / test_standard.py View on Github external
['女', dict(style=FINALS_TONE2), ['v3']],
    ['女', dict(style=FINALS_TONE2, strict=False), ['v3']],
    ['女', dict(style=FINALS_TONE3), ['v3']],
    ['女', dict(style=FINALS_TONE3, strict=False), ['v3']],

    ['吕', dict(style=NORMAL), ['lv']],
    ['吕', dict(style=NORMAL, strict=False), ['lv']],
    ['吕', dict(style=TONE), ['lǚ']],
    ['吕', dict(style=TONE, strict=False), ['lǚ']],
    ['吕', dict(style=TONE2), ['lv3']],
    ['吕', dict(style=TONE2, strict=False), ['lv3']],
    ['吕', dict(style=TONE3), ['lv3']],
    ['吕', dict(style=TONE3, strict=False), ['lv3']],
    ['吕', dict(style=INITIALS), ['l']],
    ['吕', dict(style=INITIALS, strict=False), ['l']],
    ['吕', dict(style=FIRST_LETTER), ['l']],
    ['吕', dict(style=FIRST_LETTER, strict=False), ['l']],
    ['吕', dict(style=FINALS), ['v']],
    ['吕', dict(style=FINALS, strict=False), ['v']],
    ['吕', dict(style=FINALS_TONE), ['ǚ']],
    ['吕', dict(style=FINALS_TONE, strict=False), ['ǚ']],
    ['吕', dict(style=FINALS_TONE2), ['v3']],
    ['吕', dict(style=FINALS_TONE2, strict=False), ['v3']],
    ['吕', dict(style=FINALS_TONE3), ['v3']],
    ['吕', dict(style=FINALS_TONE3, strict=False), ['v3']],
]


@pytest.mark.parametrize('hans, kwargs, result', data_for_uv)
def test_uv(hans, kwargs, result):
    assert lazy_pinyin(hans, **kwargs) == result
    assert pinyin(hans, **kwargs) == [result]
github mozillazg / python-pinyin / tests / test_standard.py View on Github external
['英', dict(style=FINALS, strict=False), ['ing']],
    ['雍', dict(style=NORMAL), ['yong']],
    ['雍', dict(style=FINALS), ['iong']],
    ['雍', dict(style=FINALS, strict=False), ['ong']],

    ['宜', dict(style=NORMAL), ['yi']],
    ['宜', dict(style=NORMAL, strict=False), ['yi']],
    ['宜', dict(style=TONE), ['yí']],
    ['宜', dict(style=TONE, strict=False), ['yí']],
    ['宜', dict(style=TONE2), ['yi2']],
    ['宜', dict(style=TONE2, strict=False), ['yi2']],
    ['宜', dict(style=TONE3), ['yi2']],
    ['宜', dict(style=TONE3, strict=False), ['yi2']],
    ['宜', dict(style=INITIALS), ['']],
    ['宜', dict(style=INITIALS, strict=False), ['y']],
    ['宜', dict(style=FIRST_LETTER), ['y']],
    ['宜', dict(style=FIRST_LETTER, strict=False), ['y']],
    ['宜', dict(style=FINALS), ['i']],
    ['宜', dict(style=FINALS, strict=False), ['i']],
    ['宜', dict(style=FINALS_TONE), ['í']],
    ['宜', dict(style=FINALS_TONE, strict=False), ['í']],
    ['宜', dict(style=FINALS_TONE2), ['i2']],
    ['宜', dict(style=FINALS_TONE2, strict=False), ['i2']],
    ['宜', dict(style=FINALS_TONE3), ['i2']],
    ['宜', dict(style=FINALS_TONE3, strict=False), ['i2']],

    ['盐', dict(style=NORMAL), ['yan']],
    ['盐', dict(style=NORMAL, strict=False), ['yan']],
    ['盐', dict(style=TONE), ['yán']],
    ['盐', dict(style=TONE, strict=False), ['yán']],
    ['盐', dict(style=TONE2), ['ya2n']],
    ['盐', dict(style=TONE2, strict=False), ['ya2n']],
github Tefx / Mcx / hosts / namechecker / pinyin.py View on Github external
def checker_first_letters(name, pattern):
    initials = pypinyin.pinyin(name, style=pypinyin.FIRST_LETTER)
    return pattern.lower() in u"".join(x[0] for x in initials).lower()