From 3c5c5ef59088a96b7988652f2dfef3d8a771f464 Mon Sep 17 00:00:00 2001 From: sanine Date: Mon, 6 May 2024 18:44:09 -0500 Subject: implement consonant featural selection --- src/language.ts | 99 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 35 deletions(-) (limited to 'src/language.ts') diff --git a/src/language.ts b/src/language.ts index 0721e09..c0360b8 100644 --- a/src/language.ts +++ b/src/language.ts @@ -1,16 +1,16 @@ export enum VowelHeight { - Open, - NearOpen, - OpenMid, - Mid, - CloseMid, - NearClose, - Close, + Open = 'open', + NearOpen = 'nearOpen', + OpenMid = 'openMid', + Mid = 'mid', + CloseMid = 'closeMid', + NearClose = 'nearClose', + Close = 'close', } export enum VowelDepth { - Front, - Central, - Back, + Front = 'front', + Central = 'central', + Back = 'back', } export interface VowelFeatures { height: VowelHeight; @@ -106,33 +106,33 @@ export function vowelFeaturesToIpa(features: VowelFeatures): string { export enum ConsonantPlace { - Bilabial, - Labiodental, - Linguolabial, - Dental, - Alveolar, - Postalveolar, - Retroflex, - Palatal, - Velar, - Uvular, - Pharyngeal, - Glottal, + Bilabial = 'bilabial', + Labiodental = 'labiodental', + Linguolabial = 'labiolingual', + Dental = 'dental', + Alveolar = 'alveolar', + Postalveolar = 'postalveolar', + Retroflex = 'retroflex', + Palatal = 'palatal', + Velar = 'velar', + Uvular = 'uvular', + Pharyngeal = 'pharyngeal', + Glottal = 'glottal', } export enum ConsonantManner { - Nasal, - Plosive, - SibilantAffricate, - NonSibilantAffricate, - SibilantFricative, - NonSibilantFricative, - Approximant, - Tap, - Trill, - LateralAffricate, - LateralFricative, - LateralApproximant, - LateralTap, + Nasal = 'nasal', + Plosive = 'plosive', + SibilantAffricate = 'sibilantAffricate', + NonSibilantAffricate = 'nonSibilantAffricate', + SibilantFricative = 'sibilantFricative', + NonSibilantFricative = 'nonSibilantFricative', + Approximant = 'approximant', + Tap = 'tap', + Trill = 'trill', + LateralAffricate = 'lateralAffricate', + LateralFricative = 'lateralFricative', + LateralApproximant = 'lateralApproximant', + LateralTap = 'lateralTap', } export interface ConsonantFeatures { place: ConsonantPlace; @@ -480,3 +480,32 @@ export function consonantFeaturesToIpa(features: ConsonantFeatures): string { } } } + + +export function isConsonantPossible(features: ConsonantFeatures): boolean { + return consonantFeaturesToIpa(features) !== ''; +} + + +// get all of the consonants based on the features selected +export function pickConsonants( + places: ConsonantPlace[], + manners: ConsonantManner[], + voicing: [boolean, boolean], +): ConsonantFeatures[] { + return places.map( + place => manners.map( + manner => { + const [ unvoiced, voiced ] = voicing; + const result = []; + if (unvoiced) { + result.push({ place, manner, voice: false }); + } + if (voiced) { + result.push({ place, manner, voice: true }); + } + return result; + } + ).flat() + ).flat().filter(isConsonantPossible); +} -- cgit v1.2.1