python-pinyin icon indicating copy to clipboard operation
python-pinyin copied to clipboard

[接口需求] 能否增加获取全部合法拼音的接口?

Open VisualJoyce opened this issue 4 years ago • 4 comments

针对每种风格的拼音,增加相关接口,获取全部合法拼音的列表。

VisualJoyce avatar Jun 17 '21 05:06 VisualJoyce

感谢建议~

可以通过目前已有的功能实现这个需求:

  1. 获取所有有声调的拼音(通过 https://github.com/mozillazg/python-pinyin/blob/master/pypinyin/pinyin_dict.py 和 https://github.com/mozillazg/python-pinyin/blob/master/pypinyin/phrases_dict.py 获取拼音数据,或者解析 https://github.com/mozillazg/pinyin-data 和 https://github.com/mozillazg/phrase-pinyin-data 项目中包含的拼音数据)
  2. 使用 https://pypinyin.readthedocs.io/zh_CN/master/contrib.html#tone-convert 这里的转换函数得到想要的结果)

mozillazg avatar Jun 17 '21 13:06 mozillazg

感谢建议~

可以通过目前已有的功能实现这个需求:

  1. 获取所有有声调的拼音(通过 https://github.com/mozillazg/python-pinyin/blob/master/pypinyin/pinyin_dict.py 和 https://github.com/mozillazg/python-pinyin/blob/master/pypinyin/phrases_dict.py 获取拼音数据,或者解析 https://github.com/mozillazg/pinyin-data 和 https://github.com/mozillazg/phrase-pinyin-data 项目中包含的拼音数据)
  2. 使用 https://pypinyin.readthedocs.io/zh_CN/master/contrib.html#tone-convert 这里的转换函数得到想要的结果)

但是没有转换成注音风格的方法

wellhowtosay avatar Jul 08 '21 12:07 wellhowtosay

@wellhowtosay 感谢反馈。

你可以先通过下面的方法实现你的需求:

  1. 先按前面的第 1 步获取有声调拼音
  2. 然后使用 https://github.com/mozillazg/python-pinyin/blob/master/pypinyin/style/bopomofo.py 这里的 to_bopomofoto_bopomofo_first 方法转换为你需要的注音风格。

等后面有空的时候我再给 pypinyin.readthedocs.io/zh_CN/master/contrib.html#tone-convert 这里加一下单独的注音转换函数。

mozillazg avatar Jul 12 '21 15:07 mozillazg

声母 (strict=True): b, c, ch, d, f, g, h, j, k, l, m, n, p, q, r, s, sh, t, x, z, zh 声母 (strict=False): 上述声母 + w, y 韵母 (strict=False): a, ai, an, ang, ao, e, ê, ei, en, eng, er, i, ia, ian, iang, iao, ie, in, ing, iong, iu, m, n, ng, o, ong, ou, u, ua, uai, uan, uang, ue, ui, un, uo, v, ve 韵母 (strict=True): a, ai, an, ang, ao, e, ê, ei, en, eng, er, i, ia, ian, iang, iao, ie, in, ing, io, iong, iou, m, n, ng, o, ong, ou, u, ua, uai, uan, uang, uei, uen, ueng, uo, v, van, ve, vn

韵母 m 和 n 参考:https://github.com/mozillazg/python-pinyin/blob/3f832563972a6e04c1a85292ac272b936b8233ba/pypinyin/phonetic_symbol.py#L40-L46

所有有声调的拼音:pinyin.txt

感谢建议~

可以通过目前已有的功能实现这个需求:

  1. 获取所有有声调的拼音(通过 https://github.com/mozillazg/python-pinyin/blob/master/pypinyin/pinyin_dict.pyhttps://github.com/mozillazg/python-pinyin/blob/master/pypinyin/phrases_dict.py 获取拼音数据,或者解析 mozillazg/pinyin-datamozillazg/phrase-pinyin-data 项目中包含的拼音数据)
  2. 使用 pypinyin.readthedocs.io/zh_CN/master/contrib.html#tone-convert 这里的转换函数得到想要的结果)

pengzhendong avatar Apr 13 '22 08:04 pengzhendong