Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Mar 2, 2014
2 parents 0dd39ca + 279233c commit 1f7619c
Show file tree
Hide file tree
Showing 21 changed files with 152,534 additions and 20,861 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -36,3 +36,5 @@ htmlcov
.mr.developer.cfg
.project
.pydevproject

tools/words.txt
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -21,4 +21,6 @@ after_script:
- "coveralls"

notifications:
email: false
email:
on_success: change
on_failure: always
9 changes: 9 additions & 0 deletions CHANGELOG.rst
@@ -1,6 +1,15 @@
Changelog
---------

0.5.0 (2014-03-01)
++++++++++++++++++

* **使用新的单字拼音库内容和格式**

| 新的格式:``{0x963F: u"ā,ē"}``
| 旧的格式:``{u'啊': u"ā,ē"}``

0.4.4 (2014-01-16)
++++++++++++++++++

Expand Down
9 changes: 9 additions & 0 deletions docs/index.rst
Expand Up @@ -175,6 +175,15 @@ API
Changelog
---------

0.5.0 (2014-03-01)
++++++++++++++++++

* **使用新的单字拼音库内容和格式**

| 新的格式:``{0x963F: u"ā,ē"}``
| 旧的格式:``{u'啊': u"ā,ē"}``

0.4.4 (2014-01-16)
++++++++++++++++++

Expand Down
18 changes: 12 additions & 6 deletions pypinyin/__init__.py
Expand Up @@ -6,7 +6,7 @@
from __future__ import unicode_literals

__title__ = 'pypinyin'
__version__ = '0.4.4'
__version__ = '0.5.0'
__author__ = 'mozillazg, 闲耘'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2014 mozillazg, 闲耘'
Expand Down Expand Up @@ -79,7 +79,7 @@
def load_single_dict(pinyin_dict):
"""载入用户自定义的单字拼音库
:param pinyin_dict: 单字拼音库。比如: ``{u"阿": u"ā,ē"}``
:param pinyin_dict: 单字拼音库。比如: ``{0x963F: u"ā,ē"}``
:type pinyin_dict: dict
"""
PINYIN_DICT.update(pinyin_dict)
Expand Down Expand Up @@ -167,9 +167,10 @@ def single_pinyin(han, style, heteronym):
:return: 返回拼音列表,多音字会有多个拼音项
:rtype: list
"""
if han not in PINYIN_DICT:
num = ord(han)
if num not in PINYIN_DICT:
return [han]
pys = PINYIN_DICT[han].split(",") # 字的拼音列表
pys = PINYIN_DICT[num].split(",") # 字的拼音列表
if not heteronym:
return [toFixed(pys[0], style)]

Expand Down Expand Up @@ -240,8 +241,13 @@ def pinyin(hans, style=TONE, heteronym=False):
pass
pys = []
for words in hans:
# 不处理非中文字符
if not re.match(r'^[\u4e00-\u9fff]+$', words):
# 初步过滤没有拼音的字符
re_hans = re.compile(r'''^(?:
[\u3400-\u4dbf] # CJK 扩展 A:[3400-4DBF]
|[\u4e00-\u9fff] # CJK 基本:[4E00-9FFF]
|[\uf900-\ufaff] # CJK 兼容:[F900-FAFF]
)+$''', re.X)
if not re_hans.match(words):
pys.append([words])
continue
if len(words) == 1:
Expand Down

0 comments on commit 1f7619c

Please sign in to comment.