phonemize
Version:
Fast phonemizer with rule-based G2P prediction. Pure JavaScript implementation.
38 lines (37 loc) • 1.48 kB
TypeScript
/**
* End-to-end principled prediction (P2.3 of G2P redesign).
*
* Combines decomposer + stress FSM + reduction into a single function:
*
* predictPrincipled(word, baseLookup) → IPA | null
*
* Steps:
* 1. Decompose word → outer suffix + base (with alternate spellings).
* 2. Look up base IPA via `baseLookup` (caller supplies; typically dict
* lookup, eventually compiled rule table from P3).
* 3. Concatenate base IPA + suffix IPA (stress marks stripped from base).
* 4. Compute new stress via assignStress, passing the base's own stress
* index for neutral suffixes.
* 5. Reduce unstressed vowels in the result.
* 6. Insert stress marks at the predicted positions.
*
* Returns null if the word can't be decomposed or the base can't be
* resolved. The caller falls back to other strategies in that case.
*
* This is purely a composition layer — all the linguistic logic lives in
* en-suffixes, en-stress, and en-reduce.
*/
import { SuffixEntry } from "./suffixes";
import { Stress } from "./stress";
export type BaseLookup = (word: string) => string | undefined;
export interface PrincipledResult {
ipa: string;
base: string;
suffix: SuffixEntry;
stress: Stress;
}
/**
* Run the full principled pipeline. Returns null if the word can't be
* processed (no recognizable suffix, or base not resolvable).
*/
export declare function predictPrincipled(word: string, baseLookup: BaseLookup): PrincipledResult | null;