Normalized the natural language input of the recipe #866
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, the recipe converter required users to enter ingredients in a strict, predefined format.
This update introduces an improved natural language preprocessing and normalization layer that
automatically extracts structured ingredient data (quantities, units, and items) from free-form
user input.
Now users can write recipes naturally (e.g. “Add one and a half cups of flour and 2 tablespoons sugar”)
and the system will convert them into the standardized format required for accurate unit conversion.
Please include a summary of the changes and the related issue:
New Functions Added:
normalizeRecipeText() - Main normalization function
normalizeIngredientLine() - Processes individual lines
normalizeNumbers() - Converts word numbers to digits/fractions
normalizeUnits() - Standardizes unit abbreviations
parseIngredientQuantity() - Extracts quantity, unit, and ingredient
cleanIngredientName() - Removes instruction words from ingredients
splitMultipleIngredients() - Handles lines with multiple ingredients
Key Improvements:
Handles multiple input formats:
"2 cups flour" (standard)
"flour 2 tbsp sugar" (ingredient-first)
"Sugar - 1 cup" (punctuation formats)
"mix 2 cups flour" (instruction lines)
"1-2 cups flour" (range quantities)
"one and a half cups milk" (word numbers)
Fixed Instruction Detection
Changes:
Separated instructions into two categories:
Mixing instructions (mix, stir, combine, add) - extract ingredients from these
Cooking instructions (bake, preheat, cook) - skip these completely
Added recursive processing to remove instruction words and extract ingredients
Enhanced Pattern Matching
Added Patterns For:
Range quantities: "1-2 cups" → "1 cup"
Ingredient-first format: "flour 2 tbsp" → "2 tbsp flour"
Instruction lines: "mix 2 cups flour" → "2 cups flour"
Punctuation formats: "Sugar - 1 cup" → "1 cup sugar"
Large ingredients: "2 large eggs" → "2 eggs"
Word numbers: "one and a half" → "1 1/2"
Mixed numbers: "1 1/2 cups" proper parsing
Improved Conversion Database
Added Entries:
Egg variations: 'egg', 'eggs', 'large egg', 'large eggs'
ML conversions: 'ml water', 'ml milk', 'ml oil', 'ml vanilla extract'
Small quantities: Proper teaspoon-based weights for spices
Common ingredients: Added missing entries for better matching
Enhanced Unit Conversions:
Added ML direct conversion (no cup conversion needed)
'milliliter': 'direct', 'milliliters': 'direct', 'ml': 'direct'
5. Better Ingredient Matching Logic
Multiple Matching Strategies:
Exact match - Direct database lookup
Singular version - Remove 's' and try again
Contains match - Database key contained in ingredient
Reverse contains - Ingredient contained in database key
Word-based matching - Split into words and match individually
Comprehensive Error Handling
Added Features:
Debug functions for troubleshooting
Warning system for ambiguous conversions
Better error messages for failed parsing
Fallback logic for unknown ingredients
Test Suite & Debugging
Added Test Functions:
runCompleteTestSuite() - Comprehensive testing
testSpecificCase() - Individual case testing
debugEggIssue(), debugMilkIssue(), debugMLConversion() - Specific debugging
quickProblemTest() - Quick validation of known issues
Key Bug Fixes
Fixed Issues: "flour 2 tbsp sugar mix well" → "2 tbsp flour"
"2-3 eggs" → "2 eggs" (range handling)
"2 large eggs" → proper conversion
"one and a half cups milk" → "1 1/2 cups milk"
"mix 2 cups flour" → "2 cups flour"
"15 ml oil" → proper ML conversion
Punctuation formats (colons, dashes, commas)
Instruction word filtering
Plural/singular matching
Enhanced User Experience
Improvements:
Better normalization - Users can input recipes in various formats
Clearer warnings - Specific information about conversion issues
Comprehensive testing - Ensures all edge cases work
Debug tools - Easy troubleshooting for developers
Result:
The recipe converter now handles virtually any input format users might throw at it, from perfectly structured recipes to messy copy-pasted text with instructions, punctuation, and various formatting styles. The system gracefully normalizes everything into a standard format for accurate conversion.
Type of change
How Has This Been Tested?
Added testing function at the end as well as check by entering on the webpage :


Checklist: