Jamo: Hangul Syllable and Jamo Analyzer
Jamo is a Python library designed for the decomposition and synthesis of Hangul syllables into their constituent jamo characters. It supports both the U+11xx jamo characters and Hangul Compatibility Jamo (HCJ, U+31xx) for display purposes. Currently in beta release (version 0.4.1), the library primarily focuses on modern Hangul. While releases are sporadic, the project is actively maintained, with documentation reflecting the 0.4-beta interface.
Warnings
- breaking Function names and module interfaces underwent significant changes between versions 0.3 and 0.4.0 (e.g., `j2h` vs. `jamo_to_hangul`), which may break older codebases.
- gotcha The `get_jamo_class` function is designed for U+11xx jamo characters and will raise an `InvalidJamoError` if passed Hangul Compatibility Jamo (HCJ) consonants, as they are ambiguous in class.
- deprecated The string return value of `get_jamo_class` ('lead', 'vowel', 'tail') is currently under consideration for change in future versions.
- gotcha When converting Hangul Compatibility Jamo (HCJ) to U+11xx jamo using `hcj2j`, you *must* provide the `position` argument (e.g., 'lead', 'vowel', 'tail') for consonant characters to resolve ambiguity.
- gotcha U+11xx jamo characters may have display issues depending on the font and environment. It is often recommended to convert them to Hangul Compatibility Jamo (HCJ) using `j2hcj` for more uniform and reliable display.
Install
-
pip install jamo
Imports
- h2j
from jamo import h2j
- j2h
from jamo import j2h
- j2hcj
from jamo import j2hcj
- hcj2j
from jamo import hcj2j
- get_jamo_class
from jamo import get_jamo_class
- jamo.hangul_to_jamo
Quickstart
from jamo import h2j, j2h, j2hcj
# Hangul Decomposition (to U+11xx jamo)
hangul_text = "안녕하세요"
decomposed_jamo = h2j(hangul_text)
print(f"Decomposed (U+11xx): {decomposed_jamo}")
# Convert U+11xx jamo to Hangul Compatibility Jamo (HCJ) for display
display_jamo = j2hcj(decomposed_jamo)
print(f"Decomposed (HCJ): {display_jamo}")
# Hangul Synthesis
lead = 'ㅇ'
vowel = 'ㅏ'
tail = 'ㄴ'
synthesized_hangul = j2h(lead, vowel, tail)
print(f"Synthesized: {synthesized_hangul}")
# Using splat operator for synthesis from a string of jamo
jamo_string = 'ㅇㅏㄴ'
synthesized_from_string = j2h(*jamo_string)
print(f"Synthesized from string: {synthesized_from_string}")