rosaenlg-commons
Version:
Common technical elements for RosaeNLG
68 lines • 2.1 kB
JavaScript
;
/**
* @license
* Copyright 2019 Ludan Stoecklé
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DictManager = void 0;
class DictManager {
constructor(iso2, validPropsWord, validPropsAdj) {
this.iso2 = iso2;
this.validPropsWord = validPropsWord;
this.validPropsAdj = validPropsAdj;
this.wordsData = {};
this.adjsData = {};
}
setEmbeddedWords(embeddedWords) {
this.wordsData = embeddedWords;
}
setEmbeddedAdj(embeddedAdjs) {
this.adjsData = embeddedAdjs;
}
getWordData() {
return this.wordsData;
}
getAdjsData() {
return this.adjsData;
}
getAdjsWordsData() {
return Object.assign(Object.assign({}, this.adjsData), this.wordsData);
}
isValidPropWord(prop) {
return this.validPropsWord.indexOf(prop) > -1;
}
isValidPropAdj(prop) {
return this.validPropsAdj.indexOf(prop) > -1;
}
checkProp(type, prop) {
if ((type === 'word' && !this.isValidPropWord(prop)) || (type === 'adj' && !this.isValidPropAdj(prop))) {
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `invalid property ${prop} as ${type} in ${this.iso2}`;
throw err;
}
}
setAdjData(adj, adjData) {
if (!this.adjsData[adj]) {
this.adjsData[adj] = {}; // not a direct copy, we want to check the keys
}
const keys = Object.keys(adjData);
for (const key of keys) {
this.checkProp('adj', key);
this.adjsData[adj][key] = adjData[key];
}
}
setWordData(word, wordData) {
if (!this.wordsData[word]) {
this.wordsData[word] = {};
}
const keys = Object.keys(wordData);
for (const key of keys) {
this.checkProp('word', key);
this.wordsData[word][key] = wordData[key];
}
}
}
exports.DictManager = DictManager;
//# sourceMappingURL=DictManager.js.map