Skip to content

Commit

Permalink
修复无声母和韵母的场景下指定 neutral_tone_with_five=True 会返回 5 作为拼音的问题 #284
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Aug 15, 2022
1 parent 178ce33 commit 32e5011
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pypinyin/contrib/neutral_tone.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def post_convert_style(self, han, orig_pinyin, converted_pinyin,

if pre_data is not None:
converted_pinyin = pre_data
if not converted_pinyin: # 空字符串
return converted_pinyin
# 有声调,跳过
if _re_number.search(converted_pinyin):
return converted_pinyin
Expand Down
10 changes: 10 additions & 0 deletions tests/test_others.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from pytest import mark

from pypinyin import pinyin, Style, lazy_pinyin, slug
from pypinyin.seg.simpleseg import simple_seg

Expand Down Expand Up @@ -49,6 +51,14 @@ def test_issue_266():
assert lazy_pinyin('呣', style=Style.FINALS, strict=False) == ['m']


@mark.parametrize('neutral_tone_with_five', [True, False])
def test_issue_284(neutral_tone_with_five):
assert lazy_pinyin('嗯', style=Style.FINALS_TONE3,
neutral_tone_with_five=neutral_tone_with_five) == ['']
assert lazy_pinyin('呣', style=Style.FINALS_TONE3,
neutral_tone_with_five=neutral_tone_with_five) == ['']


if __name__ == '__main__':
import pytest
pytest.cmdline.main()

0 comments on commit 32e5011

Please sign in to comment.