How to use the pypinyin.TONE 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
    [dict(style=TONE), [['zh\u014dng', 'zh\xf2ng'], ['x\u012bn']]],
    [dict(style=TONE, strict=False), [
        ['zh\u014dng', 'zh\xf2ng'], ['x\u012bn']]],
    [dict(style=TONE2), [['zho1ng', 'zho4ng'], ['xi1n']]],
    [dict(style=TONE2, strict=False), [['zho1ng', 'zho4ng'], ['xi1n']]],
    [dict(style=TONE3), [['zhong1', 'zhong4'], ['xin1']]],
    [dict(style=TONE3, strict=False), [['zhong1', 'zhong4'], ['xin1']]],
    [dict(style=INITIALS), [['zh'], ['x']]],
    [dict(style=INITIALS, strict=False), [['zh'], ['x']]],
    [dict(style=FIRST_LETTER), [['z'], ['x']]],
    [dict(style=FIRST_LETTER, strict=False), [['z'], ['x']]],
    [dict(style=FINALS), [['ong'], ['in']]],
    [dict(style=FINALS, strict=False), [['ong'], ['in']]],
    [dict(style=FINALS_TONE), [['\u014dng', '\xf2ng'], ['\u012bn']]],
    [dict(style=FINALS_TONE, strict=False),  [
        ['\u014dng', '\xf2ng'], ['\u012bn']]],
    [dict(style=FINALS_TONE2), [['o1ng', 'o4ng'], ['i1n']]],
github mozillazg / python-pinyin / tests / test_pinyin.py View on Github external
def test_pinyin_initials():
    """包含声明和韵母的词语"""
    hans = '中心'
    # 默认风格,带声调
    assert pinyin(hans) == [['zh\u014dng'], ['x\u012bn']]
    assert pinyin(hans, strict=False) == [['zh\u014dng'], ['x\u012bn']]
    # 普通风格,不带声调
    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) == [['ㄓㄨㄥ'], ['ㄒㄧㄣ']]
github mozillazg / python-pinyin / tests / test_standard.py View on Github external
['因', dict(style=NORMAL), ['yin']],
    ['因', dict(style=FINALS), ['in']],
    ['因', dict(style=FINALS, strict=False), ['in']],
    ['央', dict(style=NORMAL), ['yang']],
    ['央', dict(style=FINALS), ['iang']],
    ['央', dict(style=FINALS, strict=False), ['ang']],
    ['英', dict(style=NORMAL), ['ying']],
    ['英', dict(style=FINALS), ['ing']],
    ['英', 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']],
github mozillazg / python-pinyin / tests / test_standard.py View on Github external
['鱼', dict(style=INITIALS), ['']],
    ['鱼', dict(style=INITIALS, strict=False), ['y']],
    ['鱼', dict(style=FIRST_LETTER), ['y']],
    ['鱼', dict(style=FIRST_LETTER, strict=False), ['y']],
    ['鱼', dict(style=FINALS), ['v']],
    ['鱼', dict(style=FINALS, strict=False), ['u']],
    ['鱼', dict(style=FINALS_TONE), ['ǘ']],
    ['鱼', dict(style=FINALS_TONE, strict=False), ['ú']],
    ['鱼', dict(style=FINALS_TONE2), ['v2']],
    ['鱼', dict(style=FINALS_TONE2, strict=False), ['u2']],
    ['鱼', dict(style=FINALS_TONE3), ['v2']],
    ['鱼', dict(style=FINALS_TONE3, strict=False), ['u2']],

    ['约', dict(style=NORMAL), ['yue']],
    ['约', dict(style=NORMAL, strict=False), ['yue']],
    ['约', dict(style=TONE), ['yuē']],
    ['约', dict(style=TONE, strict=False), ['yuē']],
    ['约', dict(style=TONE2), ['yue1']],
    ['约', dict(style=TONE2, strict=False), ['yue1']],
    ['约', dict(style=TONE3), ['yue1']],
    ['约', dict(style=TONE3, strict=False), ['yue1']],
    ['约', dict(style=INITIALS), ['']],
    ['约', dict(style=INITIALS, strict=False), ['y']],
    ['约', dict(style=FIRST_LETTER), ['y']],
    ['约', dict(style=FIRST_LETTER, strict=False), ['y']],
    ['约', dict(style=FINALS), ['ve']],
    ['约', dict(style=FINALS, strict=False), ['ue']],
    ['约', dict(style=FINALS_TONE), ['üē']],
    ['约', dict(style=FINALS_TONE, strict=False), ['uē']],
    ['约', dict(style=FINALS_TONE2), ['ve1']],
    ['约', dict(style=FINALS_TONE2, strict=False), ['ue1']],
    ['约', dict(style=FINALS_TONE3), ['ve1']],
github Whoisurdady / WeChatRoomGame / game_chengyu.py View on Github external
def check_pinyin_tone_same(input, match_word):
    input_pinyin = pypinyin.pinyin(input, style=pypinyin.TONE)[0][0]
    match_word_pinyin = pypinyin.pinyin(match_word, style=pypinyin.TONE)[3][0]
    return input_pinyin == match_word_pinyin
github Whoisurdady / WeChatRoomGame / game_chengyu.py View on Github external
def check_pinyin_tone_same(input, match_word):
    input_pinyin = pypinyin.pinyin(input, style=pypinyin.TONE)[0][0]
    match_word_pinyin = pypinyin.pinyin(match_word, style=pypinyin.TONE)[3][0]
    return input_pinyin == match_word_pinyin