Skip to content

Commit

Permalink
ignore vegetable oil for palm oil detection if it has sub ingredients…
Browse files Browse the repository at this point in the history
…, bug #2339
  • Loading branch information
stephanegigandet committed Sep 16, 2019
1 parent e98ec85 commit 5fe0108
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/ProductOpener/Ingredients.pm
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,6 @@ sub extract_ingredients_from_text($) {

if ($between ne '') {
$ingredient{has_sub_ingredients} = "yes";
$ingredient{from_palm_oil} = "ignore";
}

if (defined $percent) {
Expand Down Expand Up @@ -1099,6 +1098,12 @@ sub analyze_ingredients($) {
}
}

# Vegetable oil (rapeseed oil, ...) : ignore "from_palm_oil:en:maybe" if the ingredient has sub-ingredients
if (($property eq "from_palm_oil") and (defined $value) and ($value eq "maybe")
and (defined $ingredient_ref->{has_sub_ingredients}) and ($ingredient_ref->{has_sub_ingredients} eq "yes")) {
$value = "ignore";
}

not defined $value and $value = "undef";

defined $values{$value} or $values{$value} = 0;
Expand Down
16 changes: 16 additions & 0 deletions t/ingredients.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ my $expected_product_ref =
},
{
'id' => 'en:chocolate',
'has_sub_ingredients' => 'yes',
'rank' => 2,
'text' => 'chocolat',
'vegan' => 'maybe',
Expand Down Expand Up @@ -69,6 +70,7 @@ my $expected_product_ref =
},
{
'id' => 'en:emulsifier',
'has_sub_ingredients' => 'yes',
'rank' => 6,
'text' => "\x{e9}mulsifiants"
},
Expand Down Expand Up @@ -97,6 +99,7 @@ my $expected_product_ref =
},
{
'id' => 'en:acidity-regulator',
'has_sub_ingredients' => 'yes',
'rank' => 10,
'text' => "correcteurs d'acidit\x{e9}"
},
Expand All @@ -116,6 +119,7 @@ my $expected_product_ref =
},
{
'id' => 'en:acid',
'has_sub_ingredients' => 'yes',
'rank' => 13,
'text' => 'acidifiant'
},
Expand Down Expand Up @@ -363,12 +367,14 @@ $expected_product_ref =
'ingredients' => [
{
'id' => 'fr:Marmelade d\'oranges',
'has_sub_ingredients' => 'yes',
'percent' => '41',
'rank' => 1,
'text' => 'Marmelade d\'oranges'
},
{
'id' => 'en:orange-pulp',
'has_sub_ingredients' => 'yes',
'percent' => '0.6',
'processing' => 'en:concentrated',
'rank' => 2,
Expand All @@ -378,6 +384,7 @@ $expected_product_ref =
},
{
'id' => 'en:gelling-agent',
'has_sub_ingredients' => 'yes',
'rank' => 3,
'text' => "g\x{e9}lifiant"
},
Expand All @@ -390,6 +397,7 @@ $expected_product_ref =
},
{
'id' => 'en:acid',
'has_sub_ingredients' => 'yes',
'rank' => 5,
'text' => 'acidifiant'
},
Expand All @@ -402,6 +410,7 @@ $expected_product_ref =
},
{
'id' => 'en:acidity-regulator',
'has_sub_ingredients' => 'yes',
'rank' => 7,
'text' => "correcteurs d'acidit\x{e9}"
},
Expand All @@ -414,6 +423,7 @@ $expected_product_ref =
},
{
'id' => 'en:thickener',
'has_sub_ingredients' => 'yes',
'rank' => 9,
'text' => "\x{e9}paississant"
},
Expand All @@ -426,6 +436,7 @@ $expected_product_ref =
},
{
'id' => 'en:chocolate',
'has_sub_ingredients' => 'yes',
'percent' => '24.9',
'rank' => 11,
'text' => 'chocolat',
Expand Down Expand Up @@ -477,6 +488,7 @@ $expected_product_ref =
},
{
'id' => 'en:raising-agent',
'has_sub_ingredients' => 'yes',
'rank' => 18,
'text' => "poudre \x{e0} lever"
},
Expand All @@ -489,6 +501,7 @@ $expected_product_ref =
},
{
'id' => 'en:emulsifier',
'has_sub_ingredients' => 'yes',
'rank' => 20,
'text' => "\x{e9}mulsifiant"
},
Expand Down Expand Up @@ -520,6 +533,7 @@ $expected_product_ref =
},
{
'id' => 'en:concentrated-orange-juice',
'has_sub_ingredients' => 'yes',
'percent' => '1.4',
'text' => "jus d'orange concentr\x{e9}",
'vegan' => 'yes',
Expand Down Expand Up @@ -587,6 +601,7 @@ $expected_product_ref =
},
{
'id' => 'en:emulsifier',
'has_sub_ingredients' => 'yes',
'text' => "\x{e9}mulsifiant"
},
{
Expand Down Expand Up @@ -1117,6 +1132,7 @@ is_deeply ($product_ref->{ingredients},
{
'id' => 'en:emulsifier',
'rank' => 1,
'has_sub_ingredients' => 'yes',
'text' => "\x{e9}mulsifiant"
},
{
Expand Down
1 change: 1 addition & 0 deletions t/ingredients_analysis.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ my @tests = (
[ { lc => "en", ingredients_text => "modified palm oil" }, [ "en:palm-oil", "en:vegan", "en:vegetarian"] ],
[ { lc => "fr", ingredients_text => "huiles végétales (huile de tournesol', huile de colza)" }, [ "en:palm-oil-free", "en:vegan", "en:vegetarian"] ],
[ { lc => "fr", ingredients_text => "huiles végétales" }, [ "en:may-contain-palm-oil", "en:vegan", "en:vegetarian"] ],
[ { lc => "fr", ingredients_text => "huile de poisson" }, [ "en:palm-oil-free", "en:non-vegan", "en:non-vegetarian"] ],
);


Expand Down

0 comments on commit 5fe0108

Please sign in to comment.