Skip to main content

shengyunmu-cm

汉语拼音声母、韵母、韵部提取工具,为《计算概论C》课程教学编写。

功能简介

本库提供 3 个函数和 3 个常量,可以从汉语拼音中提取声母、韵母,以及查询韵部归属。配合 xpinyin 库使用,可以完成诗句押韵判断等拼音相关的教学练习。

  • 23 个声母,支持双字母声母(zh、ch、sh)优先匹配
  • 35 个韵母,归为 15 个韵部
  • 兼容 xpinyin 库的输出格式(包括末尾的数字声调)

安装

pip install shengyunmu-cm

使用示例

提取声母

import shengyunmu_cm

shengyunmu_cm.get_shengmu('shuang')  # 'sh'
shengyunmu_cm.get_shengmu('long')    # 'l'
shengyunmu_cm.get_shengmu('an')      # None(没有声母)
shengyunmu_cm.get_shengmu('long3')   # 'l'(自动兼容数字声调)

提取韵母

shengyunmu_cm.get_yunmu('shuang')    # 'uang'
shengyunmu_cm.get_yunmu('long')      # 'ong'
shengyunmu_cm.get_yunmu('an')        # 'an'(没有声母时整个就是韵母)

查询韵部

shengyunmu_cm.get_yunbu('uang')      # 'ang韵'
shengyunmu_cm.get_yunbu('ong')       # 'ong韵'
shengyunmu_cm.get_yunbu('an')        # 'an韵'

【注意】 get_yunbu() 的参数是韵母,不是完整的拼音!如果传入 'shuang' 会返回 None。要从拼音中先用 get_yunmu() 提取韵母。

查看数据表

# 声母表(23 个,元组)
print(shengyunmu_cm.SHENGMU_TABLE)

# 韵母表(35 个,元组)
print(shengyunmu_cm.YUNMU_TABLE)

# 韵部对照字典(韵母 → 韵部名称)
print(shengyunmu_cm.YUNBU_DICT)
print(shengyunmu_cm.YUNBU_DICT['uang'])   # 'ang韵'

配合 xpinyin 使用的完整流程

import xpinyin
import shengyunmu_cm

p = xpinyin.Pinyin()

char = '龙'
pinyin = p.get_pinyin(char)                    # 'long'
shengmu = shengyunmu_cm.get_shengmu(pinyin)     # 'l'
yunmu = shengyunmu_cm.get_yunmu(pinyin)         # 'ong'
yunbu = shengyunmu_cm.get_yunbu(yunmu)          # 'ong韵'

韵部对照表

押韵只看韵腹 + 韵尾是否相同,韵头不参与判断。例如 iao(如"漂")和 ao(如"高")同属 ao 韵。

韵部 包含的韵母
a 韵 a、ia、ua
o 韵 o、uo
e 韵 e、ie、ue
i 韵 i
u 韵 u
v 韵 v
ai 韵 ai、uai
ei 韵 ei、ui
ao 韵 ao、iao
ou 韵 ou、iu
an 韵 an、ian、uan、van
en 韵 en、in、un、vn
ang 韵 ang、iang、uang
eng 韵 eng、ing、ueng
ong 韵 ong、iong

注:v 表示 ü,与 xpinyin 库的转写规则一致。

注意事项

  • 本库不支持带符号声调的拼音(如 'lóng'、'shuāng'),只支持无声调或数字声调。
  • get_yunbu() 的参数是韵母,不是完整拼音。

许可证

MIT License

Metadata

Release files for shengyunmu-cm 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shengyunmu-cm 1.0.4
File Size Uploaded Provenance Actions
shengyunmu_cm-1.0.4.tar.gz 5.3 kB Without provenance Details for shengyunmu_cm-1.0.4.tar.gz

Release files / shengyunmu_cm-1.0.4.tar.gz

Download URL shengyunmu_cm-1.0.4.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
056c6707e34c2819999d68ba32d0f0e594e42d22ba5623f9dc04b6a3454bf3ef
BLAKE2b-256 checksum
How to use checksums
089b590888e45b055f91a9b57c900d6d3f74bb2bd869e6b0e56ce4eeb96a888c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Security for shengyunmu-cm 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page