UNPKG

yoastseo

Version:

Yoast client-side content analysis

45 lines (42 loc) 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _lodash = require("lodash"); var _determineProminentWords = require("../helpers/prominentWords/determineProminentWords"); var _removeURLs = _interopRequireDefault(require("../helpers/sanitize/removeURLs.js")); var _removeEmailAddresses = _interopRequireDefault(require("../helpers/sanitize/removeEmailAddresses")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * Retrieves the prominent words from the given paper. * * @param {Paper} paper The paper to determine the prominent words of. * @param {Researcher} researcher The researcher to use for analysis. * * @returns {WordCombination[]} Prominent words for this paper, filtered and sorted. */ function getProminentWordsForInsights(paper, researcher) { const functionWords = researcher.getConfig("functionWords"); // An optional custom helper to return custom function to return the stem of a word. const customStemmer = researcher.getHelper("customGetStemmer"); const stemmer = customStemmer ? customStemmer(researcher) : researcher.getHelper("getStemmer")(researcher); // An optional custom helper to get words from the text. const getWordsCustomHelper = researcher.getHelper("getWordsCustomHelper"); let text = paper.getText(); // We don't want to include URLs or email addresses in prominent words. text = (0, _removeURLs.default)(text); text = (0, _removeEmailAddresses.default)(text); // If the language has a custom helper to get words from the text, we don't retrieve the abbreviation. const abbreviations = getWordsCustomHelper ? [] : (0, _determineProminentWords.retrieveAbbreviations)(text); const prominentWordsFromText = (0, _determineProminentWords.getProminentWords)(text, abbreviations, stemmer, functionWords, getWordsCustomHelper); const collapsedWords = (0, _determineProminentWords.collapseProminentWordsOnStem)(prominentWordsFromText); (0, _determineProminentWords.sortProminentWords)(collapsedWords); /* * Collapse the list of prominent words on stems, sort it, filter out all words that occur less than * 5 times in the text. Return the 20 top items from this list. */ return (0, _lodash.take)((0, _determineProminentWords.filterProminentWords)(collapsedWords, 5), 20); } var _default = exports.default = getProminentWordsForInsights; //# sourceMappingURL=getProminentWordsForInsights.js.map