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

Parsing parenthesis can cause bad multiplication #7

Open
nZac opened this issue Oct 21, 2024 · 0 comments
Open

Parsing parenthesis can cause bad multiplication #7

nZac opened this issue Oct 21, 2024 · 0 comments

Comments

@nZac
Copy link

nZac commented Oct 21, 2024

I ran into this recipe line that is giving false quantity numbers because of the Whole30

1 lb pork sausage (casings removed if necessary, sugar-free for Whole30)

def test_whole_thirty_issue():
    slicer = IngredientSlicer(
        "1 lb pork sausage (casings removed if necessary, sugar-free for whole30)",
        debug=True,
        enable_food_units=True,
    )
    parsed = slicer.to_json()
    assert parsed["quantity"] == "1" # FAILS: parsed["quanity"] == 30

The full output of parsed is this:

{'density': None,
 'dimensions': [],
 'food': 'pork sausage',
 'gram_weight': '13607.76',
 'ingredient': '1 lb pork sausage (casings removed if necessary, sugar-free '
               'for whole 30)',
 'is_required': True,
 'parenthesis_content': ['casings removed if necessary, sugar-free for whole '
                         '30'],
 'prep': [],
 'quantity': '30',
 'secondary_quantity': '1',
 'secondary_unit': None,
 'size_modifiers': [],
 'standardized_ingredient': '1 lb pork sausage',
 'standardized_secondary_unit': None,
 'standardized_unit': 'pound',
 'unit': 'lb'}

The problem seems to be here in _extract_quantities_only matching on any number in the string which is, unfortunately, to simple for this situation.

I can think of many things that could be in parenthesis that aren't related to quantity but I also can't think of a good way to differentiate (use 5 pieces) from (add 5 minutes).

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

No branches or pull requests

1 participant