UNPKG

taipa

Version:

Taiwanese morphological parsing library

43 lines 2.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createCompoundPhraseme = exports.createTonalPhrase = exports.createTonalInflectionLexeme = void 0; const analyzer_1 = require("./analyzer"); const unit_1 = require("../unchange/unit"); const metaplasm_1 = require("../metaplasm"); const phraseme_1 = require("./phraseme"); const metaplasm_2 = require("../metaplasm"); const metaplasm_3 = require("./metaplasm"); /** Creates a lexeme given a `TonalCombiningMetaplasm`. If metaplasm is not provided, `TonalZeroCombining` is defaulted. Excessive tokens are ignored. */ function createTonalInflectionLexeme(str, metaplasm) { const tia = analyzer_1.tonalInflectionAnalyzer; const ms = metaplasm ? tia.morphAnalyze(str, metaplasm) : tia.morphAnalyze(str, new metaplasm_2.TonalZeroCombining()); const lx = tia.lexAnalyze(ms, new metaplasm_3.TonalDesinenceInflection()); return lx; } exports.createTonalInflectionLexeme = createTonalInflectionLexeme; /** Creates a phrase given a sequence of arbitrary words regardless of syntax. Tokens are analyzed one by one. */ function createTonalPhrase(str) { const tia = analyzer_1.tonalInflectionAnalyzer; const strs = str.match(/\w+/g); const lxs = strs ? strs.map(it => tia.lexAnalyze(it, new metaplasm_1.TonalZeroInflection())) : []; return new unit_1.TonalPhrase(lxs.map(it => it.word)); } exports.createTonalPhrase = createTonalPhrase; /** * Creates a compound in which the preceding word will be inflected and the following word will not. * @param preceding A word that will be inflected. * @param following A word that will not be inflected. */ function createCompoundPhraseme(preceding, following) { const tia = analyzer_1.tonalInflectionAnalyzer; const tiphm = new phraseme_1.TonalInflectionPhrasemeMaker(); const lxPreceding = tia.lexAnalyze(preceding, new metaplasm_3.TonalDesinenceInflection()); const lxFollowing = createTonalInflectionLexeme(following); return tiphm.makeCompoundPhraseme(lxPreceding, lxFollowing); } exports.createCompoundPhraseme = createCompoundPhraseme; //# sourceMappingURL=creator.js.map