Skip to content

Commit

Permalink
v0.1.3: custom pinyin dict
Browse files Browse the repository at this point in the history
  • Loading branch information
letiantian committed Oct 1, 2016
1 parent 4f54ec1 commit d0cda92
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
11 changes: 11 additions & 0 deletions ChineseTone/chinesetone.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,17 @@ def __middle(s, pinyinFormat, replace):
result += __middle(item, pinyinFormat, replace)
return result

@staticmethod
def addWordPinyin(w, pinyinList):
''' 添加自定义的单词的拼音,若已有则替换 '''
PinyinHelper.loadTable()
PinyinHelper.WORD_PINYIN_TABLE[w] = pinyinList

@staticmethod
def addCharPinyin(c, pinyinList):
''' 添加自定义的字符的拼音,若已有则替换 '''
PinyinHelper.loadTable()
PinyinHelper.PINYIN_TABLE[c] = pinyinList

@staticmethod
def hasMultiPinyin(c):
Expand Down
15 changes: 15 additions & 0 deletions example/example06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# coding: utf-8

from __future__ import (print_function, unicode_literals)

from ChineseTone import *

print(','.join(PinyinHelper.convertToPinyinFromSentence('金馆长啊', pinyinFormat=PinyinFormat.WITHOUT_TONE)))
PinyinHelper.addWordPinyin('金馆长', ['jin', 'guan', 'zhang']) # 建议实际情况下拼音中加入声调
print(','.join(PinyinHelper.convertToPinyinFromSentence('金馆长啊', pinyinFormat=PinyinFormat.WITHOUT_TONE)))

print(','.join(PinyinHelper.convertToPinyinFromSentence('价值40$', pinyinFormat=PinyinFormat.WITHOUT_TONE)))
PinyinHelper.addCharPinyin('4', ['si']) # 考虑多音字,所以用list
PinyinHelper.addCharPinyin('0', ['ling'])
PinyinHelper.addWordPinyin('$', ['mei', 'yuan']) # 这个用法奇怪些
print(','.join(PinyinHelper.convertToPinyinFromSentence('价值40$', pinyinFormat=PinyinFormat.WITHOUT_TONE)))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name='ChineseTone',
version='0.1.2',
version='0.1.3',
description='汉字转换为拼音,支持多音字',
long_description=LONGDOC,
author='Letian Sun',
Expand Down

0 comments on commit d0cda92

Please sign in to comment.