Skip to content

Conversation

jiyak2804
Copy link
Contributor

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:

  1. Enhanced Recipe Normalization System
    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)

  1. 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

  2. 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

  3. 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

  1. 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

  2. Test Suite & Debugging
    Added Test Functions:
    runCompleteTestSuite() - Comprehensive testing
    testSpecificCase() - Individual case testing
    debugEggIssue(), debugMilkIssue(), debugMLConversion() - Specific debugging
    quickProblemTest() - Quick validation of known issues

  3. 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

  4. 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

  • Bug fix
  • New feature
  • [done ] Improvement
  • Documentation update

How Has This Been Tested?

Added testing function at the end as well as check by entering on the webpage :
Screenshot 2025-10-08 223021
Screenshot 2025-10-08 223054

Checklist:

  • [done ] My code follows the style guidelines of this project
  • [done ] I have performed a self-review of my code
  • [done ] I have commented my code where necessary
  • [done ] I have added tests that prove my fix is effective or that my feature works
  • I have made corresponding changes to the documentation

Copy link

github-actions bot commented Oct 8, 2025

Thanks for creating a PR for your Issue! ☺️

We'll review it as soon as possible.
In the meantime, please double-check the file changes and ensure that all commits are accurate.

If there are any unresolved review comments, feel free to resolve them. 🙌🏼

@supriya46788 supriya46788 merged commit 4b7fd36 into supriya46788:main Oct 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants