UNPKG

rosaenlg-filter

Version:

Filtering feature of RosaeNLG

39 lines 1.34 kB
"use strict"; /** * @license * Copyright 2019 Ludan Stoecklé * SPDX-License-Identifier: Apache-2.0 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.protectBlocks = exports.unprotect = exports.ProtectMapping = void 0; class ProtectMapping { constructor(protectedString, mappings) { this.protectedString = protectedString; this.mappings = mappings; } } exports.ProtectMapping = ProtectMapping; function unprotect(toUnprotect, mappings) { let res = toUnprotect; for (const key in mappings) { // we also just delete all the unnecessary special spaces const specialSpaces = /¤/g; res = res.replace(key, mappings[key].replace(specialSpaces, '')); } return res; } exports.unprotect = unprotect; function protectBlocks(input) { const regexProtect = /§([^§]*)§/g; const mappings = {}; let index = 0; const protectedInput = input.replace(regexProtect, function (corresp, first) { // must not start with E otherwise creates issues with French constractions: d'ESCAPED const replacement = 'XESCAPED_SEQ_' + ++index; mappings[replacement] = first; return replacement; }); return new ProtectMapping(protectedInput, mappings); } exports.protectBlocks = protectBlocks; //# sourceMappingURL=protect.js.map