UNPKG

yoastseo

Version:

Yoast client-side content analysis

53 lines (49 loc) 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = isPassiveSentence; var _yoastseo = require("yoastseo"); var _odikVerbs = _interopRequireDefault(require("../config/internal/odikVerbs")); var _morphologicalPassiveAffixes = require("../config/internal/morphologicalPassiveAffixes"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const { getWords } = _yoastseo.languageProcessing; /** * Checks if the input word's root is in the Hungarian verb roots list. * * @param {string} word The word to check. * @param {string[]} verbRootsList The Hungarian verb roots list. * @param {string[]} prefixes The list of prefixes. * @param {string[]} suffixes The list of suffixes. * * @returns {Boolean} Returns true if the root of the input word is in the list. */ const checkHungarianPassive = function (word, verbRootsList, prefixes, suffixes) { return verbRootsList.some(root => { return suffixes.some(function (suffix) { const rootAndSuffix = root + suffix; // Check whether the word ends in a root + suffix combination. if (word.endsWith(rootAndSuffix)) { const beforeRoot = word.slice(0, word.indexOf(rootAndSuffix)); // Word is passive if nothing precedes the root or the root is preceded by a valid prefix. return beforeRoot === "" || prefixes.includes(beforeRoot); } }); }); }; /** * Checks the passed sentence to see if it contains Hungarian passive verb-forms. * * @param {string} sentence The sentence to match against. * * @returns {Boolean} Whether the sentence contains Hungarian passive voice. */ function isPassiveSentence(sentence) { const words = getWords(sentence); const passiveVerbs1 = _odikVerbs.default.odikVerbStems1; const passiveVerbs2 = _odikVerbs.default.odikVerbStems2; return words.some(word => checkHungarianPassive(word, passiveVerbs1, _morphologicalPassiveAffixes.verbPrefixes, _morphologicalPassiveAffixes.odikSuffixes1) || checkHungarianPassive(word, passiveVerbs2, _morphologicalPassiveAffixes.verbPrefixes, _morphologicalPassiveAffixes.odikSuffixes2)); } //# sourceMappingURL=isPassiveSentence.js.map