Skip to content

Commit

Permalink
feat: use ingredients processing for NOVA classification
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanegigandet committed Feb 7, 2025
1 parent d1346e7 commit ae64f24
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
20 changes: 20 additions & 0 deletions lib/ProductOpener/Food.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2692,6 +2692,26 @@ sub compute_nova_group ($product_ref) {
}
}

# Go through the nested ingredients structure to check if some ingredients
# have a processing that has a nova:en: property
if (defined $product_ref->{ingredients}) {
# Create a copy of the ingredients structure to avoid modifying the original one
my $ingredients_ref = dclone($product_ref->{ingredients});
while (my $ingredient_ref = shift @{$ingredients_ref}) {
if (defined $ingredient_ref->{processing}) {
foreach my $processing (split(/,/, $ingredient_ref->{processing})) {
my $nova_group = get_property("ingredients_processing", $processing, "nova:en");
if (defined $nova_group) {
push @{$matching_tags_for_groups{$nova_group + 0}}, ["ingredients", $ingredient_ref->{id}];
}
}
}
if (defined $ingredient_ref->{ingredients}) {
push @{$ingredients_ref}, @{$ingredient_ref->{ingredients}};
}
}
}

# Assign the NOVA group based on matching tags (options in Config.pm and then taxonomies)
# First identify group 2 foods, then group 3 and 4
# Group 2 foods should not be moved to group 3
Expand Down
10 changes: 8 additions & 2 deletions taxonomies/food/ingredients.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28561,6 +28561,11 @@ it: farina di soia sgrassata, farina di soia senza grassi
pl: odtłuszczona mąka sojowa
ro: făină de soia degrasată, faina de soia degrasata

< en: flour
en: modified flour
fr: farine modifiée
nova:en: 4

< en:corn
< en:flour
en: corn flour, maize flour, cornflour
Expand Down Expand Up @@ -28610,11 +28615,12 @@ hu: bio kukoricaliszt
it: Farina di mais biologica
pt: farinha de milho orgânico

< en: modified flour
< en:corn
en: modified cornflour
en: modified corn flour
bg: модифицирано царевично брашно
de: Modifiziertes Maismehl
fr: Amidon de maïs modifié
fr: Farine de maïs modifié
hr: modificirano kukuruzno brašno
it: Farina di mais modificata
nl: gemodificeerd maïsmeel
Expand Down
25 changes: 25 additions & 0 deletions taxonomies/ingredients_processing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2660,6 +2660,7 @@ hr: hidrolizat, hidrolizirane, hidrolizirano, hidrolizirani
nl: gehydrolyseerd, gehydrolyseerde
pl: hydrolizat, hydrolizowane
sv: hydrolyserat
nova:en: 4

#en:description:Transformation of unsaturated glycerides into saturated glycerides (of oils and fats)
en: hydrogenated, hardened, partially hardened
Expand All @@ -2675,6 +2676,7 @@ it: idrogenato, idrogenati, idrogenata, idrogenate
nl: Gehydrogeneerde
pl: uwodorniony, uwodorniona, uwodornione, utwardzony, utwardzone, utwardzona
sv: hårdat
nova:en: 4

#<en:hydrogenated
en: fully hydrogenated
Expand All @@ -2688,6 +2690,7 @@ hr: potpuno hidrogenirana, potpuno hidrogenirane, potpuno hidrogenirano, potpuno
nb: fullherdet
pl: całkowicie uwodorniony, całkowicie uwodorniona, całkowicie uwodornione, całkowicie utwardzony, całkowicie utwardzona, całkowicie utwardzone
sv: fullhärdad
nova:en: 4

#<en:hydrogenated
en: partially hydrogenated
Expand All @@ -2706,10 +2709,12 @@ pl: częściowo uwodorniony, częściowo uwodorniona, częściowo uwodornione, c
pt: parcialmente hidrogenada
ro: parțial hidrogenate
sv: delvis härdad
nova:en: 4

en: textured
de: texturiert, texturierte, texturierter, texturiertes, texturierten, texturiertem
fr: texturé, texturée
nova:en: 4

en: processed with alkali
bg: обработено с щелоч
Expand All @@ -2727,6 +2732,26 @@ pl: przetworzone z alkalicznym
pt: processado com álcali
ro: prelucrat cu alcali
sv: behandlad med alkali
nova:en: 4

en: modified
bg: модифициран, модифицирана, модифицирани, модифицирани
ca: modificat, modificada, modificats, modificades
da: modificeret, modificerede, modificerede, modificerede
de: modifiziert, modifizierte, modifizierten, modifizierten
es: modificado, modificada, modificados, modificadas
fi: muokattu, muokattu, muokatut, muokatut
fr: modifié, modifiée, modifiés, modifiées
hr: modificiran, modificirana, modificirani, modificirane
hu: módosított, módosított, módosítottak, módosítottak
it: modificato, modificata, modificati, modificate
nl: gewijzigd, gewijzigde, gewijzigden, gewijzigde
pl: zmodyfikowany, zmodyfikowana, zmodyfikowani, zmodyfikowane
pt: modificado, modificada, modificados, modificadas
ro: modificat, modificată, modificați, modificate
sv: modifierad, modifierad, modifierade, modifierade
nova:en: 4


en: brewed
de: gebrühter
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/nova.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ my @tests = (
# allergens in parenthesis should not change the nova score but should appear in allergens
[{lc => "hr", ingredients_text_hr => "Krupica od durum pšenice (gluten), voda."}, 1],

# added nova:en: 4 property to some processings
[{lc => "fr", ingredients_text_fr => "Farine de blé modifiée"}, 4],
[{lc => "en", ingredients_text_en => "Modified cornflour"}, 4],
[{lc => "en", ingredients_text_en => "Modified whey"}, 4],
[{lc => "en", ingredients_text_en => "Modified strawberry"}, 4],

);

foreach my $test_ref (@tests) {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/packaging_food_contact.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use utf8;
use Test2::V0;
use Data::Dumper;
$Data::Dumper::Terse = 1;
$Data::Dumper::Sortkeys = 1;
use Log::Any::Adapter 'TAP';

use JSON;
Expand Down

0 comments on commit ae64f24

Please sign in to comment.