UNPKG

taipa

Version:

Taiwanese morphological parsing library

336 lines 13.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TonalInflectionLexemeMaker = exports.TonalUnmutationLexeme = exports.TonalMutationLexeme = exports.TonalUninfectionLexeme = exports.TonalInfectionLexeme = exports.TonalUninsertionLexeme = exports.TonalInsertionLexeme = exports.TonalInflectionLexeme = void 0; const unit_1 = require("../unit"); const maker_1 = require("../maker"); const unit_2 = require("../unchange/unit"); const tonalres_1 = require("../tonal/tonalres"); const unit_3 = require("../unit"); /** A word and its inflected forms. */ class TonalInflectionLexeme extends unit_1.Lexeme { word; forms = new Array(); endingAllomorphic; // TODO: word patterns for thiapwsux chongwthaiwgiy, ay, etc... check out member sounds in morpheme. constructor(morphemes, metaplasm) { super(); if (morphemes.length == 0) this.word = new unit_2.TonalWord([]); else this.word = new unit_2.TonalWord(morphemes.map((x) => x.syllable)); if (morphemes.length > 0) { if (morphemes[morphemes.length - 1]) { // tonal ending needs to be assigned to sandhi lexeme this.endingAllomorphic = this.assignAllomorphicEnding(morphemes[morphemes.length - 1].allomorph); } else { this.endingAllomorphic = new unit_2.AllomorphicEnding(); } } else { this.endingAllomorphic = new unit_2.AllomorphicEnding(); } if (morphemes.length > 0) this.forms = this.assignWordForms(morphemes, metaplasm); } assignAllomorphicEnding(allomorph) { let ending = new unit_2.AllomorphicEnding(); if (allomorph instanceof tonalres_1.FreeAllomorph) { // replace the tonal ending let fae = new unit_2.FreeAllomorphicEnding(); fae.allomorph = allomorph; ending = fae; } else if (allomorph instanceof tonalres_1.CheckedAllomorph) { // append the tonal of the tonal ending let chae = new unit_2.CheckedAllomorphicEnding(); chae.allomorph = allomorph; ending = chae; } return ending; } getInflectionalEnding() { if (this.endingAllomorphic) return this.endingAllomorphic.allomorph.tonal.toString(); return ''; } getAllomorphicEnding() { if (this.endingAllomorphic) return this.endingAllomorphic; return ''; } assignWordForms(ms, ti) { return ti.apply(ms); } getForms() { // TODO: change member variable name and method name. return this.forms; } } exports.TonalInflectionLexeme = TonalInflectionLexeme; /** A word and its inserted forms. */ class TonalInsertionLexeme { morphemes; word; forms = new Array(); constructor(morphemes, metaplasm) { this.morphemes = morphemes; if (morphemes.length == 0) this.word = new unit_2.TonalWord([]); else this.word = new unit_2.TonalWord(morphemes.map((x) => x.syllable)); if (morphemes.length > 0) this.forms = metaplasm.apply(morphemes); } getForms() { // for internal samdhi return this.forms; } insertWith(preceding) { const wrd = new unit_2.TonalWord(this.morphemes.map((x) => new unit_2.TonalSyllable(x.syllable.letters))); if (preceding.morphemes.length > 0) { const adjacentLtrs = preceding.morphemes[preceding.morphemes.length - 1].sounds; let s = new unit_3.Sound(); if (adjacentLtrs[adjacentLtrs.length - 1].name === tonalres_1.TonalSpellingTags.freeTone && adjacentLtrs[adjacentLtrs.length - 2].name === tonalres_1.TonalSpellingTags.nasalFinalConsonant) { s = adjacentLtrs[adjacentLtrs.length - 2]; } else if (adjacentLtrs[adjacentLtrs.length - 1].name === tonalres_1.TonalSpellingTags.nasalFinalConsonant) { s = adjacentLtrs[adjacentLtrs.length - 1]; } const syls = this.morphemes[0].insertNasal(s); wrd.replaceSyllable(0, syls[0]); return [wrd]; } return []; } } exports.TonalInsertionLexeme = TonalInsertionLexeme; /** A word and its inserted forms. */ class TonalUninsertionLexeme { morphemes; word; forms = new Array(); constructor(morphemes, metaplasm) { this.morphemes = morphemes; if (morphemes.length == 0) this.word = new unit_2.TonalWord([]); else this.word = new unit_2.TonalWord(morphemes.map((x) => x.syllable)); if (morphemes.length > 0) this.forms = metaplasm.apply(morphemes); } getForms() { // for internal samdhi return this.forms; } uninsertWith(preceding) { const wrd = new unit_2.TonalWord(this.morphemes.map((x) => new unit_2.TonalSyllable(x.syllable.letters))); let initial = ''; if (this.morphemes.length > 0) { initial = this.morphemes[0].sounds[0].toString(); } if (preceding.morphemes.length > 0) { const precedingLtrs = preceding.morphemes[preceding.morphemes.length - 1].sounds; let s = new unit_3.Sound(); if (precedingLtrs[precedingLtrs.length - 1].name === tonalres_1.TonalSpellingTags.freeTone && precedingLtrs[precedingLtrs.length - 2].name === tonalres_1.TonalSpellingTags.nasalFinalConsonant) { s = precedingLtrs[precedingLtrs.length - 2]; } else if (precedingLtrs[precedingLtrs.length - 1].name === tonalres_1.TonalSpellingTags.nasalFinalConsonant) { s = precedingLtrs[precedingLtrs.length - 1]; } if (s && s.toString().length > 0 && (s.toString() === initial || (s.toString() === tonalres_1.TonalLetterTags.ng && initial === tonalres_1.TonalLetterTags.g))) { // when the preceding letter is m, the initial of this enclitic is m // when the preceding letter is n, the initial of this enclitic is n // when the preceding letter is ng, the initial of this enclitic is ng/g const syls = this.morphemes[0].uninsertNasal(); wrd.replaceSyllable(0, syls[0]); return [wrd]; } } return []; } } exports.TonalUninsertionLexeme = TonalUninsertionLexeme; class TonalInfectionLexeme { morphemes; word; forms = new Array(); constructor(morphemes, metaplasm) { this.morphemes = morphemes; if (morphemes.length == 0) this.word = new unit_2.TonalWord([]); else this.word = new unit_2.TonalWord(morphemes.map((x) => x.syllable)); if (morphemes.length > 0) this.forms = metaplasm.apply(morphemes); } getForms() { // for internal sandhi return this.forms; } infectWith(preceding) { const wrd = new unit_2.TonalWord(this.morphemes.map((x) => new unit_2.TonalSyllable(x.syllable.letters))); if (preceding.morphemes.length > 0 && preceding.morphemes[preceding.morphemes.length - 1].sounds.filter((i) => i.name === tonalres_1.TonalSpellingTags.nasalization).length > 0) { // if there is a nasalization in the preceding word const syls = this.morphemes[0].infect(); wrd.replaceSyllable(0, syls[0]); return [wrd]; } return []; } } exports.TonalInfectionLexeme = TonalInfectionLexeme; class TonalUninfectionLexeme { morphemes; word; forms = new Array(); constructor(morphemes, metaplasm) { this.morphemes = morphemes; if (morphemes.length == 0) this.word = new unit_2.TonalWord([]); else this.word = new unit_2.TonalWord(morphemes.map((x) => x.syllable)); if (morphemes.length > 0) this.forms = metaplasm.apply(morphemes); } getForms() { // for internal samdhi return this.forms; } uninfectWith(preceding) { const wrd = new unit_2.TonalWord(this.morphemes.map((i) => new unit_2.TonalSyllable(i.syllable.letters))); if (preceding.morphemes.length > 0) { const adjacentLtrs = this.morphemes[this.morphemes.length - 1].sounds; const n = preceding.morphemes[preceding.morphemes.length - 1].sounds.filter((i) => i.name === tonalres_1.TonalSpellingTags.nasalization); if (n.length == 1 && adjacentLtrs.filter((it) => it.name === tonalres_1.TonalSpellingTags.nasalization) .length == 1) { // if there is a nasalization in the preceding word and the current word wrd.replaceSyllable(0, this.morphemes[0].uninfect()[0]); return [wrd]; } } return []; } } exports.TonalUninfectionLexeme = TonalUninfectionLexeme; /** A word and its mutated forms. */ class TonalMutationLexeme { morphemes; word; forms = new Array(); constructor(morphemes, metaplasm) { this.morphemes = morphemes; if (morphemes.length == 0) this.word = new unit_2.TonalWord([]); else this.word = new unit_2.TonalWord(morphemes.map((x) => x.syllable)); if (morphemes.length > 0) this.forms = metaplasm.apply(morphemes); } getForms() { // for internal samdhi return this.forms; } mutateWith(following) { const wrd = new unit_2.TonalWord(this.morphemes.map((i) => new unit_2.TonalSyllable(i.syllable.letters))); if (following.morphemes.length > 0) { const adjacentLtrs = following.morphemes[following.morphemes.length - 1].sounds; if (adjacentLtrs[0].name === tonalres_1.TonalSpellingTags.initialConsonant) { const s = adjacentLtrs[0]; const syls = this.morphemes[this.morphemes.length - 1].changeFinalPtkppttkk(s); if (syls && syls.length > 0) { wrd.popSyllable(); wrd.pushSyllable(syls[0]); } return [wrd]; } } return []; } } exports.TonalMutationLexeme = TonalMutationLexeme; /** A word and its unmutated forms. */ class TonalUnmutationLexeme { morphemes; word; forms = new Array(); constructor(morphemes, metaplasm) { this.morphemes = morphemes; if (morphemes.length == 0) this.word = new unit_2.TonalWord([]); else this.word = new unit_2.TonalWord(morphemes.map((x) => x.syllable)); if (morphemes.length > 0) this.forms = metaplasm.apply(morphemes); } getForms() { // for internal samdhi return this.forms; } unmutateWith(following) { const ltrs = this.morphemes[this.morphemes.length - 1].sounds; const fnls = ltrs.filter((i) => i.name === tonalres_1.TonalSpellingTags.stopFinalConsonant); const wrd = new unit_2.TonalWord(this.morphemes.map((i) => new unit_2.TonalSyllable(i.syllable.letters))); if (following.morphemes[0].sounds[0].toString() === tonalres_1.TonalLetterTags.g) { if (fnls[0].toString() === tonalres_1.TonalLetterTags.gg || fnls[0].toString() === tonalres_1.TonalLetterTags.g) { wrd.replaceSyllable(0, this.morphemes[0].unmutateFinalConsonant(following.morphemes[0].sounds[0])[0]); return [wrd]; } } return []; } } exports.TonalUnmutationLexeme = TonalUnmutationLexeme; class TonalInflectionLexemeMaker extends maker_1.LexemeMaker { metaplasm; constructor(metaplasm) { super(); this.metaplasm = metaplasm; } makeLexemes(morphemes) { return this.make(morphemes); } make(morphemes) { let isInflStemWithX = false; // inflectional stem with x in the middle if (morphemes) { isInflStemWithX = this.checkFifth(morphemes); if (isInflStemWithX) return new TonalInflectionLexeme([], this.metaplasm); } return new TonalInflectionLexeme(morphemes, this.metaplasm); } checkFifth(ms) { for (let i = 0; i < ms.length; i++) { if (ms[i] && ms[i].syllable.lastLetter.literal === tonalres_1.TonalLetterTags.x) { if (i < ms.length - 1 && !ms[ms.length - 1].isAy()) { if (ms[ms.length - 1].syllable.lastLetter.literal === tonalres_1.TonalLetterTags.a) { break; } else { // tonal x can't not appear in them middle of an inflectional stem // if it is not preceding an ay or a return true; } } } } return false; } } exports.TonalInflectionLexemeMaker = TonalInflectionLexemeMaker; //# sourceMappingURL=lexeme.js.map