Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes degraded performance of content analysis #21474

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@ import { findTopicFormsInString } from "../helpers/match/findKeywordFormsInStrin
*
* @param {string} currentSentence The current sentence.
* @param {Researcher} researcher The researcher object.
* @param {Object} topicForms The object with word forms of all (content) words from the keyphrase and eventually synonyms,
* comes in a shape {
* keyphraseForms: [[ form1, form2, ... ], [ form1, form2, ... ]],
* synonymsForms: [
* [[ form1, form2, ... ], [ form1, form2, ... ]],
* [[ form1, form2, ... ], [ form1, form2, ... ]],
* [[ form1, form2, ... ], [ form1, form2, ... ]],
* ],
* }
*
* @returns {ComplexWordsResult} An object containing all complex words in a given sentence.
*/
const getComplexWords = function( currentSentence, researcher ) {
const getComplexWords = function( currentSentence, researcher, topicForms ) {
const language = researcher.getConfig( "language" );
const checkIfWordIsComplex = researcher.getHelper( "checkIfWordIsComplex" );
const functionWords = researcher.getConfig( "functionWords" );
Expand All @@ -41,7 +50,6 @@ const getComplexWords = function( currentSentence, researcher ) {
let words = getWords( currentSentence );

// Filters out keyphrase forms (but not synonyms) because we consider them not to be complex.
const topicForms = researcher.getResearch( "morphology" );
const matchWordCustomHelper = researcher.getHelper( "matchWordCustomHelper" );
const foundTopicForms = findTopicFormsInString( topicForms, currentSentence, false, researcher.paper.getLocale(), matchWordCustomHelper );
words = words.filter( word => ! foundTopicForms.matches.includes( word ) );
Expand Down Expand Up @@ -102,8 +110,9 @@ export default function wordComplexity( paper, researcher ) {
text = filterShortcodesFromHTML( text, paper._attributes && paper._attributes.shortcodes );
const sentences = getSentences( text, memoizedTokenizer );

const topicForms = researcher.getResearch( "morphology" );
// Find the complex words in each sentence.
let results = sentences.map( sentence => getComplexWords( sentence, researcher ) );
let results = sentences.map( sentence => getComplexWords( sentence, researcher, topicForms ) );

// Remove sentences without complex words.
results = results.filter( result => result.complexWords.length !== 0 );
Expand Down
Loading