Skip to content

Commit

Permalink
add more info
Browse files Browse the repository at this point in the history
  • Loading branch information
letiantian committed Oct 1, 2016
1 parent d0cda92 commit 3ba8257
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ print PinyinHelper.convertToPinyinFromSentence('提出了解决方案', pinyinFo
# 输出:[u'ti', u'chu', u'le', u'jie', u'jue', u'fang', u'an']
```

#### 添加自己的词库
```python
from ChineseTone import *

print ','.join(PinyinHelper.convertToPinyinFromSentence('金馆长啊', pinyinFormat=PinyinFormat.WITHOUT_TONE))
# 输出有错: jin,guan,chang,a

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

# 也可以自定义某个字符的读音
print ','.join(PinyinHelper.convertToPinyinFromSentence('价值40$', pinyinFormat=PinyinFormat.WITHOUT_TONE))
# 输出: jia,zhi,4,0,$
# 自定义
PinyinHelper.addCharPinyin('4', ['si']) # 考虑多音字,所以用list
PinyinHelper.addCharPinyin('0', ['ling'])
PinyinHelper.addWordPinyin('$', ['mei', 'yuan']) # 这个用法奇怪些
print ','.join(PinyinHelper.convertToPinyinFromSentence('价值40$', pinyinFormat=PinyinFormat.WITHOUT_TONE))
# 输出: jia,zhi,si,ling,mei,yuan
```

#### 获取某汉字的所有拼音
```python
print PinyinHelper.convertToPinyinFromChar('')
Expand Down

0 comments on commit 3ba8257

Please sign in to comment.