rosaenlg-filter
Version:
Filtering feature of RosaeNLG
63 lines • 2.24 kB
JavaScript
;
/**
* @license
* Copyright 2019 Ludan Stoecklé
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.LanguageFilter = void 0;
class LanguageFilter {
constructor(languageCommon) {
this.cleanSpacesPunctuationDoDefault = null;
this.languageCommon = languageCommon;
this.dictManager = languageCommon.dictManager;
this.constants = languageCommon.constants;
}
contractions(input) {
return input;
}
beforeProtect(input) {
return input;
}
justBeforeUnprotect(input) {
return input;
}
titlecase(_input) {
const err = new Error();
err.name = 'InvalidArgumentError';
err.message = `titlecase is not available for ${this.languageCommon.getIso2()}`;
throw err;
}
cleanSpacesPunctuation(input) {
return input;
}
// correct things, at the end of the cleaning spaces and punctuation process
cleanSpacesPunctuationCorrect(input) {
return input;
}
addCapsSpecific(input) {
return input;
}
/*
French: de + le => du
Spanish: de + el => del
*/
contract2elts(rawFirstPart, secondPart, replacer, input) {
// de => [d|D]e
const firstPart = `[${rawFirstPart.substring(0, 1)}|${rawFirstPart
.substring(0, 1)
.toUpperCase()}]${rawFirstPart.substring(1)}`;
const regexContr = new RegExp(`${this.constants.stdBeforeWithParenthesis}(${firstPart})${this.constants.stdBetweenWithParenthesis}${secondPart}${this.constants.stdBetweenWithParenthesis}`, 'g');
/*
something like:
/([\s¤☛☚☞☜\.:!\?;,…])([à|À])([\s¤☞☜]+|$)lesquels([\s¤☞☜]+|$)/g
*/
return input.replace(regexContr, function (match, before, part1, between, after) {
const isUc = part1.substring(0, 1).toLowerCase() != part1.substring(0, 1);
const newDet = isUc ? replacer.substring(0, 1).toUpperCase() + replacer.substring(1) : replacer;
return `${before}${newDet}${between}${after}`;
});
}
}
exports.LanguageFilter = LanguageFilter;
//# sourceMappingURL=LanguageFilter.js.map