Skip to content

Commit

Permalink
Merge pull request #21957 from Yoast/fix/content-analysis-api-research
Browse files Browse the repository at this point in the history
Fixes running researches that require a tree in the experimental content analysis API
  • Loading branch information
agnieszkaszuba authored Jan 9, 2025
2 parents 3557750 + f241b02 commit abf031a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions apps/content-analysis-api/routes/research.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { Paper } = require( "yoastseo" );
const { build } = require( "yoastseo/build/parse/build" );
const { LanguageProcessor } = require( "yoastseo/build/parse/language" );
const { getResearcher } = require( "../helpers/get-researcher" );

module.exports = function( app ) {
Expand Down Expand Up @@ -45,10 +47,11 @@ module.exports = function( app ) {
request.body.text || "",
request.body || {}
);
paper.setTree( build( paper, new LanguageProcessor( researcher ), paper._attributes && paper._attributes.shortcodes ) );
researcher.setPaper( paper );
const sentenceLengths = researcher.getResearch( "countSentencesFromText" );

const responseBody = sentenceLengths.map( sentence => ( { sentence: sentence.sentence, length: sentence.sentenceLength } ) );
const responseBody = sentenceLengths.map( sentence => ( { sentence: sentence.sentence.text, length: sentence.sentenceLength } ) );
response.json( responseBody );
} );

Expand All @@ -59,10 +62,11 @@ module.exports = function( app ) {
request.body.text || "",
request.body || {}
);
paper.setTree( build( paper, new LanguageProcessor( researcher ), paper._attributes && paper._attributes.shortcodes ) );
researcher.setPaper( paper );
const paragraphLengths = researcher.getResearch( "getParagraphLength" );

const responseBody = paragraphLengths.map( paragraph => ( { paragraph: paragraph.text, length: paragraph.countLength } ) );
const responseBody = paragraphLengths.map( paragraph => ( { length: paragraph.paragraphLength } ) );
response.json( responseBody );
} );
}
3 changes: 1 addition & 2 deletions packages/yoastseo/src/parse/language/LanguageProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const whitespaceRegex = /^\s+$/;
/**
* Contains language-specific logic for splitting a text into sentences and tokens.
*/
class LanguageProcessor {
export default class LanguageProcessor {
/**
* Creates a new language processor.
*
Expand Down Expand Up @@ -71,4 +71,3 @@ class LanguageProcessor {
return tokenTexts.map( tokenText => new Token( tokenText ) );
}
}
export default LanguageProcessor;
5 changes: 5 additions & 0 deletions packages/yoastseo/src/parse/language/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import LanguageProcessor from "./LanguageProcessor";

export {
LanguageProcessor,
};

0 comments on commit abf031a

Please sign in to comment.