From 83bc3478a9a9db64b618904b3c8a1ee9c09e6cea Mon Sep 17 00:00:00 2001 From: Tim Gates Date: Sat, 30 Jul 2022 12:45:38 +1000 Subject: [PATCH 1/3] docs: Fix a few typos (#283) There are small typos in: - README_en.rst Fixes: - Should read `occurrences` rather than `occurences`. - Should read `character` rather than `charachter`. Signed-off-by: Tim Gates --- README_en.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README_en.rst b/README_en.rst index 7e81157..96652bd 100644 --- a/README_en.rst +++ b/README_en.rst @@ -20,7 +20,7 @@ Based on `hotoo/pinyin `__ Characteristics ---- -* Finds the most fitting pinyin based on phrase occurences. +* Finds the most fitting pinyin based on phrase occurrences. * Has support for characters with two or more readings (heteronyms). * Has support for simplified, traditional characters, and zhuyin (also known als bopomofo). * Has support for multiple styles of pinyin and zhuyin (e.g. tone conventions). @@ -155,7 +155,7 @@ For more FAQ: Pinyin data --------- -* Single charachter pinyin usage `pinyin-data`_ data +* Single character pinyin usage `pinyin-data`_ data * Pinyin usage in phrases `phrase-pinyin-data`_ data From 32222f2fd0416895b9c287793153e0765f1db1d5 Mon Sep 17 00:00:00 2001 From: mozillazg Date: Sat, 30 Jul 2022 11:30:23 +0800 Subject: [PATCH 2/3] backport _replace_tone2_style_dict_to_default from old version --- pypinyin/utils.py | 6 ++++++ pypinyin/utils.pyi | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/pypinyin/utils.py b/pypinyin/utils.py index e7e3612..a3e3f30 100644 --- a/pypinyin/utils.py +++ b/pypinyin/utils.py @@ -4,6 +4,12 @@ # 用于向后兼容,TODO: 废弃 from pypinyin.seg.simpleseg import simple_seg # noqa +from pypinyin.style._tone_convert import tone2_to_tone + + +# 用于向后兼容,TODO: 废弃 +def _replace_tone2_style_dict_to_default(string): + return tone2_to_tone(string) def _remove_dup_items(lst, remove_empty=False): diff --git a/pypinyin/utils.pyi b/pypinyin/utils.pyi index a7f8ddf..a6b2efc 100644 --- a/pypinyin/utils.pyi +++ b/pypinyin/utils.pyi @@ -1,5 +1,9 @@ from typing import List, Text + +def _replace_tone2_style_dict_to_default(string: Text) -> Text: ... + + def _remove_dup_items(lst: List[Text]) -> List[Text]: ... From 0a59df939f74bfc84b5794fdd5e9e02b046ec07a Mon Sep 17 00:00:00 2001 From: mozillazg Date: Sat, 30 Jul 2022 11:31:16 +0800 Subject: [PATCH 3/3] improve tests --- README_en.rst | 4 ++-- tests/contrib/test_tone_sandhi.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README_en.rst b/README_en.rst index 96652bd..7e81157 100644 --- a/README_en.rst +++ b/README_en.rst @@ -20,7 +20,7 @@ Based on `hotoo/pinyin `__ Characteristics ---- -* Finds the most fitting pinyin based on phrase occurrences. +* Finds the most fitting pinyin based on phrase occurences. * Has support for characters with two or more readings (heteronyms). * Has support for simplified, traditional characters, and zhuyin (also known als bopomofo). * Has support for multiple styles of pinyin and zhuyin (e.g. tone conventions). @@ -155,7 +155,7 @@ For more FAQ: Pinyin data --------- -* Single character pinyin usage `pinyin-data`_ data +* Single charachter pinyin usage `pinyin-data`_ data * Pinyin usage in phrases `phrase-pinyin-data`_ data diff --git a/tests/contrib/test_tone_sandhi.py b/tests/contrib/test_tone_sandhi.py index 2aaa9b7..fe103f0 100644 --- a/tests/contrib/test_tone_sandhi.py +++ b/tests/contrib/test_tone_sandhi.py @@ -50,10 +50,16 @@ class MyConverter(ToneSandhiMixin, DefaultConverter): # 不满足变调条件 [['之一'], ['zhi1', 'yi1'], ['zhi1', 'yi1']], [['一'], ['yi1'], ['yi1']], + + # #270 + [['永远'], ['yo3ng', 'yua3n'], ['yo2ng', 'yua3n']], + [['两手'], ['lia3ng', 'sho3u'], ['lia2ng', 'sho3u']], + [['辗转反侧'], ['zha3n', 'zhua3n', 'fa3n', 'ce4'], + ['zha3n', 'zhua3n', 'fa3n', 'ce4']], ]) def test_tone_sandhi(han, normal_output, sandhi_output): assert lazy_pinyin(han, style=Style.TONE2) == normal_output or \ - lazy_pinyin(han, style=Style.TONE2) == sandhi_output + lazy_pinyin(han, style=Style.TONE2) == sandhi_output assert my_pinyin.lazy_pinyin(han, style=Style.TONE2) == sandhi_output # 测试关键字参数