Python-Zhuyin (pyzhuyin) 注音和拼音轉換
Introduction 介紹
pyzhuyin is an open source Python library that provides a unified interface for converting between Chinese pinyin and Zhuyin (bopomofo).
pyzhuyin 是一個開放原始碼的 Python 套件,提供了將拼音轉換成注音的統一介面。
Installation 安裝
pip install pyzhuyin
Usage 使用
from pyzhuyin import pinyin_to_zhuyin, zhuyin_to_pinyin
assert(pinyin_to_zhuyin("lu3") == "ㄌㄨˇ")
assert(pinyin_to_zhuyin("dan4") == "ㄉㄢˋ")
assert(map(pinyin_to_zhuyin, ["lu3", "dan4"]) == ["ㄌㄨˇ", "ㄉㄢˋ"])
assert(zhuyin_to_pinyin("ㄌㄩˊ") == "lü2")
assert(zhuyin_to_pinyin("˙ㄗ") == "zi5")
assert(map(lambda z: zhuyin_to_pinyin(z, u_to_v=True), ["ㄌㄩˊ", "˙ㄗ"]) == ["lv2", "zi5"])
Testing 測試
Run the following command at the root of the project to test the library:
在根目錄執行以下指令以測試套件:
python3 -m unittest
Notes 備註
- Only support numeric tone for pinyin
- e.g. "lu3" instead of "lǔ"
- Neutral tone is represented as 5
- e.g. "˙ㄗ" -> "zi5"
- For pinyin_to_zhuyin:
- if corresponding zhuyin not found, raise ValueError
- internally convert all v to ü
- For zhuyin_to_pinyin:
- if corresponding pinyin not found, raise ValueError
- 兒化音 is not supported because it is not representable in the zhuyin system as a "combo" word
- e.g. "公園兒" -> "gong1 yuanr2" -> "ㄍㄨㄥ ㄩㄢㄦˊ" (not allowed)
Data Sources 資料來源
-
中華民國教育部(Ministry of Education, R.O.C.)。《重編國語辭典修訂本》(版本編號:2015_20210928 )
Author 作者
- Raymond Ku
Release files for pyzhuyin 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyzhuyin-0.0.3.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyzhuyin-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.8 kB
Release files / pyzhuyin-0.0.3.tar.gz
| Download URL | pyzhuyin-0.0.3.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4bcc61b79052663fe0da7cb8ecdfe43c4b7488418b1dff4cac38449df88811d4
|
|
BLAKE2b-256 checksum How to use checksums |
baeb4b01b26040930eeea319b1eed335a7b8e6d8fabb441d294351aa4f412c66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|
Release files / pyzhuyin-0.0.3-py3-none-any.whl
| Download URL | pyzhuyin-0.0.3-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e1e5f60e6f4ccdb0c10113aeda9be0d53c43a4a5d7c8306203424d94f80577c
|
|
BLAKE2b-256 checksum How to use checksums |
b9f94f100f78f58cd95f5d2eb14aab9b9dce8ffe177e432a6f1020c665372a1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|