Skip to content

Webtools parser does not support CompositeIngredientAmount #42

@strangetom

Description

@strangetom

Attempting to parse sentences such as "1 cup plus 2 tablespoons olive oil" results in HTTP 500 error with the traceback:

Traceback (most recent call last):
  File "/home/tom/Recipes/ingredient-parser/webtools/app.py", line 190, in parser
    quantity=str(amount.quantity),
                 ^^^^^^^^^^^^^^^
AttributeError: 'CompositeIngredientAmount' object has no attribute 'quantity'

This is because the amount parsed is returned as a CompositeIngredientAmount object:

[CompositeIngredientAmount(amounts=[IngredientAmount(quantity=Fraction(1, 1),
                                                     quantity_max=Fraction(1, 1),
                                                     unit=<Unit('cup')>,
                                                     text='1 cup',
                                                     confidence=0.999822,
                                                     starting_index=0,
                                                     APPROXIMATE=False,
                                                     SINGULAR=False,
                                                     RANGE=False,
                                                     MULTIPLIER=False,
                                                     PREPARED_INGREDIENT=False),
                                    IngredientAmount(quantity=Fraction(2, 1),
                                                     quantity_max=Fraction(2, 1),
                                                     unit=<Unit('tablespoon')>,
                                                     text='2 tablespoons',
                                                     confidence=0.997124,
                                                     starting_index=3,
                                                     APPROXIMATE=False,
                                                     SINGULAR=False,
                                                     RANGE=False,
                                                     MULTIPLIER=False,
                                                     PREPARED_INGREDIENT=False)],
                           join=' plus ',
                           subtractive=False,
                           text='1 cup plus 2 tablespoons',
                           confidence=0.9984729999999999,
                           starting_index=0)]

The webtools parser should be fixed to support amounts returned as ComposteIngredientAmount objects.

@mcioffi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions