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 running researches that require a tree in the experimental content analysis API #21957

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
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,
};
Loading