yoastseo
Version:
Yoast client-side content analysis
57 lines (54 loc) • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _lodash = require("lodash");
var _parseSynonyms = _interopRequireDefault(require("../../../helpers/sanitize/parseSynonyms"));
var _getContentWords = _interopRequireDefault(require("../helpers/getContentWords"));
var _createWordForms = _interopRequireDefault(require("../helpers/internal/createWordForms"));
var _doubleQuotes = _interopRequireDefault(require("../../../helpers/sanitize/doubleQuotes"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* Creates word forms for each word in the given keyphrase.
*
* @param {string} keyphrase The keyphrase to generate word forms for.
* @param {Researcher} researcher The researcher.
*
* @returns {Array<string[]>} The word forms for each word in the keyphrase.
*/
function getKeyphraseForms(keyphrase, researcher) {
// The keyphrase is in double quotes: use it as an exact match keyphrase.
if (_doubleQuotes.default.includes(keyphrase[0]) && _doubleQuotes.default.includes(keyphrase[keyphrase.length - 1])) {
return [[keyphrase]];
}
const keyphraseWords = (0, _getContentWords.default)(keyphrase);
// If the keyphrase does not contain content words, return an empty list.
if (keyphraseWords.length === 0) {
return [[]];
}
const morphologyData = (0, _lodash.get)(researcher.getData("morphology"), "ja", false);
return keyphraseWords.map(word => morphologyData ? (0, _createWordForms.default)(word, morphologyData) : [word]);
}
/**
* Gets all matching word forms for the keyphrase and synonyms.
*
* @param {Paper} paper The paper.
* @param {Researcher} researcher The researcher.
*
* @returns {Object} Object with an array of keyphrase forms and an array of arrays of synonyms forms, based on the forms
* found in the text or created forms.
*/
function _default(paper, researcher) {
let keyphrase = paper.getKeyword().toLocaleLowerCase("ja").trim();
// Remove spaces from the keyphrase.
keyphrase = keyphrase.replace(/\s/g, "");
const synonyms = (0, _parseSynonyms.default)(paper.getSynonyms().toLocaleLowerCase("ja").trim());
const keyphraseForms = getKeyphraseForms(keyphrase, researcher);
const synonymsForms = synonyms.map(synonym => getKeyphraseForms(synonym, researcher));
return {
keyphraseForms,
synonymsForms
};
}
//# sourceMappingURL=getWordForms.js.map