UNPKG

yoastseo

Version:

Yoast client-side content analysis

60 lines (56 loc) 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getKeyphraseDensity; exports.getKeywordDensity = getKeywordDensity; var _getAllWordsFromTree = _interopRequireDefault(require("../helpers/word/getAllWordsFromTree")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * @typedef {import("../../languageProcessing/AbstractResearcher").default } Researcher * @typedef {import("../../values/").Paper } Paper */ /** * Calculates the keyphrase density. * * @param {Paper} paper The paper containing keyphrase and text. * @param {Researcher} researcher The researcher. * * @returns {{density: number, textLength: number}} The keyphrase density and text length. */ function getKeyphraseDensity(paper, researcher) { const getWordsCustomHelper = researcher.getHelper("getWordsCustomHelper"); let wordCount = 0; // If there is a custom getWords helper, use its output for countWords. if (getWordsCustomHelper) { wordCount = getWordsCustomHelper(paper.getText()).length; } else { wordCount = (0, _getAllWordsFromTree.default)(paper).length; } if (wordCount === 0) { return { density: 0, textLength: 0 }; } const keyphraseCount = researcher.getResearch("getKeyphraseCount"); return { density: keyphraseCount.count / wordCount * 100, textLength: wordCount }; } /** * Calculates the keyphrase density. * * @deprecated Use getKeyphraseDensity instead. * * @param {Paper} paper The paper containing keyphrase and text. * @param {Researcher} researcher The researcher. * * @returns {{density: number, textLength: number}} The keyphrase density and text length. */ function getKeywordDensity(paper, researcher) { console.warn("This function is deprecated, use getKeyphraseDensity instead."); return getKeyphraseDensity(paper, researcher); } //# sourceMappingURL=getKeywordDensity.js.map