Skip to content

Commit

Permalink
remove html blocks inside more researches
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnieszka Szuba committed May 16, 2023
1 parent f90c4a9 commit afecbd5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @module analyses/getKeywordDensity */

import countWords from "../helpers/word/countWords.js";
import removeHtmlBlocks from "../helpers/html/htmlParser";

/**
* Calculates the keyword density.
Expand All @@ -12,7 +13,9 @@ import countWords from "../helpers/word/countWords.js";
*/
export default function( paper, researcher ) {
const getWordsCustomHelper = researcher.getHelper( "getWordsCustomHelper" );
let wordCount = countWords( paper.getText() );
let text = paper.getText();
text = removeHtmlBlocks( text );
let wordCount = countWords( text );

// If there is a custom getWords helper use its output for countWords.
if ( getWordsCustomHelper ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import AssessmentResult from "../../../values/AssessmentResult";
import { inRangeEndInclusive, inRangeStartEndInclusive, inRangeStartInclusive } from "../../helpers/assessments/inRange";
import { createAnchorOpeningTag } from "../../../helpers/shortlinker";
import keyphraseLengthFactor from "../../helpers/assessments/keyphraseLengthFactor.js";
import removeHtmlBlocks from "../../../languageProcessing/helpers/html/htmlParser";

/**
* Represents the assessment that will look if the keyphrase density is within the recommended range.
Expand Down Expand Up @@ -110,7 +111,9 @@ class KeywordDensityAssessment extends Assessment {

this._hasMorphologicalForms = researcher.getData( "morphology" ) !== false;

this.setBoundaries( paper.getText(), keyphraseLength, customGetWords );
let text = paper.getText();
text = removeHtmlBlocks( text );
this.setBoundaries( text, keyphraseLength, customGetWords );

this._keywordDensity = this._keywordDensity * keyphraseLengthFactor( keyphraseLength );
const calculatedScore = this.calculateResult();
Expand Down Expand Up @@ -328,7 +331,9 @@ class KeywordDensityAssessment extends Assessment {
if ( customApplicabilityConfig ) {
this._config.applicableIfTextLongerThan = customApplicabilityConfig;
}
const textLength = customCountLength ? customCountLength( paper.getText() ) : researcher.getResearch( "wordCountInText" ).count;
let text = paper.getText();
text = removeHtmlBlocks( text );
const textLength = customCountLength ? customCountLength( text ) : researcher.getResearch( "wordCountInText" ).count;

return paper.hasText() && paper.hasKeyword() && textLength >= this._config.applicableIfTextLongerThan;
}
Expand Down

0 comments on commit afecbd5

Please sign in to comment.