问题描述
我在网络上找到了诸如 http://www.chinesetopinyin.com/之类的地方将汉字转换为拼音(罗马化).有谁知道该怎么做,或者有可以解析的数据库?
I've found places on the web such as http://www.chinesetopinyin.com/ that convert Chinese characters to pinyin (romanization). Does anyone know how to do this, or have a database that can be parsed?
我正在使用C#,但实际上更希望使用数据库/平面文件.
I'm using C# but would actually prefer a database/flatfile.
推荐答案
使用 Python :
我认为Unicode数据库包含汉字的拼音罗马化,但是这些不包含在unicodedata
模块数据中.
I think that Unicode database contains pinyin romanizations for chinese characters, but these are not included in unicodedata
module data.
但是,您可以使用一些外部库,例如 cjklib ,例如:
however, you can use some external libraries, like cjklib, example:
# coding: UTF-8
import cjklib
from cjklib.characterlookup import CharacterLookup
c = u'好'
cjk = CharacterLookup('T')
readings = cjk.getReadingForCharacter(c, 'Pinyin')
for r in readings:
print r
输出:
hāo
hǎo
hào
更新
cjklib带有一个独立的cjknife
实用程序,可以提供帮助.在此处
cjklib comes with an standalone cjknife
utility, which micht help. some usage is described here
这篇关于将中文转换为拼音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!