-
-
Notifications
You must be signed in to change notification settings - Fork 400
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
feat: Initial support for specific ingredients parsing #6243
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, still I need to test.
lib/ProductOpener/Ingredients.pm
Outdated
# We might have an ingredient specified multiple times (e.g. once for percent, another for origins or labels) | ||
defined $product_ref->{specific_ingredients}{$ingredient_id} or $product_ref->{specific_ingredients}{$ingredient_id} = {}; | ||
$product_ref->{specific_ingredients}{$ingredient_id}{ingredient} = $ingredient; | ||
$product_ref->{specific_ingredients}{$ingredient_id}{text} = $matched_text; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok to smash previous values ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could concatenate them. I didn't do it because the case is largely hypothetical and the smashed values ("ingredient" and "text") are kept mostly for debugging purposes. But it's cleaner if we concatenate, I'll change it.
t/ingredients_parsing.t
Outdated
@@ -168,10 +168,10 @@ my @lists =( | |||
|
|||
["fr","p\x{e2}te de cacao* de Madagascar 75%, sucre de canne*, beurre de cacao*. * issus du commerce \x{e9}quitable et de l'agriculture biologique (100% du poids total).","pâte de cacao Commerce équitable Bio de Madagascar 75%, sucre de canne Commerce équitable Bio, beurre de cacao Commerce équitable Bio."], | |||
|
|||
["fr","Céleri - rave 21% - Eau, légumes 33,6% (carottes, céleri - rave, poivrons rouges 5,8% - haricots - petits pois bio - haricots verts - courge - radis, pommes de terre - patates - fenouil - cerfeuil tubéreux - persil plat)","Céleri-rave 21% - Eau, légumes 33,6% (carottes, céleri-rave, poivrons rouges 5,8% - haricots - petits pois bio - haricots verts - courge - radis, pommes de terre - patates - fenouil - cerfeuil tubéreux - persil plat)"], | |||
["fr","Céleri - rave 21% - Eau, légumes 33,6% (carottes, céleri - rave, poivrons rouges 5,8% - haricots - petits pois bio - haricots verts - courge - radis, pommes de terre - patates - fenouil - cerfeuil tubéreux - persil plat)","Céleri-rave 21% - Eau, légumes 33.6% (carottes, céleri-rave, poivrons rouges 5.8% - haricots - petits pois bio - haricots verts - courge - radis, pommes de terre - patates - fenouil - cerfeuil tubéreux - persil plat)"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, that would be clearer with a line between entry / expected !
I did not understand you where changing the expected result at first sight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I'll change it.
The sentences parsed with the new function do not appear in Details of the analysis of the ingredients, so it's not easy to test manually, and I also think it's a pity as it participates to nutri-score. |
Applied changes from code review, thank you! Also added initial support to parse things like "Origin of the milk: UK". |
I added a sub section to list the specific ingredients in the analysis. |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool !
This is in particular to resolve Nutri-Score computation errors when we fail to parse the % of fruits/vegetables or milk content indicated at the end of the ingredients list.
The resulting specific_ingredients structure is now used when computing the Nutri-Score.
It is also potentially useful to later parse other types of mentions like "Origin of something: some country" at the end of ingredients list.
Part of