Skip to content

C++版本汉字转拼音 Chinese character to pinyin #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Shellbye opened this issue Aug 31, 2018 · 1 comment
Open

C++版本汉字转拼音 Chinese character to pinyin #31

Shellbye opened this issue Aug 31, 2018 · 1 comment
Labels

Comments

@Shellbye
Copy link
Owner

开始接触C++,才更加发现了Python第三方库之多,多到写Python几乎就是不停的找库,经验丰富的人知道有哪些库,而新手则只能冒着bug百出的风险自己动手DIY。项目需要一个把汉字转成带音调的功能,本以为随手就是,结果调研好久都没有发现合适的第三方项目,倒是发现了不错的Python项目(python-pinyin),无奈之下,只得照着python-pinyin的核心代码进行了部分C++化,好在这个功能如果只是简单用用,还算比较简单,大致分为以下几步。

1. 拆分输入

就是就是把输入的语句拆分成一个个汉字,可以参考我之前写的 #27 ,也是给予前人的东西自己学习了一下。

2. 汉字转code point

找到汉字对应的code point,参考我之前写的 #25

3. 查找拼音

项目中包含了一个很大的map,这是整个项目的核心,找到code point之后就是在这个map里面找拼音了。在python-pinyin中,还对多音字进行了判断和处理,这部分我就没搞了,遇到多音字直接去第一个就是了(^_^)。

4. 后处理

python-pinyin中,还可以按照不同的需求对输出就行各种各样的定制化输出,因为我这个比较简单,所以只是一种固定的输出格式(语音 ==> yu4 yin1 .)。

整个项目没啥特别复杂的技术,正好适合我学习C++和cmake,地址在这里:hanzi2pinyin

@madosma
Copy link

madosma commented Dec 20, 2021

你好,我想问您一个问题。pypinyin目前是应用词组实现分词的,应该怎么实现呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants