contrib¶
拼音转换¶
- pypinyin.contrib.tone_convert.to_normal(pinyin, v_to_u=False)[源代码]¶
将
TONE
、TONE2
或TONE3
风格的拼音转换为NORMAL
风格的拼音Usage:
>>> from pypinyin.contrib.tone_convert import to_normal >>> to_normal('zhōng') 'zhong' >>> to_normal('zho1ng') 'zhong' >>> to_normal('zhong1') 'zhong' >>> to_normal('lüè', v_to_u=True) 'lüe'
- pypinyin.contrib.tone_convert.to_tone(pinyin)[源代码]¶
将
TONE2
或TONE3
风格的拼音转换为TONE
风格的拼音Usage:
>>> from pypinyin.contrib.tone_convert import to_tone >>> to_tone('zho1ng') 'zhōng' >>> to_tone('zhong1') 'zhōng'
- pypinyin.contrib.tone_convert.to_tone2(pinyin, v_to_u=False, neutral_tone_with_5=False)[源代码]¶
将
TONE
或TONE3
风格的拼音转换为TONE2
风格的拼音- 参数
- 返回
TONE2
风格的拼音
Usage:
>>> from pypinyin.contrib.tone_convert import to_tone2 >>> to_tone2('zhōng') 'zho1ng' >>> to_tone2('zhong1') 'zho1ng' >>> to_tone2('shang', neutral_tone_with_5=True) 'sha5ng' >>> to_tone2('lüè', v_to_u=True) 'lüe4'
- pypinyin.contrib.tone_convert.to_tone3(pinyin, v_to_u=False, neutral_tone_with_5=False)[源代码]¶
将
TONE
或TONE2
风格的拼音转换为TONE3
风格的拼音- 参数
- 返回
TONE2
风格的拼音
Usage:
>>> from pypinyin.contrib.tone_convert import to_tone3 >>> to_tone3('zhōng') 'zhong1' >>> to_tone3('zho1ng') 'zhong1' >>> to_tone3('shang', neutral_tone_with_5=True) 'shang5' >>> to_tone3('lüè', v_to_u=True) 'lüe4'
- pypinyin.contrib.tone_convert.tone_to_normal(tone, v_to_u=False)[源代码]¶
-
Usage:
>>> from pypinyin.contrib.tone_convert import tone_to_normal >>> tone_to_normal('zhōng') 'zhong' >>> tone_to_normal('lüè', v_to_u=True) 'lüe'
- pypinyin.contrib.tone_convert.tone_to_tone2(tone, v_to_u=False, neutral_tone_with_5=False)[源代码]¶
-
Usage:
>>> from pypinyin.contrib.tone_convert import tone_to_tone2 >>> tone_to_tone2('zhōng') 'zho1ng' >>> tone_to_tone2('shang', neutral_tone_with_5=True) 'sha5ng' >>> tone_to_tone2('lüè', v_to_u=True) 'lüe4'
- pypinyin.contrib.tone_convert.tone_to_tone3(tone, v_to_u=False, neutral_tone_with_5=False)[源代码]¶
-
Usage:
>>> from pypinyin.contrib.tone_convert import tone_to_tone3 >>> tone_to_tone3('zhōng') 'zhong1' >>> tone_to_tone3('shang', neutral_tone_with_5=True) 'shang5' >>> tone_to_tone3('lüè', v_to_u=True) 'lüe4'
- pypinyin.contrib.tone_convert.tone2_to_normal(tone2, v_to_u=False)[源代码]¶
-
- 参数
tone2 –
TONE2
风格的拼音v_to_u – 是否使用
ü
代替原来的v
- 返回
Style.NORMAL 风格的拼音
Usage:
>>> from pypinyin.contrib.tone_convert import tone2_to_normal >>> tone2_to_normal('zho1ng') 'zhong' >>> tone2_to_normal('lüe4', v_to_u=True) 'lüe'
- pypinyin.contrib.tone_convert.tone2_to_tone(tone2)[源代码]¶
-
- 参数
tone2 –
TONE2
风格的拼音- 返回
Style.TONE 风格的拼音
Usage:
>>> from pypinyin.contrib.tone_convert import tone2_to_tone >>> tone2_to_tone('zho1ng') 'zhōng'
- pypinyin.contrib.tone_convert.tone2_to_tone3(tone2)[源代码]¶
-
Usage:
>>> from pypinyin.contrib.tone_convert import tone2_to_tone3 >>> tone2_to_tone3('zho1ng') 'zhong1'
- pypinyin.contrib.tone_convert.tone3_to_normal(tone3, v_to_u=False)[源代码]¶
-
Usage:
>>> from pypinyin.contrib.tone_convert import tone3_to_normal >>> tone3_to_normal('zhong1') 'zhong' >>> tone3_to_normal('lüe4', v_to_u=True) 'lüe'
V2UMixin¶
- class pypinyin.contrib.uv.V2UMixin[源代码]¶
无声调相关拼音风格下的结果使用
ü
代替原来的v
使用方法:
from pypinyin import lazy_pinyin, Style from pypinyin.contrib.uv import V2UMixin from pypinyin.converter import DefaultConverter from pypinyin.core import Pinyin # 原来的结果中会使用 ``v`` 表示 ``ü`` print(lazy_pinyin('战略')) # 输出:['zhan', 'lve'] class MyConverter(V2UMixin, DefaultConverter): pass my_pinyin = Pinyin(MyConverter()) pinyin = my_pinyin.pinyin lazy_pinyin = my_pinyin.lazy_pinyin # 新的结果中使用 ``ü`` 代替原来的 ``v`` print(lazy_pinyin('战略')) # 输出: ['zhan', 'lüe'] print(pinyin('战略', style=Style.NORMAL)) # 输出:[['zhan'], ['lüe']]
NeutralToneWith5Mixin¶
- class pypinyin.contrib.neutral_tone.NeutralToneWith5Mixin[源代码]¶
声调使用数字表示的相关拼音风格下的结果使用 5 标识轻声。
使用方法:
from pypinyin import lazy_pinyin, Style from pypinyin.contrib.neutral_tone import NeutralToneWith5Mixin from pypinyin.converter import DefaultConverter from pypinyin.core import Pinyin # 原来的结果中不会标识轻声 print(lazy_pinyin('好了', style=Style.TONE2)) # 输出: ['ha3o', 'le'] class MyConverter(NeutralToneWith5Mixin, DefaultConverter): pass my_pinyin = Pinyin(MyConverter()) pinyin = my_pinyin.pinyin lazy_pinyin = my_pinyin.lazy_pinyin # 新的结果中使用 ``5`` 标识轻声 print(lazy_pinyin('好了', style=Style.TONE2)) # 输出: ['ha3o', 'le5'] print(pinyin('好了', style=Style.TONE2)) # 输出:[['ha3o'], ['le5']]