How to use the pypinyin.Style.TONE2 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 / contrib / test_neutral_tone.py View on Github external
def test_neutral_tone_with_5_many_cases(input, expected_old, expected_new):
    assert lazy_pinyin(input, style=Style.TONE2) == expected_old
    assert my_pinyin.lazy_pinyin(input, style=Style.TONE2) == expected_new
github mozillazg / python-pinyin / tests / test_pinyin.py View on Github external
    ['嘸', Style.TONE2, ['m1', 'm2']],
    ['誒', Style.TONE, ['ê̄', 'ế', 'ê̌', 'ề']],
    ['誒', Style.TONE2, ['ê1', 'ê2', 'ê3', 'ê4']],
])
def test_m_e(han, style, expect):
    result = pinyin(han, style=style, heteronym=True)
    assert len(result) == 1
    assert (set(result[0]) & set(expect)) == set(expect)
github mozillazg / python-pinyin / tests / contrib / test_neutral_tone.py View on Github external
def test_neutral_tone_with_5():
    assert lazy_pinyin('好了', style=Style.TONE2) == ['ha3o', 'le']
    assert my_pinyin.lazy_pinyin('好了', style=Style.TONE2) == ['ha3o', 'le5']
    assert her_pinyin.lazy_pinyin('好了', style=Style.TONE2) == ['ha3o', 'le5']

    assert lazy_pinyin('好了') == ['hao', 'le']
    assert my_pinyin.lazy_pinyin('好了') == ['hao', 'le']
    assert her_pinyin.lazy_pinyin('好了') == ['hao', 'le']
github aoii103 / DarkNet_ChineseTrading / common.py View on Github external
def fake_datas():
    target = Faker(random.choice(faker_langs))
    names = list(
        map(random.choice, pinyin(target.name(), style=Style.TONE2, heteronym=True))
    )
    names.append(random_key(5))
    return "".join(names)
github mozillazg / python-pinyin / pypinyin / contrib / neutral_tone.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import re

from pypinyin import Style
from pypinyin.contrib._tone_rule import right_mark_index

_NUMBER_TONE = (Style.TONE2, Style.TONE3, Style.FINALS_TONE2,
                Style.FINALS_TONE3)

_re_number = re.compile(r'\d')


class NeutralToneWith5Mixin(object):
    """声调使用数字表示的相关拼音风格下的结果使用 5 标识轻声。

    使用方法::

        from pypinyin import lazy_pinyin, Style
        from pypinyin.contrib.neutral_tone import NeutralToneWith5Mixin
        from pypinyin.converter import DefaultConverter
        from pypinyin.core import Pinyin

        # 原来的结果中不会标识轻声
github mozillazg / python-pinyin / pypinyin / runner.py View on Github external
# -*- coding: utf-8 -*-

from __future__ import unicode_literals
from argparse import ArgumentParser
import logging
import sys

import pypinyin
from pypinyin.compat import PY2

style_map = {
    'NORMAL': pypinyin.Style.NORMAL,
    'zhao': pypinyin.Style.NORMAL,
    'TONE': pypinyin.Style.TONE,
    'zh4ao': pypinyin.Style.TONE,
    'TONE2': pypinyin.Style.TONE2,
    'zha4o': pypinyin.Style.TONE2,
    'TONE3': pypinyin.Style.TONE3,
    'zhao4': pypinyin.Style.TONE3,
    'INITIALS': pypinyin.Style.INITIALS,
    'zh': pypinyin.Style.INITIALS,
    'FIRST_LETTER': pypinyin.Style.FIRST_LETTER,
    'z': pypinyin.Style.FIRST_LETTER,
    'FINALS': pypinyin.Style.FINALS,
    'ao': pypinyin.Style.FINALS,
    'FINALS_TONE': pypinyin.Style.FINALS_TONE,
    '4ao': pypinyin.Style.FINALS_TONE,
    'FINALS_TONE2': pypinyin.Style.FINALS_TONE2,
    'a4o': pypinyin.Style.FINALS_TONE2,
    'FINALS_TONE3': pypinyin.Style.FINALS_TONE3,
    'ao4': pypinyin.Style.FINALS_TONE3,
    'BOPOMOFO': pypinyin.Style.BOPOMOFO,