analyze

analyze, analyze_word

The analysis functions return the raw phonological structure of a Thai word, before rendering.


analyze

def analyze(
    text: str,
    *,
    is_final_in_compound: bool = True,
    profile: ReadingProfile = "everyday",
) -> AnalysisResult:

Run the full analysis pipeline on text and return an AnalysisResult.

Parameters

Parameter Type Default Description
text str Thai word or phrase to analyse. NFC normalisation applied automatically.
is_final_in_compound bool True When False, suppresses vowel-length overrides that apply only to a word in final position within a compound.
profile ReadingProfile "everyday" Reading profile.

Returns

AnalysisResult — see Types.

Example

from thaiphon import analyze

result = analyze("ผลไม้")

# The best phonological word.
word = result.best
print(len(word))   # 3 syllables

# Inspect each syllable.
for syl in word.syllables:
    onset = syl.onset.symbol if syl.onset else "∅"
    coda  = syl.coda.symbol  if syl.coda  else "∅"
    print(f"{onset:6} {syl.vowel.symbol:4} {syl.vowel_length.name:6} {coda:4} {syl.tone.name}")

# Output:
# pʰ     o    SHORT  n    RISING
# l      a    SHORT  ∅    HIGH
# m      a    LONG   j    HIGH

# Source and confidence.
print(result.source)           # 'derivation'
print(result.best.confidence)  # float between 0 and 1

# Normalised input text.
print(result.raw)              # 'ผลไม้'

Alternative candidates

When the syllabifier generates multiple candidate segmentations, result.alternatives contains the lower-ranked PhonologicalWord objects:

result = analyze("กรุงเทพ")
print(len(result.alternatives))   # 0 or more alternative phonological words

For most common words, alternatives is empty or contains candidates that differ only slightly.

Loan analysis

result.loan_analysis is a LoanAnalysis object attached by the foreignness detector. It is observational — the phonological derivation does not consult it:

result = analyze("ลิฟต์")
la = result.loan_analysis
if la is not None:
    print(la.is_loanword)   # probability score (float 0–1)

analyze_word

def analyze_word(
    text: str,
    *,
    profile: ReadingProfile = "everyday",
) -> AnalysisResult:

Convenience wrapper around analyze. Equivalent to analyze(text, profile=profile).

Example

from thaiphon import analyze_word

result = analyze_word("น้ำ", profile="etalon_compat")
syl = result.best.syllables[0]
print(syl.coda.symbol)   # 'm'
print(syl.tone.name)     # 'HIGH'

Rendering from an AnalysisResult

If you want to render the same word in multiple schemes, analyze once and render multiple times:

from thaiphon import analyze
from thaiphon.renderers.base import RenderContext
from thaiphon.registry import RENDERERS
import thaiphon.renderers  # ensure built-ins are registered

result = analyze("สวัสดี")
ctx = RenderContext(profile="everyday")

for scheme_id in ("ipa", "tlc", "morev"):
    renderer = RENDERERS.get(scheme_id)
    print(scheme_id, renderer.render_word(result.best, ctx))

This avoids re-running the full pipeline for each scheme.