开发者

Python CJKLIB: no pinyin tones

开发者 https://www.devze.com 2023-04-01 10:55 出处:网络
I\'m working with CJKLIB, using the getReadingForCharacter, to convert Chinese characters into pinyin. However, is there some way

I'm working with CJKLIB, using the getReadingForCharacter, to convert Chinese characters into pinyin. However, is there some way

readings = cjk.getReadingForCharacter(c, 'Pinyin')

The problem is th开发者_高级运维at it returns pinyin with the tones on them, which I do not want. For example, I want "Beijing", not "Běijīng" - with all the tone marks.

Anyone know how I can get an output without the tones? Thanks!


The solution simply is:

>>> cjk.getReadingForCharacter(u'北', 'Pinyin', toneMarkType='none')
[u'bei']

You can read more about possible options here: http://cjklib.org/0.3/library/cjklib.reading.operator.PinyinOperator.html#cjklib.reading.operator.PinyinOperator


Maybe using a simpler lib fit your task better and faster, cjklib don't provide an API to convert chinese to pinyin without tone.

such python lib is as follows:

  • hanzi2pinyin

  • xpinyin

0

精彩评论

暂无评论...
验证码 换一张
取 消