pypinyin


Namepypinyin JSON
Version 0.53.0 PyPI version JSON
download
home_pagehttps://github.com/mozillazg/python-pinyin
Summary汉字拼音转换模块/工具.
upload_time2024-09-15 08:05:49
maintainerNone
docs_urlNone
authormozillazg, 闲耘
requires_python!=3.0.*,!=3.1.*,!=3.2.*,<4,>=2.6
licenseMIT
keywords pinyin 拼音
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            汉字拼音转换工具(Python 版)
=============================

|Build| |GitHubAction| |Coverage| |Pypi version| |PyPI downloads| |DOI|


将汉字转为拼音。可以用于汉字注音、排序、检索(`Russian translation`_) 。

最初版本的代码参考了 `hotoo/pinyin <https://github.com/hotoo/pinyin>`__ 的实现。

* Documentation: https://pypinyin.readthedocs.io/
* GitHub: https://github.com/mozillazg/python-pinyin
* License: MIT license
* PyPI: https://pypi.org/project/pypinyin
* Python version: 2.7, pypy, pypy3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12

.. contents::


特性
----

* 根据词组智能匹配最正确的拼音。
* 支持多音字。
* 简单的繁体支持,注音支持,威妥玛拼音支持。
* 支持多种不同拼音/注音风格。


安装
----

.. code-block:: bash

    pip install pypinyin


使用示例
--------

.. code-block:: python

    >>> from pypinyin import pinyin, lazy_pinyin, Style
    >>> pinyin('中心')  # or pinyin(['中心']),参数值为列表时表示输入的是已分词后的数据
    [['zhōng'], ['xīn']]
    >>> pinyin('中心', heteronym=True)  # 启用多音字模式
    [['zhōng', 'zhòng'], ['xīn']]
    >>> pinyin('中心', style=Style.FIRST_LETTER)  # 设置拼音风格
    [['z'], ['x']]
    >>> pinyin('中心', style=Style.TONE2, heteronym=True)
    [['zho1ng', 'zho4ng'], ['xi1n']]
    >>> pinyin('中心', style=Style.TONE3, heteronym=True)
    [['zhong1', 'zhong4'], ['xin1']]
    >>> pinyin('中心', style=Style.BOPOMOFO)  # 注音风格
    [['ㄓㄨㄥ'], ['ㄒㄧㄣ']]
    >>> lazy_pinyin('威妥玛拼音', style=Style.WADEGILES)
    ['wei', "t'o", 'ma', "p'in", 'yin']
    >>> lazy_pinyin('中心')  # 不考虑多音字的情况
    ['zhong', 'xin']
    >>> lazy_pinyin('战略', v_to_u=True)  # 不使用 v 表示 ü
    ['zhan', 'lüe']
    # 使用 5 标识轻声
    >>> lazy_pinyin('衣裳', style=Style.TONE3, neutral_tone_with_five=True)
    ['yi1', 'shang5']
    # 变调  nǐ hǎo -> ní hǎo
    >>> lazy_pinyin('你好', style=Style.TONE2, tone_sandhi=True)
    ['ni2', 'ha3o']

**注意事项** :

* 默认情况下拼音结果不会标明哪个韵母是轻声,轻声的韵母没有声调或数字标识(可以通过参数 ``neutral_tone_with_five=True`` 开启使用 ``5`` 标识轻声 )。
* 默认情况下无声调相关拼音风格下的结果会使用 ``v`` 表示 ``ü`` (可以通过参数 ``v_to_u=True`` 开启使用 ``ü`` 代替 ``v`` )。
* 默认情况下会原样输出没有拼音的字符(自定义处理没有拼音的字符的方法见 `文档 <https://pypinyin.readthedocs.io/zh_CN/master/usage.html#handle-no-pinyin>`__ )。
* ``嗯`` 的拼音并不是大部分人以为的 ``en`` 以及存在既没有声母也没有韵母的拼音,详见下方 FAQ 中的说明。

命令行工具:

.. code-block:: console

    $ pypinyin 音乐
    yīn yuè

    $ python -m pypinyin.tools.toneconvert to-tone 'zhong4 xin1'
    zhòng xīn


文档
--------

详细文档请访问:https://pypinyin.readthedocs.io/。

项目代码开发方面的问题可以看看 `开发文档`_ 。


FAQ
---------

拼音有误?
+++++++++++++++++++++++++++++

可以通过下面的方法提高拼音准确性:

* 可以通过自定义词组拼音库或者单字拼音库的方式修正拼音结果,
  详见 `文档 <https://pypinyin.readthedocs.io/zh_CN/master/usage.html#custom-dict>`__ 。

.. code-block:: python

    >> from pypinyin import load_phrases_dict, load_single_dict

    >> load_phrases_dict({'桔子': [['jú'], ['zǐ']]})  # 增加 "桔子" 词组

    >> load_single_dict({ord('还'): 'hái,huán'})  # 调整 "还" 字的拼音顺序或覆盖默认拼音

* 也可以使用 `pypinyin-dict <https://github.com/mozillazg/pypinyin-dict>`__ 项目提供的自定义拼音库来纠正结果。

.. code-block:: python

    # 使用 phrase-pinyin-data 项目中 cc_cedict.txt 文件中的拼音数据优化结果
    >>> from pypinyin_dict.phrase_pinyin_data import cc_cedict
    >>> cc_cedict.load()

    # 使用 pinyin-data 项目中 kXHC1983.txt 文件中的拼音数据优化结果
    >>> from pypinyin_dict.pinyin_data import kxhc1983
    >>> kxhc1983.load()

* 如果是分词导致的拼音有误的话,可以先使用其他的分词模块对数据进行分词处理,
  然后将分词后的词组结果列表作为函数的参数即可:

.. code-block:: python

    >>> # 使用其他分词模块分词,比如 jieba 之类,
    >>> #或者基于 phrases_dict.py 里的词语数据使用其他分词算法分词
    >>> words = list(jieba.cut('每股24.67美元的确定性协议'))
    >>> pinyin(words)

* 如果你希望能通过训练模型的方式提高拼音准确性的话,可以看一下 `pypinyin-g2pW <https://github.com/mozillazg/pypinyin-g2pW>`__ 这个项目。


为什么没有 y, w, yu 几个声母?
++++++++++++++++++++++++++++++++++++++++++++

.. code-block:: python

    >>> from pypinyin import Style, pinyin
    >>> pinyin('下雨天', style=Style.INITIALS)
    [['x'], [''], ['t']]

因为根据 `《汉语拼音方案》 <http://www.moe.gov.cn/jyb_sjzl/ziliao/A19/195802/t19580201_186000.html>`__ ,
y,w,ü (yu) 都不是声母。

    声母风格(INITIALS)下,“雨”、“我”、“圆”等汉字返回空字符串,因为根据
    `《汉语拼音方案》 <http://www.moe.gov.cn/jyb_sjzl/ziliao/A19/195802/t19580201_186000.html>`__ ,
    y,w,ü (yu) 都不是声母,在某些特定韵母无声母时,才加上 y 或 w,而 ü 也有其特定规则。    —— @hotoo

    **如果你觉得这个给你带来了麻烦,那么也请小心一些无声母的汉字(如“啊”、“饿”、“按”、“昂”等)。
    这时候你也许需要的是首字母风格(FIRST_LETTER)**。    —— @hotoo

    参考: `hotoo/pinyin#57 <https://github.com/hotoo/pinyin/issues/57>`__,
    `#22 <https://github.com/mozillazg/python-pinyin/pull/22>`__,
    `#27 <https://github.com/mozillazg/python-pinyin/issues/27>`__,
    `#44 <https://github.com/mozillazg/python-pinyin/issues/44>`__

如果觉得这个行为不是你想要的,就是想把 y 当成声母的话,可以指定 ``strict=False`` ,
这个可能会符合你的预期:

.. code-block:: python

    >>> from pypinyin import Style, pinyin
    >>> pinyin('下雨天', style=Style.INITIALS)
    [['x'], [''], ['t']]
    >>> pinyin('下雨天', style=Style.INITIALS, strict=False)
    [['x'], ['y'], ['t']]

详见 `strict 参数的影响`_ 。

存在既没有声母也没有韵母的拼音?
+++++++++++++++++++++++++++++++++

是的,``strict=True`` 模式下存在极少数既没有声母也没有韵母的拼音。
比如下面这些拼音(来自汉字 ``嗯``、``呒``、``呣``、``唔``)::

    ń ńg ňg ǹg ň ǹ m̄ ḿ m̀

尤其需要注意的是 ``嗯`` 的所有拼音都既没有声母也没有韵母,``呣`` 的默认拼音既没有声母也没有韵母。
详见 `#109`_ `#259`_ `#284`_ 。


如何将某一风格的拼音转换为其他风格的拼音?
++++++++++++++++++++++++++++++++++++++++++++

可以通过 ``pypinyin.contrib.tone_convert`` 模块提供的辅助函数对标准拼音进行转换,得到不同风格的拼音。
比如将 ``zhōng`` 转换为 ``zhong``,或者获取拼音中的声母或韵母数据:

.. code-block:: python

    >>> from pypinyin.contrib.tone_convert import to_normal, to_tone, to_initials, to_finals
    >>> to_normal('zhōng')
    'zhong'
    >>> to_tone('zhong1')
    'zhōng'
    >>> to_initials('zhōng')
    'zh'
    >>> to_finals('zhōng')
    'ong'

更多拼音转换的辅助函数,详见 ``pypinyin.contrib.tone_convert`` 模块的
`文档 <https://pypinyin.readthedocs.io/zh_CN/master/contrib.html#tone-convert>`__ 。


如何减少内存占用?
++++++++++++++++++++

如果对拼音的准确性不是特别在意的话,可以通过设置环境变量 ``PYPINYIN_NO_PHRASES``
和 ``PYPINYIN_NO_DICT_COPY`` 来节省内存。
详见 `文档 <https://pypinyin.readthedocs.io/zh_CN/master/faq.html#no-phrases>`__


更多 FAQ 详见文档中的
`FAQ <https://pypinyin.readthedocs.io/zh_CN/master/faq.html>`__ 部分。


.. _#13 : https://github.com/mozillazg/python-pinyin/issues/113
.. _strict 参数的影响: https://pypinyin.readthedocs.io/zh_CN/master/usage.html#strict


拼音数据
---------

* 单个汉字的拼音使用 `pinyin-data`_ 的数据
* 词组的拼音使用 `phrase-pinyin-data`_ 的数据
* 声母和韵母使用 `《汉语拼音方案》 <http://www.moe.gov.cn/jyb_sjzl/ziliao/A19/195802/t19580201_186000.html>`__ 的数据


Related Projects
-----------------

* `hotoo/pinyin`__: 汉字拼音转换工具 Node.js/JavaScript 版。
* `mozillazg/go-pinyin`__: 汉字拼音转换工具 Go 版。
* `mozillazg/rust-pinyin`__: 汉字拼音转换工具 Rust 版。
* `wolfgitpr/cpp-pinyin`__: 汉字拼音转换工具 c++ 版。
* `wolfgitpr/csharp-pinyin`__: 汉字拼音转换工具 c# 版。


__ https://github.com/hotoo/pinyin
__ https://github.com/mozillazg/go-pinyin
__ https://github.com/mozillazg/rust-pinyin
__ https://github.com/wolfgitpr/cpp-pinyin
__ https://github.com/wolfgitpr/csharp-pinyin


.. |Build| image:: https://img.shields.io/circleci/project/github/mozillazg/python-pinyin/master.svg
   :target: https://circleci.com/gh/mozillazg/python-pinyin
.. |GitHubAction| image:: https://github.com/mozillazg/python-pinyin/workflows/CI/badge.svg
   :target: https://github.com/mozillazg/python-pinyin/actions
.. |Coverage| image:: https://img.shields.io/coveralls/github/mozillazg/python-pinyin/master.svg
   :target: https://coveralls.io/github/mozillazg/python-pinyin
.. |PyPI version| image:: https://img.shields.io/pypi/v/pypinyin.svg
   :target: https://pypi.org/project/pypinyin/
.. |DOI| image:: https://zenodo.org/badge/12830126.svg
   :target: https://zenodo.org/badge/latestdoi/12830126
.. |PyPI downloads| image:: https://img.shields.io/pypi/dm/pypinyin.svg
   :target: https://pypi.org/project/pypinyin/



.. _Russian translation: https://github.com/mozillazg/python-pinyin/blob/master/README_ru.rst
.. _pinyin-data: https://github.com/mozillazg/pinyin-data
.. _phrase-pinyin-data: https://github.com/mozillazg/phrase-pinyin-data
.. _开发文档: https://pypinyin.readthedocs.io/zh_CN/develop/develop.html
.. _#109: https://github.com/mozillazg/python-pinyin/issues/109
.. _#259: https://github.com/mozillazg/python-pinyin/issues/259
.. _#284: https://github.com/mozillazg/python-pinyin/issues/284



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mozillazg/python-pinyin",
    "name": "pypinyin",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,<4,>=2.6",
    "maintainer_email": null,
    "keywords": "pinyin, \u62fc\u97f3",
    "author": "mozillazg, \u95f2\u8018",
    "author_email": "mozillazg101@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b8/2d/58c9e7d0825d834fc5ac62a340640953d39a80e78cba70eb73d3bad5b4be/pypinyin-0.53.0.tar.gz",
    "platform": null,
    "description": "\u6c49\u5b57\u62fc\u97f3\u8f6c\u6362\u5de5\u5177\uff08Python \u7248\uff09\n=============================\n\n|Build| |GitHubAction| |Coverage| |Pypi version| |PyPI downloads| |DOI|\n\n\n\u5c06\u6c49\u5b57\u8f6c\u4e3a\u62fc\u97f3\u3002\u53ef\u4ee5\u7528\u4e8e\u6c49\u5b57\u6ce8\u97f3\u3001\u6392\u5e8f\u3001\u68c0\u7d22(`Russian translation`_) \u3002\n\n\u6700\u521d\u7248\u672c\u7684\u4ee3\u7801\u53c2\u8003\u4e86 `hotoo/pinyin <https://github.com/hotoo/pinyin>`__ \u7684\u5b9e\u73b0\u3002\n\n* Documentation: https://pypinyin.readthedocs.io/\n* GitHub: https://github.com/mozillazg/python-pinyin\n* License: MIT license\n* PyPI: https://pypi.org/project/pypinyin\n* Python version: 2.7, pypy, pypy3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12\n\n.. contents::\n\n\n\u7279\u6027\n----\n\n* \u6839\u636e\u8bcd\u7ec4\u667a\u80fd\u5339\u914d\u6700\u6b63\u786e\u7684\u62fc\u97f3\u3002\n* \u652f\u6301\u591a\u97f3\u5b57\u3002\n* \u7b80\u5355\u7684\u7e41\u4f53\u652f\u6301\uff0c\u6ce8\u97f3\u652f\u6301\uff0c\u5a01\u59a5\u739b\u62fc\u97f3\u652f\u6301\u3002\n* \u652f\u6301\u591a\u79cd\u4e0d\u540c\u62fc\u97f3/\u6ce8\u97f3\u98ce\u683c\u3002\n\n\n\u5b89\u88c5\n----\n\n.. code-block:: bash\n\n    pip install pypinyin\n\n\n\u4f7f\u7528\u793a\u4f8b\n--------\n\n.. code-block:: python\n\n    >>> from pypinyin import pinyin, lazy_pinyin, Style\n    >>> pinyin('\u4e2d\u5fc3')  # or pinyin(['\u4e2d\u5fc3'])\uff0c\u53c2\u6570\u503c\u4e3a\u5217\u8868\u65f6\u8868\u793a\u8f93\u5165\u7684\u662f\u5df2\u5206\u8bcd\u540e\u7684\u6570\u636e\n    [['zh\u014dng'], ['x\u012bn']]\n    >>> pinyin('\u4e2d\u5fc3', heteronym=True)  # \u542f\u7528\u591a\u97f3\u5b57\u6a21\u5f0f\n    [['zh\u014dng', 'zh\u00f2ng'], ['x\u012bn']]\n    >>> pinyin('\u4e2d\u5fc3', style=Style.FIRST_LETTER)  # \u8bbe\u7f6e\u62fc\u97f3\u98ce\u683c\n    [['z'], ['x']]\n    >>> pinyin('\u4e2d\u5fc3', style=Style.TONE2, heteronym=True)\n    [['zho1ng', 'zho4ng'], ['xi1n']]\n    >>> pinyin('\u4e2d\u5fc3', style=Style.TONE3, heteronym=True)\n    [['zhong1', 'zhong4'], ['xin1']]\n    >>> pinyin('\u4e2d\u5fc3', style=Style.BOPOMOFO)  # \u6ce8\u97f3\u98ce\u683c\n    [['\u3113\u3128\u3125'], ['\u3112\u3127\u3123']]\n    >>> lazy_pinyin('\u5a01\u59a5\u739b\u62fc\u97f3', style=Style.WADEGILES)\n    ['wei', \"t'o\", 'ma', \"p'in\", 'yin']\n    >>> lazy_pinyin('\u4e2d\u5fc3')  # \u4e0d\u8003\u8651\u591a\u97f3\u5b57\u7684\u60c5\u51b5\n    ['zhong', 'xin']\n    >>> lazy_pinyin('\u6218\u7565', v_to_u=True)  # \u4e0d\u4f7f\u7528 v \u8868\u793a \u00fc\n    ['zhan', 'l\u00fce']\n    # \u4f7f\u7528 5 \u6807\u8bc6\u8f7b\u58f0\n    >>> lazy_pinyin('\u8863\u88f3', style=Style.TONE3, neutral_tone_with_five=True)\n    ['yi1', 'shang5']\n    # \u53d8\u8c03  n\u01d0 h\u01ceo -> n\u00ed h\u01ceo\n    >>> lazy_pinyin('\u4f60\u597d', style=Style.TONE2, tone_sandhi=True)\n    ['ni2', 'ha3o']\n\n**\u6ce8\u610f\u4e8b\u9879** \uff1a\n\n* \u9ed8\u8ba4\u60c5\u51b5\u4e0b\u62fc\u97f3\u7ed3\u679c\u4e0d\u4f1a\u6807\u660e\u54ea\u4e2a\u97f5\u6bcd\u662f\u8f7b\u58f0\uff0c\u8f7b\u58f0\u7684\u97f5\u6bcd\u6ca1\u6709\u58f0\u8c03\u6216\u6570\u5b57\u6807\u8bc6\uff08\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570 ``neutral_tone_with_five=True`` \u5f00\u542f\u4f7f\u7528 ``5`` \u6807\u8bc6\u8f7b\u58f0 \uff09\u3002\n* \u9ed8\u8ba4\u60c5\u51b5\u4e0b\u65e0\u58f0\u8c03\u76f8\u5173\u62fc\u97f3\u98ce\u683c\u4e0b\u7684\u7ed3\u679c\u4f1a\u4f7f\u7528 ``v`` \u8868\u793a ``\u00fc`` \uff08\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570 ``v_to_u=True`` \u5f00\u542f\u4f7f\u7528 ``\u00fc`` \u4ee3\u66ff ``v`` \uff09\u3002\n* \u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u539f\u6837\u8f93\u51fa\u6ca1\u6709\u62fc\u97f3\u7684\u5b57\u7b26\uff08\u81ea\u5b9a\u4e49\u5904\u7406\u6ca1\u6709\u62fc\u97f3\u7684\u5b57\u7b26\u7684\u65b9\u6cd5\u89c1 `\u6587\u6863 <https://pypinyin.readthedocs.io/zh_CN/master/usage.html#handle-no-pinyin>`__ \uff09\u3002\n* ``\u55ef`` \u7684\u62fc\u97f3\u5e76\u4e0d\u662f\u5927\u90e8\u5206\u4eba\u4ee5\u4e3a\u7684 ``en`` \u4ee5\u53ca\u5b58\u5728\u65e2\u6ca1\u6709\u58f0\u6bcd\u4e5f\u6ca1\u6709\u97f5\u6bcd\u7684\u62fc\u97f3\uff0c\u8be6\u89c1\u4e0b\u65b9 FAQ \u4e2d\u7684\u8bf4\u660e\u3002\n\n\u547d\u4ee4\u884c\u5de5\u5177\uff1a\n\n.. code-block:: console\n\n    $ pypinyin \u97f3\u4e50\n    y\u012bn yu\u00e8\n\n    $ python -m pypinyin.tools.toneconvert to-tone 'zhong4 xin1'\n    zh\u00f2ng x\u012bn\n\n\n\u6587\u6863\n--------\n\n\u8be6\u7ec6\u6587\u6863\u8bf7\u8bbf\u95ee\uff1ahttps://pypinyin.readthedocs.io/\u3002\n\n\u9879\u76ee\u4ee3\u7801\u5f00\u53d1\u65b9\u9762\u7684\u95ee\u9898\u53ef\u4ee5\u770b\u770b `\u5f00\u53d1\u6587\u6863`_ \u3002\n\n\nFAQ\n---------\n\n\u62fc\u97f3\u6709\u8bef\uff1f\n+++++++++++++++++++++++++++++\n\n\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u65b9\u6cd5\u63d0\u9ad8\u62fc\u97f3\u51c6\u786e\u6027\uff1a\n\n* \u53ef\u4ee5\u901a\u8fc7\u81ea\u5b9a\u4e49\u8bcd\u7ec4\u62fc\u97f3\u5e93\u6216\u8005\u5355\u5b57\u62fc\u97f3\u5e93\u7684\u65b9\u5f0f\u4fee\u6b63\u62fc\u97f3\u7ed3\u679c\uff0c\n  \u8be6\u89c1 `\u6587\u6863 <https://pypinyin.readthedocs.io/zh_CN/master/usage.html#custom-dict>`__ \u3002\n\n.. code-block:: python\n\n    >> from pypinyin import load_phrases_dict, load_single_dict\n\n    >> load_phrases_dict({'\u6854\u5b50': [['j\u00fa'], ['z\u01d0']]})  # \u589e\u52a0 \"\u6854\u5b50\" \u8bcd\u7ec4\n\n    >> load_single_dict({ord('\u8fd8'): 'h\u00e1i,hu\u00e1n'})  # \u8c03\u6574 \"\u8fd8\" \u5b57\u7684\u62fc\u97f3\u987a\u5e8f\u6216\u8986\u76d6\u9ed8\u8ba4\u62fc\u97f3\n\n* \u4e5f\u53ef\u4ee5\u4f7f\u7528 `pypinyin-dict <https://github.com/mozillazg/pypinyin-dict>`__ \u9879\u76ee\u63d0\u4f9b\u7684\u81ea\u5b9a\u4e49\u62fc\u97f3\u5e93\u6765\u7ea0\u6b63\u7ed3\u679c\u3002\n\n.. code-block:: python\n\n    # \u4f7f\u7528 phrase-pinyin-data \u9879\u76ee\u4e2d cc_cedict.txt \u6587\u4ef6\u4e2d\u7684\u62fc\u97f3\u6570\u636e\u4f18\u5316\u7ed3\u679c\n    >>> from pypinyin_dict.phrase_pinyin_data import cc_cedict\n    >>> cc_cedict.load()\n\n    # \u4f7f\u7528 pinyin-data \u9879\u76ee\u4e2d kXHC1983.txt \u6587\u4ef6\u4e2d\u7684\u62fc\u97f3\u6570\u636e\u4f18\u5316\u7ed3\u679c\n    >>> from pypinyin_dict.pinyin_data import kxhc1983\n    >>> kxhc1983.load()\n\n* \u5982\u679c\u662f\u5206\u8bcd\u5bfc\u81f4\u7684\u62fc\u97f3\u6709\u8bef\u7684\u8bdd\uff0c\u53ef\u4ee5\u5148\u4f7f\u7528\u5176\u4ed6\u7684\u5206\u8bcd\u6a21\u5757\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u8bcd\u5904\u7406\uff0c\n  \u7136\u540e\u5c06\u5206\u8bcd\u540e\u7684\u8bcd\u7ec4\u7ed3\u679c\u5217\u8868\u4f5c\u4e3a\u51fd\u6570\u7684\u53c2\u6570\u5373\u53ef:\n\n.. code-block:: python\n\n    >>> # \u4f7f\u7528\u5176\u4ed6\u5206\u8bcd\u6a21\u5757\u5206\u8bcd\uff0c\u6bd4\u5982 jieba \u4e4b\u7c7b\uff0c\n    >>> #\u6216\u8005\u57fa\u4e8e phrases_dict.py \u91cc\u7684\u8bcd\u8bed\u6570\u636e\u4f7f\u7528\u5176\u4ed6\u5206\u8bcd\u7b97\u6cd5\u5206\u8bcd\n    >>> words = list(jieba.cut('\u6bcf\u80a124.67\u7f8e\u5143\u7684\u786e\u5b9a\u6027\u534f\u8bae'))\n    >>> pinyin(words)\n\n* \u5982\u679c\u4f60\u5e0c\u671b\u80fd\u901a\u8fc7\u8bad\u7ec3\u6a21\u578b\u7684\u65b9\u5f0f\u63d0\u9ad8\u62fc\u97f3\u51c6\u786e\u6027\u7684\u8bdd\uff0c\u53ef\u4ee5\u770b\u4e00\u4e0b `pypinyin-g2pW <https://github.com/mozillazg/pypinyin-g2pW>`__ \u8fd9\u4e2a\u9879\u76ee\u3002\n\n\n\u4e3a\u4ec0\u4e48\u6ca1\u6709 y, w, yu \u51e0\u4e2a\u58f0\u6bcd\uff1f\n++++++++++++++++++++++++++++++++++++++++++++\n\n.. code-block:: python\n\n    >>> from pypinyin import Style, pinyin\n    >>> pinyin('\u4e0b\u96e8\u5929', style=Style.INITIALS)\n    [['x'], [''], ['t']]\n\n\u56e0\u4e3a\u6839\u636e `\u300a\u6c49\u8bed\u62fc\u97f3\u65b9\u6848\u300b <http://www.moe.gov.cn/jyb_sjzl/ziliao/A19/195802/t19580201_186000.html>`__ \uff0c\ny\uff0cw\uff0c\u00fc (yu) \u90fd\u4e0d\u662f\u58f0\u6bcd\u3002\n\n    \u58f0\u6bcd\u98ce\u683c\uff08INITIALS\uff09\u4e0b\uff0c\u201c\u96e8\u201d\u3001\u201c\u6211\u201d\u3001\u201c\u5706\u201d\u7b49\u6c49\u5b57\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u6839\u636e\n    `\u300a\u6c49\u8bed\u62fc\u97f3\u65b9\u6848\u300b <http://www.moe.gov.cn/jyb_sjzl/ziliao/A19/195802/t19580201_186000.html>`__ \uff0c\n    y\uff0cw\uff0c\u00fc (yu) \u90fd\u4e0d\u662f\u58f0\u6bcd\uff0c\u5728\u67d0\u4e9b\u7279\u5b9a\u97f5\u6bcd\u65e0\u58f0\u6bcd\u65f6\uff0c\u624d\u52a0\u4e0a y \u6216 w\uff0c\u800c \u00fc \u4e5f\u6709\u5176\u7279\u5b9a\u89c4\u5219\u3002    \u2014\u2014 @hotoo\n\n    **\u5982\u679c\u4f60\u89c9\u5f97\u8fd9\u4e2a\u7ed9\u4f60\u5e26\u6765\u4e86\u9ebb\u70e6\uff0c\u90a3\u4e48\u4e5f\u8bf7\u5c0f\u5fc3\u4e00\u4e9b\u65e0\u58f0\u6bcd\u7684\u6c49\u5b57\uff08\u5982\u201c\u554a\u201d\u3001\u201c\u997f\u201d\u3001\u201c\u6309\u201d\u3001\u201c\u6602\u201d\u7b49\uff09\u3002\n    \u8fd9\u65f6\u5019\u4f60\u4e5f\u8bb8\u9700\u8981\u7684\u662f\u9996\u5b57\u6bcd\u98ce\u683c\uff08FIRST_LETTER\uff09**\u3002    \u2014\u2014 @hotoo\n\n    \u53c2\u8003: `hotoo/pinyin#57 <https://github.com/hotoo/pinyin/issues/57>`__,\n    `#22 <https://github.com/mozillazg/python-pinyin/pull/22>`__,\n    `#27 <https://github.com/mozillazg/python-pinyin/issues/27>`__,\n    `#44 <https://github.com/mozillazg/python-pinyin/issues/44>`__\n\n\u5982\u679c\u89c9\u5f97\u8fd9\u4e2a\u884c\u4e3a\u4e0d\u662f\u4f60\u60f3\u8981\u7684\uff0c\u5c31\u662f\u60f3\u628a y \u5f53\u6210\u58f0\u6bcd\u7684\u8bdd\uff0c\u53ef\u4ee5\u6307\u5b9a ``strict=False`` \uff0c\n\u8fd9\u4e2a\u53ef\u80fd\u4f1a\u7b26\u5408\u4f60\u7684\u9884\u671f\uff1a\n\n.. code-block:: python\n\n    >>> from pypinyin import Style, pinyin\n    >>> pinyin('\u4e0b\u96e8\u5929', style=Style.INITIALS)\n    [['x'], [''], ['t']]\n    >>> pinyin('\u4e0b\u96e8\u5929', style=Style.INITIALS, strict=False)\n    [['x'], ['y'], ['t']]\n\n\u8be6\u89c1 `strict \u53c2\u6570\u7684\u5f71\u54cd`_ \u3002\n\n\u5b58\u5728\u65e2\u6ca1\u6709\u58f0\u6bcd\u4e5f\u6ca1\u6709\u97f5\u6bcd\u7684\u62fc\u97f3\uff1f\n+++++++++++++++++++++++++++++++++\n\n\u662f\u7684\uff0c``strict=True`` \u6a21\u5f0f\u4e0b\u5b58\u5728\u6781\u5c11\u6570\u65e2\u6ca1\u6709\u58f0\u6bcd\u4e5f\u6ca1\u6709\u97f5\u6bcd\u7684\u62fc\u97f3\u3002\n\u6bd4\u5982\u4e0b\u9762\u8fd9\u4e9b\u62fc\u97f3\uff08\u6765\u81ea\u6c49\u5b57 ``\u55ef``\u3001``\u5452``\u3001``\u5463``\u3001``\u5514``\uff09::\n\n    \u0144 \u0144g \u0148g \u01f9g \u0148 \u01f9 m\u0304 \u1e3f m\u0300\n\n\u5c24\u5176\u9700\u8981\u6ce8\u610f\u7684\u662f ``\u55ef`` \u7684\u6240\u6709\u62fc\u97f3\u90fd\u65e2\u6ca1\u6709\u58f0\u6bcd\u4e5f\u6ca1\u6709\u97f5\u6bcd\uff0c``\u5463`` \u7684\u9ed8\u8ba4\u62fc\u97f3\u65e2\u6ca1\u6709\u58f0\u6bcd\u4e5f\u6ca1\u6709\u97f5\u6bcd\u3002\n\u8be6\u89c1 `#109`_ `#259`_ `#284`_ \u3002\n\n\n\u5982\u4f55\u5c06\u67d0\u4e00\u98ce\u683c\u7684\u62fc\u97f3\u8f6c\u6362\u4e3a\u5176\u4ed6\u98ce\u683c\u7684\u62fc\u97f3\uff1f\n++++++++++++++++++++++++++++++++++++++++++++\n\n\u53ef\u4ee5\u901a\u8fc7 ``pypinyin.contrib.tone_convert`` \u6a21\u5757\u63d0\u4f9b\u7684\u8f85\u52a9\u51fd\u6570\u5bf9\u6807\u51c6\u62fc\u97f3\u8fdb\u884c\u8f6c\u6362\uff0c\u5f97\u5230\u4e0d\u540c\u98ce\u683c\u7684\u62fc\u97f3\u3002\n\u6bd4\u5982\u5c06 ``zh\u014dng`` \u8f6c\u6362\u4e3a ``zhong``\uff0c\u6216\u8005\u83b7\u53d6\u62fc\u97f3\u4e2d\u7684\u58f0\u6bcd\u6216\u97f5\u6bcd\u6570\u636e\uff1a\n\n.. code-block:: python\n\n    >>> from pypinyin.contrib.tone_convert import to_normal, to_tone, to_initials, to_finals\n    >>> to_normal('zh\u014dng')\n    'zhong'\n    >>> to_tone('zhong1')\n    'zh\u014dng'\n    >>> to_initials('zh\u014dng')\n    'zh'\n    >>> to_finals('zh\u014dng')\n    'ong'\n\n\u66f4\u591a\u62fc\u97f3\u8f6c\u6362\u7684\u8f85\u52a9\u51fd\u6570\uff0c\u8be6\u89c1 ``pypinyin.contrib.tone_convert`` \u6a21\u5757\u7684\n`\u6587\u6863 <https://pypinyin.readthedocs.io/zh_CN/master/contrib.html#tone-convert>`__ \u3002\n\n\n\u5982\u4f55\u51cf\u5c11\u5185\u5b58\u5360\u7528\uff1f\n++++++++++++++++++++\n\n\u5982\u679c\u5bf9\u62fc\u97f3\u7684\u51c6\u786e\u6027\u4e0d\u662f\u7279\u522b\u5728\u610f\u7684\u8bdd\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf ``PYPINYIN_NO_PHRASES``\n\u548c ``PYPINYIN_NO_DICT_COPY`` \u6765\u8282\u7701\u5185\u5b58\u3002\n\u8be6\u89c1 `\u6587\u6863 <https://pypinyin.readthedocs.io/zh_CN/master/faq.html#no-phrases>`__\n\n\n\u66f4\u591a FAQ \u8be6\u89c1\u6587\u6863\u4e2d\u7684\n`FAQ <https://pypinyin.readthedocs.io/zh_CN/master/faq.html>`__ \u90e8\u5206\u3002\n\n\n.. _#13 : https://github.com/mozillazg/python-pinyin/issues/113\n.. _strict \u53c2\u6570\u7684\u5f71\u54cd: https://pypinyin.readthedocs.io/zh_CN/master/usage.html#strict\n\n\n\u62fc\u97f3\u6570\u636e\n---------\n\n* \u5355\u4e2a\u6c49\u5b57\u7684\u62fc\u97f3\u4f7f\u7528 `pinyin-data`_ \u7684\u6570\u636e\n* \u8bcd\u7ec4\u7684\u62fc\u97f3\u4f7f\u7528 `phrase-pinyin-data`_ \u7684\u6570\u636e\n* \u58f0\u6bcd\u548c\u97f5\u6bcd\u4f7f\u7528 `\u300a\u6c49\u8bed\u62fc\u97f3\u65b9\u6848\u300b <http://www.moe.gov.cn/jyb_sjzl/ziliao/A19/195802/t19580201_186000.html>`__ \u7684\u6570\u636e\n\n\nRelated Projects\n-----------------\n\n* `hotoo/pinyin`__: \u6c49\u5b57\u62fc\u97f3\u8f6c\u6362\u5de5\u5177 Node.js/JavaScript \u7248\u3002\n* `mozillazg/go-pinyin`__: \u6c49\u5b57\u62fc\u97f3\u8f6c\u6362\u5de5\u5177 Go \u7248\u3002\n* `mozillazg/rust-pinyin`__: \u6c49\u5b57\u62fc\u97f3\u8f6c\u6362\u5de5\u5177 Rust \u7248\u3002\n* `wolfgitpr/cpp-pinyin`__: \u6c49\u5b57\u62fc\u97f3\u8f6c\u6362\u5de5\u5177 c++ \u7248\u3002\n* `wolfgitpr/csharp-pinyin`__: \u6c49\u5b57\u62fc\u97f3\u8f6c\u6362\u5de5\u5177 c# \u7248\u3002\n\n\n__ https://github.com/hotoo/pinyin\n__ https://github.com/mozillazg/go-pinyin\n__ https://github.com/mozillazg/rust-pinyin\n__ https://github.com/wolfgitpr/cpp-pinyin\n__ https://github.com/wolfgitpr/csharp-pinyin\n\n\n.. |Build| image:: https://img.shields.io/circleci/project/github/mozillazg/python-pinyin/master.svg\n   :target: https://circleci.com/gh/mozillazg/python-pinyin\n.. |GitHubAction| image:: https://github.com/mozillazg/python-pinyin/workflows/CI/badge.svg\n   :target: https://github.com/mozillazg/python-pinyin/actions\n.. |Coverage| image:: https://img.shields.io/coveralls/github/mozillazg/python-pinyin/master.svg\n   :target: https://coveralls.io/github/mozillazg/python-pinyin\n.. |PyPI version| image:: https://img.shields.io/pypi/v/pypinyin.svg\n   :target: https://pypi.org/project/pypinyin/\n.. |DOI| image:: https://zenodo.org/badge/12830126.svg\n   :target: https://zenodo.org/badge/latestdoi/12830126\n.. |PyPI downloads| image:: https://img.shields.io/pypi/dm/pypinyin.svg\n   :target: https://pypi.org/project/pypinyin/\n\n\n\n.. _Russian translation: https://github.com/mozillazg/python-pinyin/blob/master/README_ru.rst\n.. _pinyin-data: https://github.com/mozillazg/pinyin-data\n.. _phrase-pinyin-data: https://github.com/mozillazg/phrase-pinyin-data\n.. _\u5f00\u53d1\u6587\u6863: https://pypinyin.readthedocs.io/zh_CN/develop/develop.html\n.. _#109: https://github.com/mozillazg/python-pinyin/issues/109\n.. _#259: https://github.com/mozillazg/python-pinyin/issues/259\n.. _#284: https://github.com/mozillazg/python-pinyin/issues/284\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\u6c49\u5b57\u62fc\u97f3\u8f6c\u6362\u6a21\u5757/\u5de5\u5177.",
    "version": "0.53.0",
    "project_urls": {
        "Documentation": "https://pypinyin.readthedocs.io/",
        "Homepage": "https://github.com/mozillazg/python-pinyin",
        "Source": "https://github.com/mozillazg/python-pinyin",
        "Tracker": "https://github.com/mozillazg/python-pinyin/issues"
    },
    "split_keywords": [
        "pinyin",
        " \u62fc\u97f3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b1afa1f9ee31b860ea55985a743b53fc06e61fe156bc1a9d64d94a81afa80470",
                "md5": "a1c1e9839390576a62a6043f158381a6",
                "sha256": "a906768919da3c31771f2c5e0e5a759214dc38d0087e15e6ff67649e03df8097"
            },
            "downloads": -1,
            "filename": "pypinyin-0.53.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a1c1e9839390576a62a6043f158381a6",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,<4,>=2.6",
            "size": 834720,
            "upload_time": "2024-09-15T08:05:47",
            "upload_time_iso_8601": "2024-09-15T08:05:47.379953Z",
            "url": "https://files.pythonhosted.org/packages/b1/af/a1f9ee31b860ea55985a743b53fc06e61fe156bc1a9d64d94a81afa80470/pypinyin-0.53.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b82d58c9e7d0825d834fc5ac62a340640953d39a80e78cba70eb73d3bad5b4be",
                "md5": "08672cdf43694a9d9f1d0d5fb2263bd5",
                "sha256": "a2d39ddc2bd31b55897bbb10d2e11a0c4d399988a97c00ad489c151afd9b106d"
            },
            "downloads": -1,
            "filename": "pypinyin-0.53.0.tar.gz",
            "has_sig": false,
            "md5_digest": "08672cdf43694a9d9f1d0d5fb2263bd5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,<4,>=2.6",
            "size": 824458,
            "upload_time": "2024-09-15T08:05:49",
            "upload_time_iso_8601": "2024-09-15T08:05:49.637053Z",
            "url": "https://files.pythonhosted.org/packages/b8/2d/58c9e7d0825d834fc5ac62a340640953d39a80e78cba70eb73d3bad5b4be/pypinyin-0.53.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-15 08:05:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mozillazg",
    "github_project": "python-pinyin",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "circle": true,
    "tox": true,
    "lcname": "pypinyin"
}
        
Elapsed time: 0.30531s