learn-teochew / parsetc

Parse and convert between different Teochew romanization systems
https://learn-teochew.github.io/parsetc/
MIT License
0 stars 1 forks source link
natural-language parsing romanization teochew

Parsing and conversion of Teochew Chinese romanizations

PyPI version shields.io GitHub License

Parse and convert between different Teochew romanized spelling schemes.

parsetc represents romanization schemes as context-free grammars, and implements parsers and translators using the lark Python library. The aim is to represent romanized text as an abstract parse tree representing the phonology, which can then be converted to other romanization schemes in a consistent, rule-based way.

Available romanization schemes for Teochew

Input

Output

gdpi, ggnn, tlo, duffus, dieghv, plus:

Other languages

This tool was originally developed for Teochew, but can be extended in the future to other dialects or languages. An experimental Cantonese module (--language Cantonese) with Jyutping (jp) and Cantonese Pinyin (cpy) is available.

Orthographic requirements for input text

Installation

parsetc requires Python 3 and lark v1.1.

Install latest release with pip from PyPI:

pip install parsetc

If you are interested in latest development version, you can clone this repository and checkout the dev branch, then install with pip from source code:

pip install .

See help message:

parsetc --help

View available input and output schemes for Teochew:

parsetc --language Teochew --show_options

Usage

Command line tool

Input text is read line-by-line from STDIN. Output is written to STDOUT.

The language (--language or -l) is Teochew by default.

# Convert to Tie-lo
echo 'ua2 ain3 oh8 diê5ghe2, ain3 dan3 diê5ziu1 uê7.' | parsetc -i gdpi -o tlo
# Convert to all available output romanizations
echo 'ua2 ain3 oh8 diê5ghe2, ain3 dan3 diê5ziu1 uê7.' | parsetc -i gdpi --all
# Show parse tree (useful for debugging)
echo 'ua2 ain3 oh8 diê5ghe2, ain3 dan3 diê5ziu1 uê7.' | parsetc -i gdpi -p

Testing with sample texts in the examples/ folder:

# Example with tone numbers but no syllable separators
cat examples/teochew.dieghv.tones.txt | parsetc -i dieghv --all
# Example with hyphens as syllable separators
cat examples/teochew.dieghv.sep.txt | parsetc -i dieghv --all

Try a Cantonese example (work in progress):

echo "ceon1 min4 bat1 gok3 hiu2" | parsetc -l Cantonese -i jp --all
cat examples/cantonese.cpy.txt | parsetc -l Cantonese -i cpy --all

Python module

Common functions and command line script are in the parsetc.parsetc submodule. Each language has a dedicated subpackage with the following structure (using Teochew as an example):

src/parsetc/Teochew/
├── shared.lark     # lark grammar for shared parser rules
├── extends.json    # lark %extend statements specific to individual schemes
├── terminals.json  # dictionary of terminals for each scheme
├── mergers.json    # dictionary of phonological mergers specific to individual schemes
├── parser.py       # preprocessing and parser functions
└── translit.py     # Translator classes

The lark rules and json files are the data required for the parsing and translation functions in parser.py and translit.py.

Refer to the API documentation for more information.

Q & A

Related projects

From Learn-Teochew

We use parsetc to convert Teochew opera transcriptions into different romanization systems for the Learn Teochew Opera website.

How to type the special diacritics like ṳ, o̍, o͘ in some romanization systems? If you use MacOS X, check out our custom keyboard layouts

Others