From 70ea2e1086192c2645280cec0d262e31fa72b819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Gigandet?= Date: Wed, 6 Oct 2021 19:46:11 +0200 Subject: [PATCH] fix: Make maybe vegan/vegetarian attribute score 50 instead of 20 (#5839) --- lib/ProductOpener/Attributes.pm | 4 +- t/attributes.t | 13 +- .../attributes/en-attributes.json | 4 +- .../attributes/en-maybe-vegan.json | 522 ++++++++++++++++++ .../attributes/fr-palm-oil-free.json | 2 +- .../attributes/fr-vegetable-oils.json | 2 +- 6 files changed, 540 insertions(+), 7 deletions(-) create mode 100644 t/expected_test_results/attributes/en-maybe-vegan.json diff --git a/lib/ProductOpener/Attributes.pm b/lib/ProductOpener/Attributes.pm index c16ba039d0302..bfe1e205008c4 100644 --- a/lib/ProductOpener/Attributes.pm +++ b/lib/ProductOpener/Attributes.pm @@ -1335,7 +1335,7 @@ sub compute_attribute_ingredients_analysis($$$) { $status = "known"; } elsif (has_tag($product_ref, "ingredients_analysis", "en:may-contain-$ingredient")) { - $match = 20; + $match = 50; $analysis_tag = "may-contain-$ingredient"; $status = "known"; } @@ -1360,7 +1360,7 @@ sub compute_attribute_ingredients_analysis($$$) { } elsif (has_tag($product_ref, "labels", "en:maybe-$analysis") or has_tag($product_ref, "ingredients_analysis", "en:maybe-$analysis")) { - $match = 20; + $match = 50; $analysis_tag = "maybe-$analysis"; $status = "known"; } diff --git a/t/attributes.t b/t/attributes.t index 4db7576495959..94db9f58a868f 100755 --- a/t/attributes.t +++ b/t/attributes.t @@ -140,7 +140,18 @@ my @tests = ( "fiber_100g" => 5.5, }, } - ], + ], + + # Maybe vegan: attribute score should be 50 + [ + 'en-maybe-vegan', + { + lc => "en", + categories => "Non-dairy cheeses", + categories_tags => ["en:non-dairy-cheeses"], + ingredients_text => "tapioca starch, palm oil, enzyme", + } + ], ); foreach my $test_ref (@tests) { diff --git a/t/expected_test_results/attributes/en-attributes.json b/t/expected_test_results/attributes/en-attributes.json index 5062acfe152d3..ac9c77d10e291 100644 --- a/t/expected_test_results/attributes/en-attributes.json +++ b/t/expected_test_results/attributes/en-attributes.json @@ -623,7 +623,7 @@ "en:egg", "en:strawberry", "en:fruit", - "en:berries", + "en:berries", "en:high-fructose-corn-syrup", "en:glucose", "en:fructose", @@ -671,7 +671,7 @@ "en:egg", "en:strawberry", "en:fruit", - "en:berries", + "en:berries", "en:high-fructose-corn-syrup", "en:glucose", "en:fructose", diff --git a/t/expected_test_results/attributes/en-maybe-vegan.json b/t/expected_test_results/attributes/en-maybe-vegan.json new file mode 100644 index 0000000000000..d5a0cde5a75f8 --- /dev/null +++ b/t/expected_test_results/attributes/en-maybe-vegan.json @@ -0,0 +1,522 @@ +{ + "additives_n" : 0, + "additives_old_n" : 0, + "additives_old_tags" : [], + "additives_original_tags" : [], + "additives_tags" : [], + "allergens" : "", + "allergens_from_ingredients" : "", + "allergens_from_user" : "(en) ", + "allergens_hierarchy" : [], + "allergens_tags" : [], + "amino_acids_tags" : [], + "attribute_groups_en" : [ + { + "attributes" : [ + { + "description" : "", + "description_short" : "Unknown nutritional quality", + "icon_url" : "https://server_domain/images/attributes/nutriscore-unknown.svg", + "id" : "nutriscore", + "match" : 0, + "name" : "Nutri-Score", + "status" : "unknown", + "title" : "Nutri-Score not computed" + }, + { + "icon_url" : "https://server_domain/images/attributes/nutrient-level-salt-unknown.svg", + "id" : "low_salt", + "missing" : "Missing nutrition facts", + "name" : "Salt", + "status" : "unknown", + "title" : "Salt in unknown quantity" + }, + { + "icon_url" : "https://server_domain/images/attributes/nutrient-level-fat-unknown.svg", + "id" : "low_fat", + "missing" : "Missing nutrition facts", + "name" : "Fat", + "status" : "unknown", + "title" : "Fat in unknown quantity" + }, + { + "icon_url" : "https://server_domain/images/attributes/nutrient-level-sugars-unknown.svg", + "id" : "low_sugars", + "missing" : "Missing nutrition facts", + "name" : "Sugars", + "status" : "unknown", + "title" : "Sugars in unknown quantity" + }, + { + "icon_url" : "https://server_domain/images/attributes/nutrient-level-saturated-fat-unknown.svg", + "id" : "low_saturated_fat", + "missing" : "Missing nutrition facts", + "name" : "Saturated fat", + "status" : "unknown", + "title" : "Saturated fat in unknown quantity" + } + ], + "id" : "nutritional_quality", + "name" : "Nutritional quality" + }, + { + "attributes" : [ + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-gluten.svg", + "id" : "allergens_no_gluten", + "match" : 100, + "name" : "Gluten", + "status" : "known", + "title" : "Does not contain: Gluten" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-milk.svg", + "id" : "allergens_no_milk", + "match" : 100, + "name" : "Milk", + "status" : "known", + "title" : "Does not contain: Milk" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-eggs.svg", + "id" : "allergens_no_eggs", + "match" : 100, + "name" : "Eggs", + "status" : "known", + "title" : "Does not contain: Eggs" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-nuts.svg", + "id" : "allergens_no_nuts", + "match" : 100, + "name" : "Nuts", + "status" : "known", + "title" : "Does not contain: Nuts" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-peanuts.svg", + "id" : "allergens_no_peanuts", + "match" : 100, + "name" : "Peanuts", + "status" : "known", + "title" : "Does not contain: Peanuts" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-sesame-seeds.svg", + "id" : "allergens_no_sesame_seeds", + "match" : 100, + "name" : "Sesame seeds", + "status" : "known", + "title" : "Does not contain: Sesame seeds" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-soybeans.svg", + "id" : "allergens_no_soybeans", + "match" : 100, + "name" : "Soybeans", + "status" : "known", + "title" : "Does not contain: Soybeans" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-celery.svg", + "id" : "allergens_no_celery", + "match" : 100, + "name" : "Celery", + "status" : "known", + "title" : "Does not contain: Celery" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-mustard.svg", + "id" : "allergens_no_mustard", + "match" : 100, + "name" : "Mustard", + "status" : "known", + "title" : "Does not contain: Mustard" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-lupin.svg", + "id" : "allergens_no_lupin", + "match" : 100, + "name" : "Lupin", + "status" : "known", + "title" : "Does not contain: Lupin" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-fish.svg", + "id" : "allergens_no_fish", + "match" : 100, + "name" : "Fish", + "status" : "known", + "title" : "Does not contain: Fish" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-crustaceans.svg", + "id" : "allergens_no_crustaceans", + "match" : 100, + "name" : "Crustaceans", + "status" : "known", + "title" : "Does not contain: Crustaceans" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-molluscs.svg", + "id" : "allergens_no_molluscs", + "match" : 100, + "name" : "Molluscs", + "status" : "known", + "title" : "Does not contain: Molluscs" + }, + { + "debug" : "3 ingredients (0 unknown)", + "icon_url" : "https://server_domain/images/attributes/no-sulphur-dioxide-and-sulphites.svg", + "id" : "allergens_no_sulphur_dioxide_and_sulphites", + "match" : 100, + "name" : "Sulphur dioxide and sulphites", + "status" : "known", + "title" : "Does not contain: Sulphur dioxide and sulphites" + } + ], + "id" : "allergens", + "name" : "Allergens", + "warning" : "There is always a possibility that data about allergens may be missing, incomplete, incorrect or that the product's composition has changed. If you are allergic, always check the information on the actual product packaging." + }, + { + "attributes" : [ + { + "icon_url" : "https://server_domain/images/attributes/maybe-vegan.svg", + "id" : "vegan", + "match" : 50, + "name" : "Vegan", + "status" : "known", + "title" : "Maybe vegan" + }, + { + "icon_url" : "https://server_domain/images/attributes/maybe-vegetarian.svg", + "id" : "vegetarian", + "match" : 50, + "name" : "Vegetarian", + "status" : "known", + "title" : "Maybe vegetarian" + }, + { + "icon_url" : "https://server_domain/images/attributes/contains-palm-oil.svg", + "id" : "palm_oil_free", + "match" : 0, + "name" : "Palm oil free", + "status" : "known", + "title" : "Palm oil" + } + ], + "id" : "ingredients_analysis", + "name" : "Ingredients" + }, + { + "attributes" : [ + { + "description" : "", + "description_short" : "Processed foods", + "icon_url" : "https://server_domain/images/attributes/nova-group-3.svg", + "id" : "nova", + "match" : 50, + "name" : "NOVA group", + "status" : "known", + "title" : "NOVA 3" + }, + { + "icon_url" : "https://server_domain/images/attributes/0-additives.svg", + "id" : "additives", + "match" : 100, + "name" : "Additives", + "status" : "known", + "title" : "Without additives" + } + ], + "id" : "processing", + "name" : "Food processing" + }, + { + "attributes" : [ + { + "description" : "", + "description_short" : "Unknown environmental impact", + "icon_url" : "https://server_domain/images/attributes/ecoscore-unknown.svg", + "id" : "ecoscore", + "match" : 0, + "name" : "Eco-Score", + "status" : "unknown", + "title" : "Eco-Score not computed" + }, + { + "description" : "", + "description_short" : "Currently only for products with chicken or eggs", + "icon_url" : "https://server_domain/images/attributes/forest-footprint-not-computed.svg", + "id" : "forest_footprint", + "match" : 0, + "name" : "Forest footprint", + "status" : "known", + "title" : "Forest footprint not computed" + } + ], + "id" : "environment", + "name" : "Environment" + }, + { + "attributes" : [ + { + "description" : "Organic farming aims to protect the environment and to conserve biodiversity by prohibiting or limiting the use of synthetic fertilizers, pesticides and food additives.", + "description_short" : "Organic products promote ecological sustainability and biodiversity.", + "icon_url" : "https://server_domain/images/attributes/organic-unknown.svg", + "id" : "labels_organic", + "name" : "Organic farming", + "status" : "unknown", + "title" : "Missing information: organic product?" + }, + { + "description" : "When you buy fair trade products, producers in developing countries are paid an higher and fairer price, which helps them improve and sustain higher social and often environmental standards.", + "description_short" : "Fair trade products help producers in developping countries.", + "icon_url" : "https://server_domain/images/attributes/fair-trade-unknown.svg", + "id" : "labels_fair_trade", + "name" : "Fair trade", + "status" : "unknown", + "title" : "Missing information: fair trade product?" + } + ], + "id" : "labels", + "name" : "Labels" + } + ], + "categories" : "Non-dairy cheeses", + "categories_properties" : {}, + "categories_properties_tags" : [ + "all-products", + "categories-known", + "agribalyse-food-code-unknown", + "agribalyse-proxy-food-code-unknown", + "ciqual-food-code-unknown", + "agribalyse-unknown" + ], + "categories_tags" : [ + "en:non-dairy-cheeses" + ], + "ecoscore_data" : { + "adjustments" : { + "origins_of_ingredients" : { + "aggregated_origins" : [ + { + "origin" : "en:unknown", + "percent" : 100 + } + ], + "epi_score" : 0, + "epi_value" : -5, + "origins_from_origins_field" : [ + "en:unknown" + ], + "transportation_score_be" : 0, + "transportation_score_ch" : 0, + "transportation_score_de" : 0, + "transportation_score_es" : 0, + "transportation_score_fr" : 0, + "transportation_score_ie" : 0, + "transportation_score_it" : 0, + "transportation_score_lu" : 0, + "transportation_score_nl" : 0, + "transportation_score_uk" : 0, + "transportation_value_be" : 0, + "transportation_value_ch" : 0, + "transportation_value_de" : 0, + "transportation_value_es" : 0, + "transportation_value_fr" : 0, + "transportation_value_ie" : 0, + "transportation_value_it" : 0, + "transportation_value_lu" : 0, + "transportation_value_nl" : 0, + "transportation_value_uk" : 0, + "value_be" : -5, + "value_ch" : -5, + "value_de" : -5, + "value_es" : -5, + "value_fr" : -5, + "value_ie" : -5, + "value_it" : -5, + "value_lu" : -5, + "value_nl" : -5, + "value_uk" : -5, + "warning" : "origins_are_100_percent_unknown" + }, + "packaging" : { + "non_recyclable_and_non_biodegradable_materials" : 1, + "value" : -15, + "warning" : "packaging_data_missing" + }, + "production_system" : { + "labels" : [], + "value" : 0, + "warning" : "no_label" + }, + "threatened_species" : { + "ingredient" : "en:palm-oil", + "value" : -10 + } + }, + "agribalyse" : { + "warning" : "missing_agribalyse_match" + }, + "missing" : { + "agb_category" : 1, + "labels" : 1, + "origins" : 1, + "packagings" : 1 + }, + "missing_agribalyse_match_warning" : 1, + "status" : "unknown" + }, + "ecoscore_grade" : "unknown", + "ecoscore_tags" : [ + "unknown" + ], + "ingredients" : [ + { + "id" : "en:tapioca-starch", + "percent_estimate" : 66.6666666666667, + "percent_max" : 100, + "percent_min" : 33.3333333333333, + "text" : "tapioca starch", + "vegan" : "yes", + "vegetarian" : "yes" + }, + { + "from_palm_oil" : "yes", + "id" : "en:palm-oil", + "percent_estimate" : 16.6666666666667, + "percent_max" : 50, + "percent_min" : 0, + "text" : "palm oil", + "vegan" : "yes", + "vegetarian" : "yes" + }, + { + "id" : "en:enzyme", + "percent_estimate" : 16.6666666666667, + "percent_max" : 33.3333333333333, + "percent_min" : 0, + "text" : "enzyme", + "vegan" : "maybe", + "vegetarian" : "maybe" + } + ], + "ingredients_analysis_tags" : [ + "en:palm-oil", + "en:maybe-vegan", + "en:maybe-vegetarian" + ], + "ingredients_from_or_that_may_be_from_palm_oil_n" : 0, + "ingredients_from_palm_oil_n" : 0, + "ingredients_from_palm_oil_tags" : [], + "ingredients_hierarchy" : [ + "en:tapioca-starch", + "en:starch", + "en:palm-oil", + "en:oil-and-fat", + "en:vegetable-oil-and-fat", + "en:palm-oil-and-fat", + "en:enzyme" + ], + "ingredients_n" : 3, + "ingredients_n_tags" : [ + "3", + "1-10" + ], + "ingredients_original_tags" : [ + "en:tapioca-starch", + "en:palm-oil", + "en:enzyme" + ], + "ingredients_percent_analysis" : 1, + "ingredients_tags" : [ + "en:tapioca-starch", + "en:starch", + "en:palm-oil", + "en:oil-and-fat", + "en:vegetable-oil-and-fat", + "en:palm-oil-and-fat", + "en:enzyme" + ], + "ingredients_text" : "tapioca starch, palm oil, enzyme", + "ingredients_that_may_be_from_palm_oil_n" : 0, + "ingredients_that_may_be_from_palm_oil_tags" : [], + "ingredients_with_specified_percent_n" : 0, + "ingredients_with_specified_percent_sum" : 0, + "ingredients_with_unspecified_percent_n" : 3, + "ingredients_with_unspecified_percent_sum" : 100, + "known_ingredients_n" : 7, + "languages" : {}, + "languages_codes" : {}, + "languages_hierarchy" : [], + "languages_tags" : [ + "en:0" + ], + "lc" : "en", + "minerals_tags" : [], + "misc_tags" : [ + "en:nutriscore-not-computed", + "en:nutrition-not-enough-data-to-compute-nutrition-score", + "en:nutrition-no-saturated-fat", + "en:nutriscore-missing-nutrition-data", + "en:nutriscore-missing-nutrition-data-energy", + "en:ecoscore-extended-data-not-computed", + "en:ecoscore-not-computed" + ], + "nova_group" : 3, + "nova_group_debug" : " -- ingredients/en:starch : 3", + "nova_groups" : "3", + "nova_groups_tags" : [ + "en:3-processed-foods" + ], + "nucleotides_tags" : [], + "nutrient_levels" : {}, + "nutrient_levels_tags" : [], + "nutriments" : { + "fruits-vegetables-nuts-estimate-from-ingredients_100g" : 0, + "nova-group" : 3, + "nova-group_100g" : 3, + "nova-group_serving" : 3 + }, + "nutrition_grades_tags" : [ + "unknown" + ], + "nutrition_score_beverage" : 0, + "nutrition_score_debug" : "missing energy", + "other_nutritional_substances_tags" : [], + "packagings" : [], + "pnns_groups_1" : "unknown", + "pnns_groups_1_tags" : [ + "unknown", + "missing-association" + ], + "pnns_groups_2" : "unknown", + "pnns_groups_2_tags" : [ + "unknown", + "missing-association" + ], + "traces" : "", + "traces_from_ingredients" : "", + "traces_from_user" : "(en) ", + "traces_hierarchy" : [], + "traces_tags" : [], + "unknown_ingredients_n" : 0, + "unknown_nutrients_tags" : [], + "vitamins_tags" : [] +} diff --git a/t/expected_test_results/attributes/fr-palm-oil-free.json b/t/expected_test_results/attributes/fr-palm-oil-free.json index 8dbe2f7acef21..e2b7b808ec822 100644 --- a/t/expected_test_results/attributes/fr-palm-oil-free.json +++ b/t/expected_test_results/attributes/fr-palm-oil-free.json @@ -197,7 +197,7 @@ { "icon_url" : "https://server_domain/images/attributes/maybe-vegan.svg", "id" : "vegan", - "match" : 20, + "match" : 50, "name" : "Végétalien", "status" : "known", "title" : "Peut-être végétalien" diff --git a/t/expected_test_results/attributes/fr-vegetable-oils.json b/t/expected_test_results/attributes/fr-vegetable-oils.json index f6fad19fc339d..060f643ca2d8e 100644 --- a/t/expected_test_results/attributes/fr-vegetable-oils.json +++ b/t/expected_test_results/attributes/fr-vegetable-oils.json @@ -213,7 +213,7 @@ { "icon_url" : "https://server_domain/images/attributes/may-contain-palm-oil.svg", "id" : "palm_oil_free", - "match" : 20, + "match" : 50, "name" : "Sans huile de palme", "status" : "known", "title" : "Pourrait contenir de l'huile de palme"