Skip to content

Fixed how the spoonacular api call parses through the data#154

Merged
Adish-Singh merged 1 commit intomainfrom
149-fix-the-how-the-steps-are-processed-by-the-api
Dec 2, 2025
Merged

Fixed how the spoonacular api call parses through the data#154
Adish-Singh merged 1 commit intomainfrom
149-fix-the-how-the-steps-are-processed-by-the-api

Conversation

@Adish-Singh
Copy link
Copy Markdown
Collaborator

Overview
Fixed an issue in FindInstructionsSpoonacular where the API returned abnormally long instruction steps that were difficult to read. The parser now splits steps into individual sentences for better readability.

Files Modified
FindInstructionsSpoonacular.java

Problem
The Spoonacular API sometimes returns very long instruction steps that combine multiple sentences into a single step. For example:
Mix the wet ingredients, warm the liquid either in the microwave (about 40 seconds) or on the stovetop you want the temperature to be that of a hot bath.Slowly incorporate the liquid into the dry ingredients while stirring.When you can stir no more, start to knead the dough with your hands.

Solution
Modified the parsing logic to split steps by sentences using regex pattern matching:
Splits on periods, exclamation marks, or question marks followed by a capital letter
Handles edge cases where punctuation is missing (e.g., "bath.Slowly" with no space)
Uses \s* to match zero or more spaces after punctuation

Testing
Manually tested with recipes containing long multi-sentence steps. Confirmed proper splitting at sentence boundaries.

@Adish-Singh Adish-Singh linked an issue Dec 2, 2025 that may be closed by this pull request

if (!stepText.isEmpty()) {
steps.add(new InstructionStep(number, stepText));
// Split by: period/!/? followed by space + capital OR capital letter after lowercase (missing punctuation)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck> reported by reviewdog 🐶
Line is longer than 120 characters (found 127).

if (!stepText.isEmpty()) {
steps.add(new InstructionStep(number, stepText));
// Split by: period/!/? followed by space + capital OR capital letter after lowercase (missing punctuation)
String[] sentences = stepText.split("(?<=[.!?])\\s*(?=[A-Z])");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.coding.FinalLocalVariableCheck> reported by reviewdog 🐶
Variable 'sentences' should be declared final.

// Split by: period/!/? followed by space + capital OR capital letter after lowercase (missing punctuation)
String[] sentences = stepText.split("(?<=[.!?])\\s*(?=[A-Z])");
for (String sentence : sentences) {
String trimmed = sentence.trim();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [checkstyle] <com.puppycrawl.tools.checkstyle.checks.coding.FinalLocalVariableCheck> reported by reviewdog 🐶
Variable 'trimmed' should be declared final.

Copy link
Copy Markdown
Collaborator

@hussssni hussssni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice watch out for checkstyle

@Adish-Singh Adish-Singh merged commit ea7a22c into main Dec 2, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix the how the steps are processed by the api

2 participants