Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Mar 13, 2021
2 parents 9281888 + bed0feb commit ade6d50
Show file tree
Hide file tree
Showing 21 changed files with 735 additions and 33 deletions.
10 changes: 9 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v2.0.0
rev: v3.4.0
hooks:
- id: check-merge-conflict
- id: debug-statements
Expand All @@ -11,5 +11,13 @@ repos:
exclude: '.bumpversion.cfg'
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
exclude: 'tools|pypinyin/(phrases_dict.py|pinyin_dict.py|phonetic_symbol.py)|(docs/conf.py)'
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: 'v0.812'
# hooks:
# - id: mypy
# files: 'pypinyin/'
12 changes: 12 additions & 0 deletions .whitesource
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"scanSettings": {
"baseBranches": []
},
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure",
"displayMode": "diff"
},
"issueSettings": {
"minSeverityLevel": "LOW"
}
}
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Changelog
---------

`0.41.0`_ (2021-03-13)
++++++++++++++++++++++++

* **[New]** 新增 ``pypinyin.contrib.tone_convert`` 模块,用于
``Style.TONE`` 、 ``Style.TONE2`` 、 ``Style.TONE3`` 、 ``Style.NORMAL`` 风格的拼音之间互相转换。
详见 `文档 <https://pypinyin.readthedocs.io/zh_CN/develop/contrib.html#tone-convert>`__
* **[Improved]** 使用 `pinyin-data`_ v0.10.2 的拼音数据。


`0.40.0`_ (2020-11-22)
++++++++++++++++++++++++

Expand Down Expand Up @@ -891,3 +900,4 @@ __ https://github.com/mozillazg/python-pinyin/issues/8
.. _0.39.0: https://github.com/mozillazg/python-pinyin/compare/v0.38.1...v0.39.0
.. _0.39.1: https://github.com/mozillazg/python-pinyin/compare/v0.39.0...v0.39.1
.. _0.40.0: https://github.com/mozillazg/python-pinyin/compare/v0.39.1...v0.40.0
.. _0.41.0: https://github.com/mozillazg/python-pinyin/compare/v0.40.0...v0.41.0
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ help:
.PHONY: test
test: lint
@echo "run test"
py.test --cov pypinyin tests/
make testonly

.PHONY: testonly
testonly:
py.test --random-order --cov pypinyin tests/ pypinyin/

.PHONY: publish
publish: clean
Expand Down
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ FAQ
详见 `文档 <https://pypinyin.readthedocs.io/zh_CN/master/usage.html#custom-dict>`__ 。

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

.. code-block:: python
>>> # 使用其他分词模块分词,比如 jieba 之类,
>>> #或者基于 phrases_dict.py 里的词语数据使用其他分词算法分词
>>> words = list(jieba.cut('每股24.67美元的确定性协议'))
>>> pinyin(words)
为什么没有 y, w, yu 几个声母?
++++++++++++++++++++++++++++++++++++++++++++

Expand Down
22 changes: 22 additions & 0 deletions docs/contrib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@
contrib
========

.. _tone_convert:

拼音转换
--------

.. autofunction:: pypinyin.contrib.tone_convert.to_normal
.. autofunction:: pypinyin.contrib.tone_convert.to_tone
.. autofunction:: pypinyin.contrib.tone_convert.to_tone2
.. autofunction:: pypinyin.contrib.tone_convert.to_tone3

.. autofunction:: pypinyin.contrib.tone_convert.tone_to_normal
.. autofunction:: pypinyin.contrib.tone_convert.tone_to_tone2
.. autofunction:: pypinyin.contrib.tone_convert.tone_to_tone3

.. autofunction:: pypinyin.contrib.tone_convert.tone2_to_normal
.. autofunction:: pypinyin.contrib.tone_convert.tone2_to_tone
.. autofunction:: pypinyin.contrib.tone_convert.tone2_to_tone3

.. autofunction:: pypinyin.contrib.tone_convert.tone3_to_normal
.. autofunction:: pypinyin.contrib.tone_convert.tone3_to_tone
.. autofunction:: pypinyin.contrib.tone_convert.tone3_to_tone2


V2UMixin
---------
Expand Down
3 changes: 2 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@
Out[7]: ['ū']
当 ``strict=True`` 时根据 `《汉语拼音方案》`_ 的如下规则处理声母、在韵母相关风格下还原正确的韵母:
当 ``strict=True`` 时根据 `《汉语拼音方案》`_ 的如下规则处理声母、在韵母相关风格下还原正确的韵母
(只对只获取声母或只获取韵母相关拼音风格有效,不影响其他获取完整拼音信息的拼音风格的结果):

* 21 个声母: ``b p m f d t n l g k h j q x zh ch sh r z c s`` (**y, w 不是声母**)
* i行的韵母,前面没有声母的时候,写成yi(衣),ya(呀),ye(耶),yao(腰),you(忧),yan(烟),
Expand Down
2 changes: 1 addition & 1 deletion pinyin-data
18 changes: 9 additions & 9 deletions pypinyin/contrib/_tone_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
"""


def right_mark_index(pinyin_no_number):
def right_mark_index(pinyin_no_tone):
# 有 ɑ 不放过, 没 ɑ 找 o、e
for c in ['a', 'o', 'e']:
if c in pinyin_no_number:
return pinyin_no_number.index(c)
if c in pinyin_no_tone:
return pinyin_no_tone.index(c)

# i、u 若是连在一起,谁在后面就标谁
for c in ['iu', 'ui']:
if c in pinyin_no_number:
return pinyin_no_number.index(c) + 1
if c in pinyin_no_tone:
return pinyin_no_tone.index(c) + 1

# ɑ、o、e、i、u、ü
for c in ['i', 'u', 'v', 'ü']:
if c in pinyin_no_number:
return pinyin_no_number.index(c)
if c in pinyin_no_tone:
return pinyin_no_tone.index(c)

# n, m, ê
for c in ['n', 'm', 'ê']:
if c in pinyin_no_number:
return pinyin_no_number.index(c)
if c in pinyin_no_tone:
return pinyin_no_tone.index(c)
4 changes: 2 additions & 2 deletions pypinyin/contrib/_tone_rule.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from typing import Text
from typing import Text, Optional


def right_mark_index(pinyin_no_number: Text) -> int: ...
def right_mark_index(pinyin_no_number: Text) -> Optional[int]: ...
Loading

0 comments on commit ade6d50

Please sign in to comment.