lxyu / pinyin Goto Github PK
View Code? Open in Web Editor NEWA simple python script to translate chinese to pinyin based on Mandarin.dat
Home Page: http://lxyu.github.io/pinyin
License: MIT License
A simple python script to translate chinese to pinyin based on Mandarin.dat
Home Page: http://lxyu.github.io/pinyin
License: MIT License
_compat.py 无法解码成unicode 当用CMD运行时
error“UnicodeDecodeError: 'utf8' codec can't decode byte 0xc4 in position 0: invalid continuation byte”
solution:
s = unicode(s, "utf-8") ===> s = unicode(s, "gbk")
print(pinyin.get('西藏'))
xīcáng
When trying to pip install pinyin, error occurs: UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 571: character maps to <undefined>
How to resolve this issue? Thanks
In [3]: pinyin.get(u"猎神")
Out[3]: 'xishen'
发音错了
a='沈'
pinyin.get(a)
'chen'
c=u'洁'
pinyin.get(c)
'ji'
如题。
音乐使我快乐
yin1 le4 shi3 wo3 kuai4 le4
如题。作者辛苦了
>>> pinyin.get("嗯", format="strip")
'嗯'
Is this a problem or is this designed on purpose?
夏门的'夏‘ should be 'xia'
莆田的‘莆’ should be 'pu'
Is there any way to fix it?
Thanks in advance.
Thank you for the work on this library. A big and easy improvement to its usefulness is to prominently document that it currently performs a character-level translation, which is incorrect for many common words and sentences.
>>> import pinyin
>>> pinyin.get('了解', format='numerical')
'le5jie3'
The output should be
'liao3jie3'
When converting names, we need each character to be capitalized.
e.g. 王小明 => Wang Xiao Ming, instead of wang xiao ming
应该是jing1
I think that's how mandarin.dat represents it, but it would be nice to translate that to the more common ü (obviously with the proper tone markers, as well).
Version 0.3 is producing incorrect diacritical marks:
In [3]: pinyin.get("绝")
Out[3]: 'júe'
This issue is caused by a problem in Line 41 of pinyin.py:
pinyin = pinyin[:vowel] + tonemarks[tone] + pinyin[vowel:]
Which if changed to the following:
pinyin = pinyin[:vowel] + pinyin[vowel:vowel+1] + tonemarks[tone] + pinyin[vowel+1:]
Produces correct output for more cases:
In [2]: pinyin.get("绝")
Out[2]: 'jué'
In [3]: pinyin.get("小")
Out[3]: 'xiǎo'
In [4]: pinyin.get("许")
Out[4]: 'xǔ'
However this fails with words like 操 and 被, which places marks incorrectly on the second vowel. So the maybe the following:
elif format == "diacritical":
# Find first vowel -- we should put the diacritical mark
# just after
vowels = [x for x in pinyin if x in "aeiou"]
vowel = pinyin.index(vowels[1]) if len(vowels) > 1 else pinyin.index(vowels[0])
if vowels[0] in "aeo" and len(vowels) > 1:
pinyin = pinyin[:vowel] + tonemarks[tone] + pinyin[vowel:]
else:
pinyin = pinyin[:vowel] + pinyin[vowel:vowel+1] + tonemarks[tone] + pinyin[vowel+1:]
Which produces the best-seeming output of all:
In [16]: pinyin.get("他")
Out[16]: 'tā'
In [17]: pinyin.get("绝")
Out[17]: 'jué'
In [18]: pinyin.get("小")
Out[18]: 'xiǎo'
In [19]: pinyin.get("被")
Out[19]: 'bèi'
In [4]: pinyin.get('战略')
Out[4]: 'zhànlvè'
In [13]: pinyin.get("战略", format='strip', delimiter=" ")
Out[13]: 'zhan lve'
我想得到zhan lue
我应该如何改正?
import pinyin
pinyin.get('这里不收信用卡。', delimiter=" ")
# Out[3]: 'zhè lǐ bù shōu xìn yòng qiǎ 。'
Expected output:
'zhè lǐ bù shōu xìn yòng kǎ 。'
python 3 has a function for strings ('string'.translate()) which takes a dictionary and uses it to "translate" character by character to the mapping specified in the dictionary.
Its seems to me that your code would by more pythonic if you took advantage of this
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.