UNPKG

taipa

Version:

Taiwanese morphological parsing library

271 lines 10.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TonalSoundGenerator = exports.syllableCompositions = void 0; const unit_1 = require("../unit"); const tonalres_1 = require("./tonalres"); const collections_1 = require("./collections"); function initialConsonant(sg) { if (tonalres_1.initialConsonantsTonal.includes(sg.letters[sg.matchedSounds.length])) { const sounds = tonalres_1.tonalPositionalSounds.get(sg.letters[sg.matchedSounds.length]); if (sounds) { const s = sounds(tonalres_1.TonalSpellingTags.initialConsonant); if (s) sg.matchedSounds.push(s); } } else sg.matching = false; return sg; } function nasalFinalConsonant(sg) { // check out the length of letters like we do in the loop in function vowel if (!sg.matching || sg.letters.length == 0) return sg; if (tonalres_1.nasalFinalConsonantsTonal.includes(sg.letters[sg.matchedSounds.length])) { const sounds = tonalres_1.tonalPositionalSounds.get(sg.letters[sg.matchedSounds.length]); if (sounds) { const s = sounds(tonalres_1.TonalSpellingTags.nasalFinalConsonant); if (s) sg.matchedSounds.push(s); } } else { sg.matching = false; } return sg; } function vowel(sg) { // we need the below line when the preceding initial consonant is not matched if (!sg.matching) return sg; let toBePredicted = true; let matches = 0; for (let i = sg.matchedSounds.length; i < sg.letters.length; i++) { if (tonalres_1.vowelsTonal.includes(sg.letters[i])) { toBePredicted = true; const sounds = tonalres_1.tonalPositionalSounds.get(sg.letters[i]); if (sounds) { const s = sounds(tonalres_1.TonalSpellingTags.vowel); matches++; if (s) sg.matchedSounds.push(s); } } else { toBePredicted = false; if (matches == 0) sg.matching = false; break; } } return sg; } function materLectionis(sg) { if (tonalres_1.materLectionisTonal.includes(sg.letters[sg.matchedSounds.length])) { const sounds = tonalres_1.tonalPositionalSounds.get(sg.letters[sg.matchedSounds.length]); if (sounds) { const s = sounds(tonalres_1.TonalSpellingTags.materLectionis); if (s) sg.matchedSounds.push(s); } } else sg.matching = false; return sg; } function nasalization(sg) { if (!sg.matching) return sg; if (tonalres_1.nasalizationsTonal.includes(sg.letters[sg.matchedSounds.length])) { const sounds = tonalres_1.tonalPositionalSounds.get(sg.letters[sg.matchedSounds.length]); if (sounds) { const s = sounds(tonalres_1.TonalSpellingTags.nasalization); if (s) sg.matchedSounds.push(s); } } else { sg.matching = false; } return sg; } function freeToneLetter(sg) { if (!sg.matching) return sg; if (tonalres_1.freeToneLettersTonal.includes(sg.letters[sg.matchedSounds.length])) { const sounds = tonalres_1.tonalPositionalSounds.get(sg.letters[sg.matchedSounds.length]); if (sounds) { const s = sounds(tonalres_1.TonalSpellingTags.freeTone); if (s) sg.matchedSounds.push(s); } } else { sg.matching = false; } return sg; } function stopFinalConsonant(sg) { if (!sg.matching) return sg; if (tonalres_1.finalConsonantsPtkhppttkkhhTonal.includes(sg.letters[sg.matchedSounds.length])) { const sounds = tonalres_1.tonalPositionalSounds.get(sg.letters[sg.matchedSounds.length]); if (sounds) { const s = sounds(tonalres_1.TonalSpellingTags.stopFinalConsonant); if (s) sg.matchedSounds.push(s); } } else { sg.matching = false; } return sg; } function neutralFinalConsonant(sg) { if (!sg.matching) return sg; if (tonalres_1.neutralFinalConsonantsTonal.includes(sg.letters[sg.matchedSounds.length])) { const sounds = tonalres_1.tonalPositionalSounds.get(sg.letters[sg.matchedSounds.length]); if (sounds) { const s = sounds(tonalres_1.TonalSpellingTags.stopFinalConsonant); if (s) sg.matchedSounds.push(s); } } else { sg.matching = false; } return sg; } function checkedToneLetter(sg) { if (!sg.matching) return sg; if (tonalres_1.checkedToneLettersTonal.includes(sg.letters[sg.matchedSounds.length])) { const sounds = tonalres_1.tonalPositionalSounds.get(sg.letters[sg.matchedSounds.length]); if (sounds) { const s = sounds(tonalres_1.TonalSpellingTags.checkedTone); if (s) sg.matchedSounds.push(s); } } else { sg.matching = false; } return sg; } function sandhiFinalConsonant(sg) { if (!sg.matching) return sg; if (tonalres_1.finalConsonantsBgjklpsTonal.includes(sg.letters[sg.matchedSounds.length]) || tonalres_1.finalConsonantsBBggkkllppssTonal.includes(sg.letters[sg.matchedSounds.length])) { const sounds = tonalres_1.tonalPositionalSounds.get(sg.letters[sg.matchedSounds.length]); if (sounds) { const s = sounds(tonalres_1.TonalSpellingTags.stopFinalConsonant); if (s) sg.matchedSounds.push(s); } } else { sg.matching = false; } return sg; } // common syllables const scV = (0, unit_1.sgPipe)(vowel); const scM = (0, unit_1.sgPipe)(materLectionis); const scVT = (0, unit_1.sgPipe)(vowel, freeToneLetter); const scMT = (0, unit_1.sgPipe)(materLectionis, freeToneLetter); const scMC = (0, unit_1.sgPipe)(materLectionis, neutralFinalConsonant); const scCV = (0, unit_1.sgPipe)(initialConsonant, vowel); const scVC1 = (0, unit_1.sgPipe)(vowel, stopFinalConsonant); const scVC2 = (0, unit_1.sgPipe)(vowel, nasalFinalConsonant); const scVCT1 = (0, unit_1.sgPipe)(vowel, stopFinalConsonant, checkedToneLetter); const scVCT2 = (0, unit_1.sgPipe)(vowel, nasalFinalConsonant, freeToneLetter); const scCVT = (0, unit_1.sgPipe)(initialConsonant, vowel, freeToneLetter); const scCVC1 = (0, unit_1.sgPipe)(initialConsonant, vowel, stopFinalConsonant); const scCVC2 = (0, unit_1.sgPipe)(initialConsonant, vowel, nasalFinalConsonant); const scCVCT1 = (0, unit_1.sgPipe)(initialConsonant, vowel, stopFinalConsonant, checkedToneLetter); const scCVCT2 = (0, unit_1.sgPipe)(initialConsonant, vowel, nasalFinalConsonant, freeToneLetter); const scCVCC = (0, unit_1.sgPipe)(initialConsonant, vowel, nasalFinalConsonant, neutralFinalConsonant); const scVCCT = (0, unit_1.sgPipe)(vowel, nasalFinalConsonant, neutralFinalConsonant, checkedToneLetter); // consonant syllables const scCC = (0, unit_1.sgPipe)(initialConsonant, nasalFinalConsonant); const scCCT = (0, unit_1.sgPipe)(initialConsonant, nasalFinalConsonant, freeToneLetter); const scCCC = (0, unit_1.sgPipe)(initialConsonant, nasalFinalConsonant, neutralFinalConsonant); const scCCCT = (0, unit_1.sgPipe)(initialConsonant, nasalFinalConsonant, neutralFinalConsonant, checkedToneLetter); // nasalization syllables const scVN = (0, unit_1.sgPipe)(vowel, nasalization); const scVNT = (0, unit_1.sgPipe)(vowel, nasalization, freeToneLetter); const scVNC = (0, unit_1.sgPipe)(vowel, nasalization, neutralFinalConsonant); const scCVN = (0, unit_1.sgPipe)(initialConsonant, vowel, nasalization); const scCVNT = (0, unit_1.sgPipe)(initialConsonant, vowel, nasalization, freeToneLetter); const scCVNC = (0, unit_1.sgPipe)(initialConsonant, vowel, nasalization, neutralFinalConsonant); const scCVNCT = (0, unit_1.sgPipe)(initialConsonant, vowel, nasalization, neutralFinalConsonant, checkedToneLetter); // sandhi syllables const scVC3 = (0, unit_1.sgPipe)(vowel, sandhiFinalConsonant); const scVCT3 = (0, unit_1.sgPipe)(vowel, sandhiFinalConsonant, checkedToneLetter); const scCVC3 = (0, unit_1.sgPipe)(initialConsonant, vowel, sandhiFinalConsonant); const scCVCT3 = (0, unit_1.sgPipe)(initialConsonant, vowel, sandhiFinalConsonant, checkedToneLetter); const scCVCCT = (0, unit_1.sgPipe)(initialConsonant, vowel, nasalFinalConsonant, neutralFinalConsonant, checkedToneLetter); // prettier-ignore exports.syllableCompositions = [ // syllable compositions or patterns scV, scM, scVT, scMT, scMC, scCV, scVC1, scVC2, scVCT1, scVCT2, scCVT, scCVC1, scCVC2, scCVCT1, scCVCT2, scCVCC, scVCCT, scCC, scCCT, scCCC, scCCCT, scVN, scVNT, scVNC, scCVN, scCVNT, scCVNC, scCVNCT, scVC3, scVCT3, scCVC3, scCVCT3, scCVCCT, ]; class TonalSoundGenerator { isStopFinal(str) { if (tonalres_1.finalConsonantsPtkhppttkkhhTonal.includes(str)) return true; return false; } genChecked(ltrs) { /** if the 3rd and 5th checked tones would be changed to -ppx, -ttx, -kkx, * -hhx, -ppw, -ttw, -kkw, and -hhw, edit the rules in combiningRules */ const tos = collections_1.combiningRules.get(ltrs[ltrs.length - 1]); let strs = new Array(); strs.push(ltrs); // console.debug(tos); if (tos) { for (let i in tos) { let syl = new Array(); Object.assign(syl, ltrs); syl.push(tonalres_1.lowerLettersTonal.get(tos[i]).literal); strs.push(syl); } } return strs; } generate(letters) { let strs = new Array(); const sequences = new Array(); // to be returned if (this.isStopFinal(letters[letters.length - 1])) { strs = this.genChecked(letters); } else { strs.push(letters); } for (let i in strs) { // generates all needed sounds to be processed for (let j = 0; j < exports.syllableCompositions.length; j++) { let sg = new unit_1.SoundGeneration(); sg.letters = strs[i]; //console.log(`j: ${j}`) sg = exports.syllableCompositions[j](sg); if (sg.letters.length == sg.matchedSounds.length && sg.matching == true) { sequences.push(sg.matchedSounds); break; } } } // console.log(letters, sequences); return sequences; } } exports.TonalSoundGenerator = TonalSoundGenerator; //# sourceMappingURL=soundgen.js.map