yoastseo
Version:
Yoast client-side content analysis
58 lines (55 loc) • 2.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getEnglishClauses;
var _yoastseo = require("yoastseo");
var _Clause = _interopRequireDefault(require("../values/Clause"));
var _passiveVoiceAuxiliaries = _interopRequireDefault(require("../config/internal/passiveVoiceAuxiliaries.js"));
var _stopWords = _interopRequireDefault(require("../config/stopWords.js"));
var _lodash = require("lodash");
var _stripSpaces = _interopRequireDefault(require("../../../helpers/sanitize/stripSpaces"));
var _indices = require("../../../helpers/word/indices");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const {
createRegexFromArray,
getClauses
} = _yoastseo.languageProcessing;
const options = {
Clause: _Clause.default,
stopwords: _stopWords.default,
auxiliaries: _passiveVoiceAuxiliaries.default,
ingExclusions: ["king", "cling", "ring", "being", "thing", "something", "anything"],
regexes: {
auxiliaryRegex: createRegexFromArray(_passiveVoiceAuxiliaries.default),
stopCharacterRegex: /([:,]|('ll)|('ve))(?=[ \n\r\t'"+\-»«‹›<>])/ig,
verbEndingInIngRegex: /\w+ing(?=$|[ \n\r\t.,'()"+\-;!?:/»«‹›<>])/ig
},
otherStopWordIndices: []
};
/**
* Gets active verbs (ending in ing) to determine sentence breakers in English.
*
* @param {string} sentence The sentence to get the active verbs from.
*
* @returns {Array} The array with valid matches.
*/
const getVerbsEndingInIngIndices = function (sentence) {
// Matches the sentences with words ending in ing.
let matches = sentence.match(options.regexes.verbEndingInIngRegex) || [];
// Filters out words ending in -ing that aren't verbs.
matches = matches.filter(match => !(0, _lodash.includes)(options.ingExclusions, (0, _stripSpaces.default)(match)));
return (0, _indices.getIndicesByWordList)(matches, sentence);
};
/**
* Gets the clauses from a sentence by determining sentence breakers.
*
* @param {string} sentence The sentence to split up in clauses.
*
* @returns {Array} The array with all clauses that have an auxiliary.
*/
function getEnglishClauses(sentence) {
options.otherStopWordIndices = getVerbsEndingInIngIndices(sentence);
return getClauses(sentence, options);
}
//# sourceMappingURL=getClauses.js.map