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
+1392
File diff suppressed because it is too large.
Load diff
+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 };
|
||||
+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 };
|
||||
+1362
File diff suppressed because it is too large.
Load diff
+61
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"name": "@ingglish/g2p",
|
||||
"version": "0.1.1",
|
||||
"description": "NRL/Elovitz grapheme-to-phoneme rules for English",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"source": "./src/index.ts",
|
||||
"import": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/index.d.cts",
|
||||
"default": "./dist/index.cjs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"build:fast": "tsup src/index.ts --format esm",
|
||||
"lint": "eslint --cache src",
|
||||
"test": "vitest run --no-color",
|
||||
"bench": "vitest bench --no-color",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ingglish/phonemes": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ingglish/ipa": "^0.1.0"
|
||||
},
|
||||
"keywords": [
|
||||
"g2p",
|
||||
"grapheme-to-phoneme",
|
||||
"english",
|
||||
"pronunciation",
|
||||
"phonemes"
|
||||
],
|
||||
"author": "Paul Tarjan",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ptarjan/ingglish.git",
|
||||
"directory": "packages/g2p"
|
||||
},
|
||||
"homepage": "https://github.com/ptarjan/ingglish#readme",
|
||||
"bugs": {
|
||||
"url": "https://github.com/ptarjan/ingglish/issues"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user