ctnx.syllable module

class ctnx.syllable.NewStyleTonePlacer[source]

Bases: TonePlacer

Places tone marks according to the new style of Vietnamese spelling (e.g., ‘oà’, ‘uý’).

classmethod placement_index(syllable: Syllable) int[source]
class ctnx.syllable.OldStyleTonePlacer[source]

Bases: NewStyleTonePlacer

Places tone marks according to the old style of Vietnamese spelling (e.g., ‘òa’, ‘úy’).

classmethod placement_index(syllable: Syllable) int[source]
class ctnx.syllable.Syllable(onset: str, nucleus: str, coda: str, tone='', auto_correct: bool = True, tone_placer=<class 'ctnx.syllable.NewStyleTonePlacer'>)[source]

Bases: object

Represents a syllable in the Vietnamese language.

CLOSEABLE_DIPHTHONGS = ('oa', 'oă', 'oe', 'uê', 'uy')
CLOSED_DIPHTHONGS = ('ai', 'ao', 'au', 'ay', 'âu', 'ây', 'eo', 'êu', 'ia', 'iu', 'oi', 'ôi', 'ơi', 'ua', 'ui', 'uơ', 'ưa', 'ưi', 'ưu', 'yu')
CLOSED_NUCLEI = ('uyêu', 'iêu', 'oai', 'oao', 'oau', 'oay', 'oeo', 'uay', 'uây', 'uêu', 'uôi', 'uya', 'uyu', 'uơi', 'ươi', 'ươu', 'yêu', 'ai', 'ao', 'au', 'ay', 'âu', 'ây', 'eo', 'êu', 'ia', 'iu', 'oi', 'ôi', 'ơi', 'ua', 'ui', 'uơ', 'ưa', 'ưi', 'ưu', 'yu')
CLOSED_TRIPHTHONGS = ('iêu', 'oai', 'oao', 'oau', 'oay', 'oeo', 'uay', 'uây', 'uêu', 'uôi', 'uya', 'uyu', 'uơi', 'ươi', 'ươu', 'yêu')
CODAS = ('ch', 'c', 'm', 'ng', 'nh', 'n', 'p', 't', '')
DIPHTHONGS = ('iê', 'oo', 'ôô', 'uâ', 'uô', 'ươ', 'yê', 'oa', 'oă', 'oe', 'uê', 'uy', 'ai', 'ao', 'au', 'ay', 'âu', 'ây', 'eo', 'êu', 'ia', 'iu', 'oi', 'ôi', 'ơi', 'ua', 'ui', 'uơ', 'ưa', 'ưi', 'ưu', 'yu')
MONOPHTHONGS = ('a', 'ă', 'â', 'e', 'ê', 'i', 'o', 'ô', 'ơ', 'u', 'ư', 'y')
NON_LIP_ROUNDABLE_NUCLEI_SET = {'o', 'oi', 'oo', 'u', 'ua', 'ui', 'uô', 'uôi'}
NUCLEI = ('uyêu', 'iêu', 'oai', 'oao', 'oau', 'oay', 'oeo', 'uay', 'uây', 'uêu', 'uôi', 'uya', 'uyu', 'uơi', 'ươi', 'ươu', 'yêu', 'uyê', 'iê', 'oo', 'ôô', 'uâ', 'uô', 'ươ', 'yê', 'oa', 'oă', 'oe', 'uê', 'uy', 'ai', 'ao', 'au', 'ay', 'âu', 'ây', 'eo', 'êu', 'ia', 'iu', 'oi', 'ôi', 'ơi', 'ua', 'ui', 'uơ', 'ưa', 'ưi', 'ưu', 'yu', 'a', 'ă', 'â', 'e', 'ê', 'i', 'o', 'ô', 'ơ', 'u', 'ư', 'y')
ONSETS = ('b', 'ch', 'c', 'd', 'đ', 'gh', 'gi', 'g', 'h', 'kh', 'k', 'l', 'm', 'ngh', 'ng', 'nh', 'ng', 'n', 'ph', 'p', 'q', 'r', 's', 'th', 'tr', 't', 'v', 'x', '')
OPEN_DIPHTHONGS = ('iê', 'oo', 'ôô', 'uâ', 'uô', 'ươ', 'yê')
OPEN_NUCLEI = ('uyê', 'iê', 'oo', 'ôô', 'uâ', 'uô', 'ươ', 'yê')
OPEN_TRIPHTHONGS = ('uyê',)
OTHER_CLOSED_NUCLEI = ('uyêu',)
OTHER_NUCLEI = ('uyêu',)
QU_NUCLEUS_PREFIX_REPLACEMENTS = {'ua': 'oa', 'ue': 'oe', 'uă': 'oă'}
TRIPHTHONGS = ('iêu', 'oai', 'oao', 'oau', 'oay', 'oeo', 'uay', 'uây', 'uêu', 'uôi', 'uya', 'uyu', 'uơi', 'ươi', 'ươu', 'yêu', 'uyê')
apply_onglide_semivowel() bool[source]

Applies an on-glide semivowel to the syllable, modifying the nucleus (and onset if necessary).

property can_apply_onglide_semivowel: bool

Checks whether an on-glide semivowel can be applied to the syllable’s nucleus.

property coda: str

The final consonant part of the syllable.

classmethod from_string(string: str, auto_correct=True, tone_placer=<class 'ctnx.syllable.NewStyleTonePlacer'>) Syllable[source]

Creates a Syllable object from a string.

This method is cached by default. Use _from_string() for the uncached version.

property has_even_tone: bool

Checks whether the syllable’s tone is even (not oblique).

property has_oblique_tone: bool

Checks whether the syllable’s tone is oblique (uneven).

property has_onglide_semivowel: bool

Checks whether the syllable has an on-glide semivowel, as present in ‘qua’ and ‘xoa’.

property i_normalized_nucleus: str

The vowel part of the syllable, with i/y-normalized value.

is_rhyme_with(other: Syllable | str) bool[source]

Checks whether the syllable rhymes with another syllable. Besides exact rime matching, this method uses predefined rules for detecting similar rimes.

Similar-rime rules are based on https://bentinhyeu.forumvi.com/t10-topic and https://hoaanhdao0603082010.violet.vn/entry/van-trong-tho-12076153.html .

property normalized_nucleus: str

The normalized vowel part of the syllable, resolving spelling variants like ‘iê’ to ‘ia’ when there is no coda.

property normalized_rime: str

The rime of the syllable, with i/y-normalized value.

property nucleus: str

The vowel part of the syllable as stored in this object, including semivowels.

property onset: str

The initial consonant part of the syllable.

property rime: str

The rime of the syllable, which is the combination of the nucleus and the coda.

to_string() str[source]

Returns the written form of the syllable.

property tone: str

The tone of the syllable.

The returned tone is denoted as one of the following: ‘’: unmarked (ngang) ‘/’: acute accent (sắc) ‘': grave accent (huyền) ‘?’: hook above (hỏi) ‘~’: tilde (ngã) ‘.’: dot below (nặng)

update(onset: str, nucleus: str, coda: str, tone: str)[source]
class ctnx.syllable.TonePlacer[source]

Bases: ABC

Controls tone mark placement on Vietnamese vowels.

classmethod place(syllable: Syllable, nucleus) str[source]
static place_to_vowels_at(vowels, tone, position)[source]
abstract classmethod placement_index(syllable: Syllable) int[source]
ctnx.syllable.find_startswith(text: str, candidates: Iterable)[source]