diff --git a/lib/ProductOpener/Config_off.pm b/lib/ProductOpener/Config_off.pm index a4173855f8a76..0436810822c17 100644 --- a/lib/ProductOpener/Config_off.pm +++ b/lib/ProductOpener/Config_off.pm @@ -492,7 +492,7 @@ $options{categories_not_considered_as_beverages_for_nutriscore_2021} = [ en:plant-milks en:milks en:meal-replacement - en:dairy-drinks-substitutes + en:plant-based-milk-alternatives en:chocolate-powders en:soups ) @@ -524,7 +524,7 @@ $options{categories_considered_as_beverages_for_nutriscore_2021} = [ $options{categories_considered_as_beverages_for_nutriscore_2023} = [ qw( en:milks - en:dairy-drinks-substitutes + en:plant-based-milk-alternatives en:dairy-drinks en:plant-based-beverages en:tea-based-beverages @@ -582,8 +582,7 @@ $options{categories_exempted_from_nutrient_levels} = [ en:coffees en:teas en:yeasts - fr:levure - fr:levures + en:food-additives ) ]; diff --git a/lib/ProductOpener/Food.pm b/lib/ProductOpener/Food.pm index 96b92a8628dc2..5237f28dc06d4 100644 --- a/lib/ProductOpener/Food.pm +++ b/lib/ProductOpener/Food.pm @@ -121,6 +121,36 @@ use Storable qw/dclone/; use Log::Any qw($log); +# Normalize values listed in Config.pm + +# Canonicalize the list of categories used to compute Nutri-Score, so that Nutri-Score +# computation does not change if we change the canonical English name of a category + +foreach my $categories_list_id ( + qw( + categories_not_considered_as_beverages_for_nutriscore_2021 + categories_not_considered_as_beverages_for_nutriscore_2023 + categories_exempted_from_nutriscore + categories_not_exempted_from_nutriscore + categories_exempted_from_nutrient_levels + ) + ) +{ + my $categories_list_ref = $options{$categories_list_id}; + if (defined $categories_list_ref) { + foreach my $category_id (@{$categories_list_ref}) { + $category_id = canonicalize_taxonomy_tag("en", "categories", $category_id); + # Check that the entry exists + if (not exists_taxonomy_tag("categories", $category_id)) { + $log->error( + "Categoryused in Nutri-Score and listed in Config.pm \$options\{$categories_list_id\} does not exist in the categories taxonomy.", + {category_id => $category_id} + ) if $log->is_error(); + } + } + } +} + # Load nutrient stats for all categories and countries # the stats are displayed on category pages and used in product pages, # as well as in data quality checks and improvement opportunity detection diff --git a/taxonomies/categories.txt b/taxonomies/categories.txt index ceba0ec1b06b3..6dbc5b7920479 100644 --- a/taxonomies/categories.txt +++ b/taxonomies/categories.txt @@ -8666,28 +8666,6 @@ fr:Substituts de produits laitiers nl:Zuivelvervangers pl:Zastępniki nabiału, Substytuty nabiału -{nutrition_score_beverage}, 1); $product_ref = { lc => "en", categories => "beverages", - categories_tags => ["en:beverages", "en:plant-milks"], + categories_tags => ["en:beverages", "en:plant-based-milk-alternatives"], ingredients_tags => ["en:water", "en:sugar"], ingredients_text => "water, fruit juice", }; diff --git a/tests/unit/nutriscore.t b/tests/unit/nutriscore.t index 91d246b32406c..18b385157a9a8 100644 --- a/tests/unit/nutriscore.t +++ b/tests/unit/nutriscore.t @@ -661,6 +661,24 @@ my @tests = ( }, } ], + # Coconut milk -> for cooking, not considered a beverage in 2023 Nutri-Score + [ + "fr-coconut-milk", + { + lc => "fr", + categories => "lait de coco", + ingredients => "Noix de coco 60%, eau", + nutriments => { + energy_100g => 178, + fat_100g => 2.6, + "saturated-fat_100g" => 0.6, + sugars_100g => 0.5, + salt_100g => 0.03, + fiber_100g => 0.5, + proteins_100g => 3.9, + }, + } + ], );