morph-it-helper
Version:
Helper functions on an included database derived from morph-it (Free Morphological Lexicon for the Italian Language)
56 lines • 1.72 kB
JavaScript
;
/**
* @license
* Copyright 2019 Ludan Stoecklé
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MorphItHelper = void 0;
const fs_1 = require("fs");
class MorphItHelper {
constructor() {
this.adjectives = null;
this.nouns = null;
this.pastParticiples = null;
}
isAdj(flexform) {
return this.getAdj(flexform) != null;
}
isNoun(flexform) {
return this.getNoun(flexform) != null;
}
getNoun(param) {
if (!this.nouns) {
this.nouns = JSON.parse((0, fs_1.readFileSync)(__dirname + '/../resources_pub/nouns.json', 'utf8'));
}
return this.nouns[param];
}
getAdj(param) {
if (!this.adjectives) {
this.adjectives = JSON.parse((0, fs_1.readFileSync)(__dirname + '/../resources_pub/adjectives.json', 'utf8'));
}
const adjectiveInfo = this.adjectives[param];
if (!adjectiveInfo) {
return undefined;
}
const lemma = adjectiveInfo[0];
const isPp = adjectiveInfo[1];
if (isPp) {
/*
educato educare VER:part+past+s+m
educati educare VER:part+past+p+m
educata educare VER:part+past+s+f
*/
if (!this.pastParticiples) {
this.pastParticiples = JSON.parse((0, fs_1.readFileSync)(__dirname + '/../resources_pub/pastParticiples.json', 'utf8'));
}
return this.pastParticiples[lemma];
}
else {
// all good
return lemma;
}
}
}
exports.MorphItHelper = MorphItHelper;
//# sourceMappingURL=index.js.map