yoastseo
Version:
Yoast client-side content analysis
43 lines (41 loc) • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isPassiveSentence;
var _yoastseo = require("yoastseo");
var _nonPassiveVerbStems = _interopRequireDefault(require("../config/internal/nonPassiveVerbStems"));
var _morphologicalPassiveSuffixes = require("../config/internal/morphologicalPassiveSuffixes.js");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const {
getWords,
directPrecedenceException
} = _yoastseo.languageProcessing;
const directPrecedenceExceptionList = ["να"];
/**
* Checks the passed sentence to see if it contains Greek passive verb-forms.
*
* @param {string} sentence The sentence to match against.
*
* @returns {Boolean} Whether the sentence is passive or not.
*/
function isPassiveSentence(sentence) {
const words = getWords(sentence);
for (const word of words) {
for (const suffix of _morphologicalPassiveSuffixes.passiveSuffixes) {
if (word.endsWith(suffix) && word.length > 4) {
// Get the stem of the word.
const stem = word.slice(0, -suffix.length);
/*
* Return true if the word ends with one of the passive suffixes, if the word is more than 4 characters long
* And if the word stem is not in the non-passive exception list.
*
* Passive infinitive with -θεί/-τεί is not a valid passive if it's directly preceded by "να".
*/
return /^(θεί|τεί)$/.test(suffix) ? !_nonPassiveVerbStems.default.includes(stem) && !directPrecedenceException(sentence, word, directPrecedenceExceptionList) : !_nonPassiveVerbStems.default.includes(stem);
}
}
}
return false;
}
//# sourceMappingURL=isPassiveSentence.js.map