cleverdeng / pinyin.py Goto Github PK
View Code? Open in Web Editor NEW汉字转拼音,With Python
汉字转拼音,With Python
有时候挺麻烦,建议能把word.data的加载透明化,同时只开放一个能操作的单例对象即可。
如题
def hanzi2pinyin(self, string=""):
result = []
if not isinstance(string, unicode):
string = string.decode("utf-8")
for char in string:
# 做ascII的判断
if ord(char) > 128:
key = '%X' % ord(char)
result.append(self.word_dict.get(key, char).split()[0][:-1].lower())
else:
result.append(char)
return result
def hanzi2pinyin_split(self, string="", split=""):
result = self.hanzi2pinyin(string=string)
# 去除split的判断
return split.join(result)
# 新增获取简拼(**zg)
def hanzi2jianpin(self, string=""):
result = self.hanzi2pinyin(string=string)
return
运行示例报错
>>> from pinyin import PinYin
>>> test = PinYin()
>>> test.load_word()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Users/tianyu/.virtualenvs/hpgolf/lib/python2.7/site-packages/pinyin.py", line 23, in load_word
raise IOError("NotFoundFile")
IOError: NotFoundFile
平台是:
test = PinYin()
test.load_word() # should no need to call
test.hanzi2pinyin(string='钓鱼岛是**的')
//Out:diao-yu-dao-shi-zhong-guo-de
// should get list of pinyin like ['diao', 'yu', 'dao'...]
看到了自己三年前提的pr >_<
能否加下 collaborators? 帮忙维护, 对所有pr进行review并合并, 加一些新特性等
@cleverdeng
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.