recipe-scrapers
recipe-scrapers copied to clipboard
[discussion] servings text
Currently a recipe, no matter what its schema content is, parses the amount of servings(yield) and returns <number> servings
. If a schema information states the yield in some other unit than servings
(for example "loafs" or "pieces" or similar) that information is lost.
The method in _utils
also handles "items" which is a defined whitelist of lets call them units for which items instead of servings is returned. This helps to a certain degree as people will be able to know from the context what the items are but it also applies to those hardcoded strings which does not help a lot given the countless options in different languages that exist.
Changing this would mean that probably most tests will need to be updated and it will change the results people using this library get but on the other hand it will re-add context that was previously lost.
I have not seen as many different formats and recipes as you so I am not sure if there are other problems that might arise by changing this but is there any interest in changing the format here?
print(get_yields('4 cakes'))
print(get_yields('2 loaf of bread'))
print(get_yields('6 items'))
print(get_yields('12 pieces'))
print(get_yields('2 servings'))
# produces
4 servings
2 servings
6 servings
12 servings
2 servings
In a written recipe (ignoring parsing/scraping for the moment), the output (yields / servings / ...) information seems to provide for at least two purposes:
- It allows the reader to understand what the recipe will produce (assuming that the recipe is accurate and can be followed correctly)
- It allows the reader to scale up-or-down the number of items produced (at least theoretically; not all equipment, ingredients, etc may scale linearly -- but certainly a complete recipe could be repeated multiple times)
Not sure whether those help to determine an answer, but perhaps they could guide discussion.
@vabene1111, just scrolling through some of the older library issues and I believe this has been fixed for a bit!
Take a look at #620 and let me know if this is what you are discussing here.
yes you are indeed correct. I just tested with v15 rc3 and it produces the results I would expect from this function
>>> from recipe_scrapers._utils import get_yields
>>> print(get_yields('4 cakes'))
4 cakes
>>> print(get_yields('2 loaf of bread'))
2 loaves
thanks for cleaning this up. Just for future reference, the link you put into your answer is to this post, but it doesn't matter since its all resolved.
Glad to hear this is what you had in mind!
Oops you're right, If you're interested the link was supposed to be to #963