taipa
Version:
Taiwanese morphological parsing library
124 lines • 3.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TonalPhrase = exports.TonalWord = exports.CheckedAllomorphicEnding = exports.FreeAllomorphicEnding = exports.AllomorphicEnding = exports.CheckedInflectionalEnding = exports.FreeInflectionalEnding = exports.InflectionalEnding = exports.TonalSyllable = void 0;
const unit_1 = require("../unit");
const tonalres_1 = require("../tonal/tonalres");
const tonalres_2 = require("../tonal/tonalres");
const unit_2 = require("../unit");
class TonalSyllable extends unit_1.Syllable {
popLetter() {
this.letters = this.letters.slice(0, this.letters.length - 1);
this.concat();
}
get lastLetter() {
if (this.letters.length >= 1)
return this.letters[this.letters.length - 1];
return new unit_1.AlphabeticLetter([]);
}
get lastSecondLetter() {
if (this.letters.length >= 2)
return this.letters[this.letters.length - 2];
return new unit_1.AlphabeticLetter([]);
}
}
exports.TonalSyllable = TonalSyllable;
class Ending {
}
class InflectionalEnding extends Ending {
affix = new tonalres_2.TonalAffix(); // the affix of this word
toString() {
return this.affix.toString();
}
}
exports.InflectionalEnding = InflectionalEnding;
class FreeInflectionalEnding extends InflectionalEnding {
}
exports.FreeInflectionalEnding = FreeInflectionalEnding;
class CheckedInflectionalEnding extends InflectionalEnding {
}
exports.CheckedInflectionalEnding = CheckedInflectionalEnding;
class AllomorphicEnding extends Ending {
allomorph = new tonalres_1.Allomorph();
toString() {
return this.allomorph.toString();
}
}
exports.AllomorphicEnding = AllomorphicEnding;
class FreeAllomorphicEnding extends AllomorphicEnding {
}
exports.FreeAllomorphicEnding = FreeAllomorphicEnding;
class CheckedAllomorphicEnding extends AllomorphicEnding {
}
exports.CheckedAllomorphicEnding = CheckedAllomorphicEnding;
/** A word made of syllables. */
class TonalWord extends unit_1.Word {
syllables;
constructor(syllables) {
super();
this.syllables = new Array();
if (syllables != undefined) {
this.syllables = syllables;
this.concat();
}
}
popSyllable() {
this.syllables = this.syllables.slice(0, this.syllables.length - 1);
this.concat();
}
pushSyllable(syllable) {
this.syllables.push(syllable);
this.concat();
}
shiftSyllable() {
const syl = this.syllables.shift();
this.concat();
return syl;
}
unshiftSyllable(syllable) {
const num = this.syllables.unshift(syllable);
this.concat();
return num;
}
replaceSyllable(i, syllable) {
if (i < this.syllables.length) {
this.syllables.splice(i, 1, syllable);
}
this.concat();
}
concat() {
this.literal = this.syllables.map(x => (x ? x.literal : '')).join('');
}
}
exports.TonalWord = TonalWord;
/** A phrase made of words. */
class TonalPhrase extends unit_2.Phrase {
words;
constructor(words) {
super();
this.words = new Array();
if (words) {
this.words = words;
this.concat();
}
}
popWord() {
// get rid off the last word from array
this.words = this.words.slice(0, this.words.length - 1);
this.concat();
}
pushWord(w) {
this.words.push(w);
this.concat();
}
concat() {
if (this.words.length > 0) {
if (this.words.filter(x => x && x.literal.length > 0).length == 0) {
this.literal = '';
}
else
this.literal = this.words.map(x => (x ? x.literal : '')).join(' ');
}
}
}
exports.TonalPhrase = TonalPhrase;
//# sourceMappingURL=unit.js.map