Baseline: main branch state prior to Top-10 films expansion
This commit is contained in:
commit
6b15603e56
139 files changed
+329420
No files matched your search
+81
@@ -0,0 +1,81 @@
|
||||
import { OutputFormat } from '@ingglish/phonemes';
|
||||
|
||||
/**
|
||||
* NRL/Elovitz letter-to-sound rules for grapheme-to-phoneme conversion.
|
||||
*
|
||||
* Based on: Elovitz, H., Johnson, R., McHugh, A., and Shore, J. (1976)
|
||||
* "Automatic translation of English text to phonetics by means of
|
||||
* letter-to-sound rules." NRL Report 7948.
|
||||
*
|
||||
* ~960 context-sensitive rules that examine left and right letter context
|
||||
* to determine pronunciation. ~150 are general spelling rules (silent E,
|
||||
* digraphs, vowel teams, C/G softening, suffixes). The other ~800 are
|
||||
* narrow context patches and whole-word memorizations for the cases where
|
||||
* those rules break down.
|
||||
*
|
||||
* Each rule has the form:
|
||||
*
|
||||
* leftContext[TARGET]rightContext=/PHONEMES/
|
||||
*
|
||||
* Special context symbols:
|
||||
* # = 1+ vowels (AEIOUY)
|
||||
* . = voiced consonant (BDVGJLMNRWZ)
|
||||
* % = suffix (ER, E, ES, ED, ING, ELY)
|
||||
* & = sibilant (S, C, G, Z, X, J, CH, SH)
|
||||
* @ = non-palate consonant (T, S, R, D, L, Z, N, J, TH, CH, SH)
|
||||
* ^ = single consonant
|
||||
* + = front vowel (E, I, Y)
|
||||
* : = 0+ consonants
|
||||
* ' '= word boundary (space)
|
||||
*/
|
||||
|
||||
interface G2PTrace {
|
||||
phonemes: string[];
|
||||
steps: G2PTraceStep[];
|
||||
}
|
||||
interface G2PTraceStep {
|
||||
letters: string;
|
||||
phonemes: string[];
|
||||
rule: string;
|
||||
}
|
||||
/**
|
||||
* Converts a word to ARPAbet using NRL context-sensitive rules.
|
||||
*
|
||||
* @param word The word to convert
|
||||
* @returns Array of ARPAbet phonemes
|
||||
*/
|
||||
declare function wordToArpabet(word: string): string[];
|
||||
/**
|
||||
* Converts a word to ARPAbet using NRL context-sensitive rules,
|
||||
* returning both the phonemes and a trace of which rules fired.
|
||||
*/
|
||||
declare function wordToArpabetTraced(word: string): G2PTrace;
|
||||
/**
|
||||
* Translates an unknown word using NRL letter-to-sound rules.
|
||||
* This is a fallback when the word isn't in the dictionary.
|
||||
*
|
||||
* @param word The unknown word
|
||||
* @param format The output format
|
||||
* @returns The best-effort translation
|
||||
*/
|
||||
declare function wordToPhonetic(word: string, format?: OutputFormat): string;
|
||||
|
||||
/**
|
||||
* Stress prediction post-processor for G2P rules.
|
||||
*
|
||||
* The NRL rules assign stress-1 to ALL non-schwa vowels, meaning multi-syllable
|
||||
* words get every vowel stressed. This module predicts which syllable gets
|
||||
* primary stress using Rastle & Coltheart-style affix rules, then reduces
|
||||
* unstressed vowels to schwa where appropriate.
|
||||
*/
|
||||
/**
|
||||
* Apply stress prediction to a phoneme array produced by NRL rules.
|
||||
*
|
||||
* - Finds all vowel positions (phonemes ending in 0/1/2)
|
||||
* - Predicts which syllable gets primary stress
|
||||
* - Reduces unstressed reducible vowels to AH0 (schwa)
|
||||
* - Marks other unstressed vowels with 0
|
||||
*/
|
||||
declare function applyStressPrediction(word: string, phonemes: string[]): string[];
|
||||
|
||||
export { type G2PTrace, type G2PTraceStep, applyStressPrediction, wordToArpabet, wordToArpabetTraced, wordToPhonetic };
|
||||
Reference in new issue
Block a user