UNPKG

@botonic/plugin-contentful

Version:

Botonic Plugin Contentful is one of the **[available](https://github.com/hubtype/botonic/tree/master/packages)** plugins for Botonic. **[Contentful](http://www.contentful.com)** is a CMS (Content Management System) which manages contents of a great variet

61 lines 1.96 kB
"use strict"; // From http://nlp.ffzg.hr/resources/tools/stemmer-for-croatian/ Object.defineProperty(exports, "__esModule", { value: true }); exports.StemmerHr = void 0; const stopwords_hr_1 = require("../stopwords/stopwords-hr"); const rules_hr_1 = require("./rules/rules-hr"); const transformations_hr_1 = require("./transformations/transformations-hr"); class StemmerHr { stem(tokens) { return tokens.map(token => this.stemToken(token)); } stemToken(token) { if (this.isStopWord(token)) { return token; } else { return this.getRoot(this.transform(token)); } } isStopWord(token) { return stopwords_hr_1.hrDefaultStopWords.indexOf(token) != -1; } transform(token) { for (const replacement in transformations_hr_1.hrTransformations) { const targets = transformations_hr_1.hrTransformations[replacement]; for (const target of targets) { if (token.endsWith(target)) { return token.replace(target, replacement); } } } return token; } getRoot(token) { for (const rule of rules_hr_1.hrRules) { const match = new RegExp(rule).exec(token); if (match) { const root = match[1]; if (this.containsVocal(root) && root.length > 1) { return root; } } } return token; } containsVocal(token) { token = this.highlightRSyllable(token); if (token.search(/[aeiouR]/) == undefined) { return false; } else { return true; } } highlightRSyllable(token) { // eslint-disable-next-line no-useless-escape return token.replace(/(^|[^aeiou])r($|[^aeiou])/gm, `\$1R\$2`); } } exports.StemmerHr = StemmerHr; //# sourceMappingURL=stemmer-hr.js.map