Skip to content

Commit

Permalink
taxonomy: Fixing coconut milks (#9151)
Browse files Browse the repository at this point in the history
  • Loading branch information
moon-rabbitOFF authored Oct 25, 2023
1 parent 76a0ab1 commit 5621289
Show file tree
Hide file tree
Showing 7 changed files with 393 additions and 134 deletions.
7 changes: 3 additions & 4 deletions lib/ProductOpener/Config_off.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -582,8 +582,7 @@ $options{categories_exempted_from_nutrient_levels} = [
en:coffees
en:teas
en:yeasts
fr:levure
fr:levures
en:food-additives
)
];

Expand Down
30 changes: 30 additions & 0 deletions lib/ProductOpener/Food.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 5621289

Please sign in to comment.