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

4475 fix related keyphrase status #21941

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
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
@@ -0,0 +1,127 @@
import { RelatedKeywordScoreAggregator } from "../../../src/scoring/scoreAggregators";
import AssessmentResult from "../../../src/values/AssessmentResult";

describe( "RelatedKeywordScoreAggregator", () => {
let aggregator;

beforeEach( () => {
aggregator = new RelatedKeywordScoreAggregator();
} );

describe( "aggregate", () => {
it( "returns score 0 with default assessment results", () => {
const results = [
new AssessmentResult(),
new AssessmentResult(),
];
const score = aggregator.aggregate( results );
expect( score ).toBe( 0 );
} );

it( "returns score 0 without assessment results", () => {
const results = [];
const score = aggregator.aggregate( results );
expect( score ).toBe( 0 );
} );

it( "returns score 100 with only score 9 assessment results", () => {
const results = [
new AssessmentResult( { score: 9 } ),
new AssessmentResult( { score: 9 } ),
new AssessmentResult( { score: 9 } ),
new AssessmentResult( { score: 9 } ),
];
const score = aggregator.aggregate( results );
expect( score ).toBe( 100 );
} );

it( "returns score 89 with only score 8 assessment results", () => {
const results = [
new AssessmentResult( { score: 8 } ),
new AssessmentResult( { score: 8 } ),
new AssessmentResult( { score: 8 } ),
];
const score = aggregator.aggregate( results );
expect( score ).toBe( 89 );
} );

it( "returns score 67 with only score 6 assessment results", () => {
const results = [
new AssessmentResult( { score: 6 } ),
new AssessmentResult( { score: 6 } ),
new AssessmentResult( { score: 6 } ),
new AssessmentResult( { score: 6 } ),
new AssessmentResult( { score: 6 } ),
new AssessmentResult( { score: 6 } ),
];
const score = aggregator.aggregate( results );
expect( score ).toBe( 67 );
} );

it( "returns score 33 with only score 3 assessment results", () => {
const results = [
new AssessmentResult( { score: 3 } ),
new AssessmentResult( { score: 3 } ),
new AssessmentResult( { score: 3 } ),
new AssessmentResult( { score: 3 } ),
new AssessmentResult( { score: 3 } ),
new AssessmentResult( { score: 3 } ),
new AssessmentResult( { score: 3 } ),
new AssessmentResult( { score: 3 } ),
new AssessmentResult( { score: 3 } ),
new AssessmentResult( { score: 3 } ),
new AssessmentResult( { score: 3 } ),
new AssessmentResult( { score: 3 } ),
];
const score = aggregator.aggregate( results );
expect( score ).toBe( 33 );
} );

it( "returns score 11 with only score 1 assessment results", () => {
const results = [
new AssessmentResult( { score: 1 } ),
new AssessmentResult( { score: 1 } ),
];
const score = aggregator.aggregate( results );
expect( score ).toBe( 11 );
} );

it( "returns score as expected with combined assessment results", () => {
const results = [
new AssessmentResult( { score: 1 } ),
new AssessmentResult( { score: 2 } ),
new AssessmentResult( { score: 3 } ),
new AssessmentResult( { score: 4 } ),
new AssessmentResult( { score: 5 } ),
new AssessmentResult( { score: 6 } ),
new AssessmentResult( { score: 7 } ),
new AssessmentResult( { score: 8 } ),
new AssessmentResult( { score: 9 } ),
];
const score = aggregator.aggregate( results );
expect( score ).toBe( 56 );
} );

it( "returns score as expected with combined assessment results - part 2", () => {
const results = [
new AssessmentResult( { score: 5 } ),
new AssessmentResult( { score: 4 } ),
new AssessmentResult( { score: 8 } ),
];
const score = aggregator.aggregate( results );
expect( score ).toBe( 63 );
} );

it( "exclude assessments without score from aggregator", () => {
const results = [
new AssessmentResult( { score: 5 } ),
new AssessmentResult(),
new AssessmentResult( { score: 4 } ),
new AssessmentResult( { score: 8 } ),
new AssessmentResult(),
];
const score = aggregator.aggregate( results );
expect( score ).toBe( 63 );
} );
} );
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import SEOScoreAggregator from "./SEOScoreAggregator";

/**
* Aggregates SEO assessment results into a single score.
*
* @memberOf module:parsedPaper/assess
*/
class RelatedKeywordScoreAggregator extends SEOScoreAggregator {
/**
* Returns the list of valid results.
* Valid results are all results that have a score.
*
* @param {AssessmentResult[]} results The results to filter the valid results from.
*
* @returns {AssessmentResult[]} The list of valid results.
*/
getValidResults( results ) {
return results.filter( result => result.hasScore() );
}

/**
* Aggregates the given assessment results into a single score.
*
* @param {AssessmentResult[]} results The assessment results.
*
* @returns {number} The aggregated score.
*/
aggregate( results ) {
const validResults = this.getValidResults( results );

return super.aggregate( validResults );
}
}

export default RelatedKeywordScoreAggregator;
1 change: 1 addition & 0 deletions packages/yoastseo/src/scoring/scoreAggregators/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as ReadabilityScoreAggregator } from "./ReadabilityScoreAggregator";
export { default as RelatedKeywordScoreAggregator } from "./RelatedKeywordScoreAggregator";
export { default as ScoreAggregator } from "./ScoreAggregator";
export { default as SEOScoreAggregator } from "./SEOScoreAggregator";
5 changes: 3 additions & 2 deletions packages/yoastseo/src/worker/AnalysisWebWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import SEOAssessor from "../scoring/assessors/seoAssessor.js";
import TaxonomyAssessor from "../scoring/assessors/taxonomyAssessor.js";

// Tree assessor functionality.
import { ReadabilityScoreAggregator, SEOScoreAggregator } from "../scoring/scoreAggregators";
import { ReadabilityScoreAggregator, SEOScoreAggregator, RelatedKeywordScoreAggregator } from "../scoring/scoreAggregators";

const logger = getLogger( "yoast-analysis-worker" );
logger.setDefaultLevel( "error" );
Expand Down Expand Up @@ -313,6 +313,7 @@ export default class AnalysisWebWorker {
// Score aggregators
this._seoScoreAggregator = new SEOScoreAggregator();
this._contentScoreAggregator = new ReadabilityScoreAggregator();
this._relatedKeywordScoreAggregator = new RelatedKeywordScoreAggregator();

// Tree representation of text to analyze
this._tree = null;
Expand Down Expand Up @@ -1241,7 +1242,7 @@ export default class AnalysisWebWorker {
const analysisCombination = {
oldAssessor: this._relatedKeywordAssessor,
treeAssessor: this._relatedKeywordTreeAssessor,
scoreAggregator: this._seoScoreAggregator,
scoreAggregator: this._relatedKeywordScoreAggregator,
};

// We need to remember the key, since the SEO results are stored in an object, not an array.
Expand Down
Loading