Convert Jyutping romanization to Traditional Chinese characters
Project description
Jyutping2Characters
Convert Cantonese Jyutping romanization to Traditional Chinese characters.
Overview
Jyutping2Characters is a Python library that converts Jyutping romanization (the standard romanization system for Cantonese) into Traditional Chinese characters. It uses the Viterbi algorithm to find the most probable sequence of Chinese characters based on word frequencies from real-world data.
The project follows the Jyutping standard set by The Linguistic Society of Hong Kong Cantonese Romanization Scheme.
Installation
pip install jyutping2characters
[!WARNING] First Run Notice
On first use, this library downloads and processes mapping data from online sources (up to a minute). The data is then cached locally for instant subsequent use.
Quick Start
from jyutping2characters import transcribe
# Basic transcription
jyutping = "zou6jan4jyu4gwo2mou5mung6soeng2tung4tiu4haam4jyu2jau5me1fan1bit6" # 做人如果冇夢想同條鹹魚有咩分別
print(transcribe(jyutping)) # 我愛你
See the example/ directory for more examples.
How It Works
The transcriber uses the Viterbi algorithm to find the optimal sequence of Chinese characters. It combines data from authoritative sources to build probabilistic models based on real-world usage frequencies, then finds the character/word/phrase segmentation that maximizes total probability.
# 只 is more common than 紙
zi2 -> 只
# 不 is more common than 筆
bat1 -> 不
# but 紙筆 is a common word, occurs more often than 只 and 不 standalone
zi2bat1 -> 紙筆
# word segmentation (我愛+粵拼)
ngo5oi3jyut6ping3 -> 我愛粵拼
# let's try a long sentence
# (做人+如果+冇+夢想+同條+鹹魚+有+咩+分別)
zou6jan4jyu4gwo2mou5mung6soeng2tung4tiu4haam4jyu2jau5me1fan1bit6 -> 做人如果冇夢想同條鹹魚有咩分別
[!NOTE] As the model does not consider n-gram transitions between words, it may occasionally produce less natural results for ambiguous inputs. Future versions may incorporate more complex language models to improve accuracy.
Logging Configuration
By default, the library operates silently. To see initialization progress:
import logging
logging.basicConfig(level=logging.INFO)
from jyutping2characters import transcribe
result = transcribe("nei5hou2") # Shows loading messages
Command Line Interface
# Transcribe text
jyutping2characters transcribe "ngo5oi3nei5"
# Pre-load data for faster performance
jyutping2characters warmup
# Show system information
jyutping2characters info
Data Sources & Attribution
This project builds upon excellent open-source data from:
- LSHK Jyutping Table: Maintained by the Linguistic Society of Hong Kong, providing character-to-Jyutping mappings. (CC-BY 4.0)
- Rime Cantonese: Part of the Rime Input Method Engine project, providing word frequencies and dictionary data. (CC-BY 4.0 and ODbL 1.0)
Credits to the authors and contributors of these projects for making this work possible.
License
Author
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jyutping2characters-0.1.0.tar.gz.
File metadata
- Download URL: jyutping2characters-0.1.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a08905b8a0d0df0cd5b4be2442bbf5637dc2b37e71c44077641d196b026745c
|
|
| MD5 |
f77001be666271fd80697885498267d3
|
|
| BLAKE2b-256 |
51a784ebd6fd541a88214cb58e0c2d162460660e3ed397b618487f774e0928c2
|
Provenance
The following attestation bundles were made for jyutping2characters-0.1.0.tar.gz:
Publisher:
pypi-publish.yml on endernoke/jyutping2characters
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jyutping2characters-0.1.0.tar.gz -
Subject digest:
1a08905b8a0d0df0cd5b4be2442bbf5637dc2b37e71c44077641d196b026745c - Sigstore transparency entry: 474094638
- Sigstore integration time:
-
Permalink:
endernoke/jyutping2characters@8b4012f1556883e0ab453e3311d9fab608b26b7c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/endernoke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@8b4012f1556883e0ab453e3311d9fab608b26b7c -
Trigger Event:
release
-
Statement type:
File details
Details for the file jyutping2characters-0.1.0-py3-none-any.whl.
File metadata
- Download URL: jyutping2characters-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
affdd7a5f86b66ddee6837c6623483f585efcdaaff297596c59b0cef0145b108
|
|
| MD5 |
35ac57ed5da395f931d4608d368d7105
|
|
| BLAKE2b-256 |
da414f263e42c931c43c945c95e65a07f1da82e3d5573f733179970b9cc29165
|
Provenance
The following attestation bundles were made for jyutping2characters-0.1.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on endernoke/jyutping2characters
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jyutping2characters-0.1.0-py3-none-any.whl -
Subject digest:
affdd7a5f86b66ddee6837c6623483f585efcdaaff297596c59b0cef0145b108 - Sigstore transparency entry: 474094653
- Sigstore integration time:
-
Permalink:
endernoke/jyutping2characters@8b4012f1556883e0ab453e3311d9fab608b26b7c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/endernoke
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@8b4012f1556883e0ab453e3311d9fab608b26b7c -
Trigger Event:
release
-
Statement type: