把汉字转成拼音后可以进行深度学习分类,做内容识别
1.安装
pip install pypinyin
2.使用
from pypinyin import Style, pinyin content = pinyin('汉语拼音') print(content)
E:\python>python pinyin.py
[['hàn'], ['yǔ'], ['pīn'], ['yīn']]
设置拼音风格
普通
from pypinyin import Style, pinyin content = pinyin('汉语拼音', style=Style.NORMAL) print(content)
E:\python>python pinyin.py
[['han'], ['yu'], ['pin'], ['yin']]
首字母
from pypinyin import Style, pinyin content = pinyin('汉语拼音', style=Style.FIRST_LETTER) print(content)
E:\python>python pinyin.py
[['h'], ['y'], ['p'], ['y']]
将汉字转换为拼音并生成 slug 字符串
import pypinyin from pypinyin import Style content = pypinyin.slug('汉语拼音') print(content)
E:\python\>python pinyin.py
han-yu-pin-yin
修改分隔字符串
import pypinyin from pypinyin import Style content = pypinyin.slug('汉语拼音',separator=' ') print(content)
E:\python>python pinyin.py
han yu pin yin
更多可见