phonemize
Version:
Fast phonemizer with rule-based G2P prediction. Pure JavaScript implementation.
33 lines (32 loc) • 1.43 kB
TypeScript
/**
* Universal English phonotactic post-processing.
*
* A small, principled set of rules that apply to *any* IPA output
* regardless of which pipeline produced it. These are pure
* phonological tweaks (not word-specific patches) that adjust the
* surface form to match native phonology — happy-tensing, syllabic
* consonants, etc.
*
* Distinct from the retired postBase pile (which was 500+ ad-hoc
* if/replace rules for specific orthographic patterns). The rules
* here have ≤10 entries and each one captures a universal pattern.
*
* Performance notes:
* - Every regex is module-level const so the engine caches its
* compilation.
* - Each rule is guarded by a cheap substring/endsWith check before
* the regex executes. The vast majority of IPA strings don't hit
* any given rule, so the guards skip the expensive scan.
* - dropSilentH short-circuits when there's no /h/ at all (avoids
* allocating a new string).
*/
/**
* Apply the small phonotactic rule set in the canonical order. Each
* rule self-guards with a cheap pre-check, so calls that don't trigger
* any rule do roughly O(rule-count) substring scans + zero allocations.
*
* `word` is the lowercased orthographic form, used by rules that need
* lexical context (e.g. the weak-schwa function-word exemption in
* normalizeStrut).
*/
export declare function applyPhonotactics(ipa: string, word?: string): string;