Last active
June 11, 2021 12:29
-
-
Save mkpoli/1b572140b37e3b10eab65fda46704568 to your computer and use it in GitHub Desktop.
取得所有拼音以 ou 或 uo 結尾的入聲字
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # pip install qieyun | |
| # pip install xpinyin | |
| import Qieyun | |
| from dataclasses import dataclass | |
| from xpinyin import Pinyin | |
| p = Pinyin() | |
| @dataclass | |
| class 表示類: | |
| 字頭: str | |
| 音韻地位: Qieyun.音韻地位 | |
| def 乃入聲(self): | |
| return self.音韻地位.屬於('入聲') | |
| def 取表示集(音韻地位: Qieyun.音韻地位): | |
| return [表示類(條目.字頭, 音韻地位) for 條目 in Qieyun.音韻地位2字頭_韻書出處們(音韻地位)] | |
| 所有表示們 = [取表示集(音韻地位) for 音韻地位 in Qieyun.韻書.iter音韻地位()] | |
| 所有表示 = [表示 for 表示集 in 所有表示們 for 表示 in 表示集] | |
| 所有入聲表示 = list(filter(lambda 表示: 表示.乃入聲(), 所有表示)) | |
| def 取字頭所有拼音(字頭: str) -> list[str]: | |
| 字頭拼音們 = p.get_pinyins(字頭) | |
| if 字頭拼音們[0] == 字頭: | |
| return [] | |
| return 字頭拼音們 | |
| def 取字頭所有完整拼音(字頭: str) -> list[str]: | |
| 字頭拼音們 = p.get_pinyins(字頭, tone_marks='marks') | |
| if 字頭拼音們[0] == 字頭: | |
| return [] | |
| return 字頭拼音們 | |
| def 取字頭所有音韻地位(字頭: str) -> list[Qieyun.音韻地位]: | |
| return [表示.音韻地位 for 表示 in 所有表示 if 表示.字頭 == 字頭] | |
| def 格式化表示拼音(表示: 表示類, 拼音們: list[str], 音韻地位們: list[Qieyun.音韻地位]): | |
| return f'{表示.字頭} {" ".join(拼音們)}\n {" ".join(音韻地位.描述 for 音韻地位 in 音韻地位們)}' | |
| def 取所有以結尾(表示們, 結尾): | |
| def 乃存在並以結尾(拼音們, 結尾): | |
| return any((拼音.endswith(結尾) for 拼音 in 拼音們)) | |
| return (格式化表示拼音(表示, 取字頭所有完整拼音(表示.字頭), 取字頭所有音韻地位(表示.字頭)) for 表示 in 表示們 if 乃存在並以結尾(取字頭所有拼音(表示.字頭), 結尾)) | |
| print('以 ou 結尾入聲字') | |
| print('\n'.join(取所有以結尾(所有入聲表示, 'ou'))) | |
| print() | |
| print('以 uo 結尾入聲字') | |
| print('\n'.join(取所有以結尾(所有入聲表示, 'uo'))) | |
| # + 人工判斷 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment