-
Notifications
You must be signed in to change notification settings - Fork 92
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
ingredient amounts given as intervals are not treated properly #2234
Comments
I still have this same issue with the following ingredient given with ranges:
Error message is:
Similar to common This can be eventually solved together with the alternative ingredients |
@j0hannesr0th here is some problem with the indredient recalculator. Can you give your advice here? |
Good question! I don't have a solution for this, but here are some thoughts:
|
@j0hannesr0th your comment made me smile and thus got me interested into the challenge 😺 I have been checking the current regex expressions and tried to yield something more general: cookbook/src/js/yieldCalculator.js Lines 1 to 33 in 993b6a1
I noticed that
Actually I am unsure whether it will work with Latin-1 characters like in french I could come up with the following regex that should match a basic grammar for ^(?<amount>(?<range_from>(?<numerator_from>\d+(?:\.(?:\d+))?|\p{N}+)(?:\/(?<dividend_from>\d+(?:\.(?:\d+))?|\p{N}+))?)(?:(?:-)(?<range_to>(?<numerator_to>\d+(?:\.(?:\d+))?|\p{N}+)(?:\/(?<dividend_to>\d+(?:\.(?:\d+))?|\p{N}+))?))?)(?:\s)(?<unit>\p{L}*)\s(?<ingredient>.*?)(?:\s(?<option>\(optional\)))?(?:\s(?<alternative>(?:or|oder|ou)))?$ You can test it on the below regex101 instance against the following set of examples:
|
@stefan123t as I said: not impossible but kind of ugly but not that easy to understand. And a few weeks later some other edge case, which we haven't considered, comes up. For me it's fine if you want to commit your code. |
Yeah, no one will be able to read this as suggested nor maintain in case of bugs/problems. Can't we split up the RegEx into building blocks and define something like with BNF typically done? I am thinking along this lines: const reInteger = '([0-9]+)'
const reFloat = '([0-9]*\\.[0-9]+)'
const reNumber = `(${reInteger}|${reFloat})`
// ...
const re = new Regex(...) The problem with is kind of parsing is that there are many groups and you have to be super careful to not get caught in assembling the actual numeric value. Do you think this was resulting in a cleaner structure and more maintainability? |
@christianlupus splitting the rather unwieldy RegEx I construed into BNF form would be a really good idea Do you think the named capture groups cookbook/src/js/yieldCalculator.js Lines 1 to 5 in 993b6a1
cookbook/src/js/yieldCalculator.js Lines 49 to 59 in 993b6a1
Note: I have not been able to include the |
In many recipes, amounts of some ingredients are specified as an interval, such as "4-5 eggs".
If I do this in the Cookbook, the upper bound is completely ignored, i.e., it shows as "4 eggs".
I tested this with both "-" and "–", the result is the same.
Even worse, if I use spaces around the dash ("4 - 5 eggs"), the "- 5" part is interpreted as part of the name of the ingredients, so if I ask for twice the number of portions, it would say "8 - 5 eggs".
Is this a bug, or is there some different way to specify imprecise amounts that I did not think of?
The text was updated successfully, but these errors were encountered: