Skip to main content

Convert Jyutping romanization to Traditional Chinese characters

Project description

Jyutping2Characters

Convert Cantonese Jyutping romanization to Traditional Chinese characters.

Python 3.8+ License: MIT

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:

Credits to the authors and contributors of these projects for making this work possible.

License

MIT License

Author

James Zheng

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jyutping2characters-0.1.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jyutping2characters-0.1.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

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

Hashes for jyutping2characters-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1a08905b8a0d0df0cd5b4be2442bbf5637dc2b37e71c44077641d196b026745c
MD5 f77001be666271fd80697885498267d3
BLAKE2b-256 51a784ebd6fd541a88214cb58e0c2d162460660e3ed397b618487f774e0928c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for jyutping2characters-0.1.0.tar.gz:

Publisher: pypi-publish.yml on endernoke/jyutping2characters

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jyutping2characters-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jyutping2characters-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 affdd7a5f86b66ddee6837c6623483f585efcdaaff297596c59b0cef0145b108
MD5 35ac57ed5da395f931d4608d368d7105
BLAKE2b-256 da414f263e42c931c43c945c95e65a07f1da82e3d5573f733179970b9cc29165

See more details on using hashes here.

Provenance

The following attestation bundles were made for jyutping2characters-0.1.0-py3-none-any.whl:

Publisher: pypi-publish.yml on endernoke/jyutping2characters

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page