zoukankan      html  css  js  c++  java
  • 汉语拼音转换工具包pypinyin

     1 #pip install pypinyin汉字转换汉语拼音
     2 from pypinyin import lazy_pinyin,TONE,TONE2,TONE3
     3 str="你知道我是谁吗?"
     4 res=lazy_pinyin(str)
     5 res1=lazy_pinyin(str,style=TONE)
     6 res2=lazy_pinyin(str,style=TONE2)
     7 res3=lazy_pinyin(str,style=TONE3)
     8 print(res)
     9 print(res1)
    10 print(res2)
    11 print(res3)
    12 
    13 # ['ni', 'zhi', 'dao', 'wo', 'shi', 'shei', 'ma', '?']
    14 # ['nǐ', 'zhī', 'dào', 'wǒ', 'shì', 'shéi', 'ma', '?']
    15 # ['ni3', 'zhi1', 'da4o', 'wo3', 'shi4', 'she2i', 'ma', '?']
    16 # ['ni3', 'zhi1', 'dao4', 'wo3', 'shi4', 'shei2', 'ma', '?']

    可应用在同音汉字模糊匹配,比如在ai领域的语音识别方向

  • 相关阅读:
    网页抓取
    基本数据结构
    小节
    顺序统计量
    线性时间排序
    快速排序
    堆排序 Heapsort
    大数运算
    趣味题,文本中洞的数量
    nginx config配置
  • 原文地址:https://www.cnblogs.com/open-yang/p/11253025.html
Copyright © 2011-2022 走看看