Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add more linked panels for attributes #6808

Merged
merged 12 commits into from
May 30, 2023
25 changes: 23 additions & 2 deletions lib/ProductOpener/Attributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,17 @@ sub compute_attribute_allergen ($product_ref, $target_lc, $attribute_id) {
display_taxonomy_tag($target_lc, "allergens", $allergen_id)
);
$attribute_ref->{icon_url} = "$static_subdomain/images/attributes/$allergen-content-unknown.svg";

if (not($product_ref->{ingredients_n})) {
# If we don't have ingredients,
# link to the ingredients panel that will have an action to add ingredients
$attribute_ref->{panel_id} = "ingredients";
}
else {
# If we have ingredients, then we have too many ingredients that we did not recognize,
# link to the ingredients analysis details
$attribute_ref->{panel_id} = "ingredients_analysis_details";
}
}
elsif ($attribute_ref->{match} == 100) {
$attribute_ref->{title} = sprintf(
Expand Down Expand Up @@ -1463,8 +1474,18 @@ sub compute_attribute_ingredients_analysis ($product_ref, $target_lc, $analysis)
# the ingredients_analysis taxonomy contains en:palm-oil and not en:contains-palm-oil
$analysis_tag =~ s/contains-(.*)$/$1/;

# Link to the corresponding knowledge panel (the panel id depends on the value of the property)
$attribute_ref->{panel_id} = "ingredients_analysis_en:" . $analysis_tag;
# Link to the corresponding knowledge panel
if (($status eq "unknown") and not($product_ref->{ingredients_n})) {
# If the status is unknown, and we don't have ingredients,
# link to the ingredients panel that will have an action to add ingredients
# Note that the status may be known (e.g. from labels like "Palm oil free")
# even if we don't have ingredients
$attribute_ref->{panel_id} = "ingredients";
}
else {
# Otherwise we link to the panel specific to the ingredients analysis property
$attribute_ref->{panel_id} = "ingredients_analysis_en:" . $analysis_tag;
}

if ($target_lc ne "data") {
$attribute_ref->{title} = display_taxonomy_tag($target_lc, "ingredients_analysis", "en:$analysis_tag");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/gluten-content-unknown.svg",
"id" : "allergens_no_gluten",
"name" : "Gluten",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Gluten"
},
Expand All @@ -74,6 +75,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/milk-content-unknown.svg",
"id" : "allergens_no_milk",
"name" : "Milk",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Milk"
},
Expand All @@ -83,6 +85,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/eggs-content-unknown.svg",
"id" : "allergens_no_eggs",
"name" : "Eggs",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Eggs"
},
Expand All @@ -92,6 +95,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/nuts-content-unknown.svg",
"id" : "allergens_no_nuts",
"name" : "Nuts",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Nuts"
},
Expand All @@ -101,6 +105,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/peanuts-content-unknown.svg",
"id" : "allergens_no_peanuts",
"name" : "Peanuts",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Peanuts"
},
Expand All @@ -110,6 +115,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/sesame-seeds-content-unknown.svg",
"id" : "allergens_no_sesame_seeds",
"name" : "Sesame seeds",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Sesame seeds"
},
Expand All @@ -119,6 +125,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/soybeans-content-unknown.svg",
"id" : "allergens_no_soybeans",
"name" : "Soybeans",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Soybeans"
},
Expand All @@ -128,6 +135,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/celery-content-unknown.svg",
"id" : "allergens_no_celery",
"name" : "Celery",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Celery"
},
Expand All @@ -137,6 +145,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/mustard-content-unknown.svg",
"id" : "allergens_no_mustard",
"name" : "Mustard",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Mustard"
},
Expand All @@ -146,6 +155,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/lupin-content-unknown.svg",
"id" : "allergens_no_lupin",
"name" : "Lupin",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Lupin"
},
Expand All @@ -155,6 +165,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/fish-content-unknown.svg",
"id" : "allergens_no_fish",
"name" : "Fish",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Fish"
},
Expand All @@ -164,6 +175,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/crustaceans-content-unknown.svg",
"id" : "allergens_no_crustaceans",
"name" : "Crustaceans",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Crustaceans"
},
Expand All @@ -173,6 +185,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/molluscs-content-unknown.svg",
"id" : "allergens_no_molluscs",
"name" : "Molluscs",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Molluscs"
},
Expand All @@ -182,6 +195,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/sulphur-dioxide-and-sulphites-content-unknown.svg",
"id" : "allergens_no_sulphur_dioxide_and_sulphites",
"name" : "Sulphur dioxide and sulphites",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Sulphur dioxide and sulphites"
}
Expand All @@ -197,7 +211,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/vegan-status-unknown.svg",
"id" : "vegan",
"name" : "Vegan",
"panel_id" : "ingredients_analysis_en:vegan-status-unknown",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Vegan status unknown"
},
Expand All @@ -206,7 +220,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/vegetarian-status-unknown.svg",
"id" : "vegetarian",
"name" : "Vegetarian",
"panel_id" : "ingredients_analysis_en:vegetarian-status-unknown",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Vegetarian status unknown"
},
Expand All @@ -215,7 +229,7 @@
"icon_url" : "http://static.openfoodfacts.localhost/images/attributes/palm-oil-content-unknown.svg",
"id" : "palm_oil_free",
"name" : "Palm oil free",
"panel_id" : "ingredients_analysis_en:palm-oil-content-unknown",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Palm oil content unknown"
}
Expand Down
21 changes: 19 additions & 2 deletions tests/unit/attributes.t
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,26 @@ my @tests = (
ingredients_text =>
"Cow milk, salt, microbial culture, garlic flavouring, guar gum, sugar, high fructose corn syrup",
}
]
],

#
# Ingredients analysis and allergens when we don't have ingredients, or ingredients are not recognized
[
'en-no-ingredients',
{
lc => "en",
categories => "Cheeses",
categories_tags => ["en:cheeses"],
}
],
[
'en-unknown-ingredients',
{
lc => "en",
categories => "Cheeses",
categories_tags => ["en:cheeses"],
ingredients_text => "some ingredient that we do not recognize",
}
],
);

foreach my $test_ref (@tests) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"icon_url" : "https://server_domain/images/attributes/gluten-content-unknown.svg",
"id" : "allergens_no_gluten",
"name" : "Gluten",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Gluten"
},
Expand All @@ -80,6 +81,7 @@
"icon_url" : "https://server_domain/images/attributes/milk-content-unknown.svg",
"id" : "allergens_no_milk",
"name" : "Milk",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Milk"
},
Expand All @@ -89,6 +91,7 @@
"icon_url" : "https://server_domain/images/attributes/eggs-content-unknown.svg",
"id" : "allergens_no_eggs",
"name" : "Eggs",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Eggs"
},
Expand All @@ -98,6 +101,7 @@
"icon_url" : "https://server_domain/images/attributes/nuts-content-unknown.svg",
"id" : "allergens_no_nuts",
"name" : "Nuts",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Nuts"
},
Expand All @@ -107,6 +111,7 @@
"icon_url" : "https://server_domain/images/attributes/peanuts-content-unknown.svg",
"id" : "allergens_no_peanuts",
"name" : "Peanuts",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Peanuts"
},
Expand All @@ -116,6 +121,7 @@
"icon_url" : "https://server_domain/images/attributes/sesame-seeds-content-unknown.svg",
"id" : "allergens_no_sesame_seeds",
"name" : "Sesame seeds",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Sesame seeds"
},
Expand All @@ -125,6 +131,7 @@
"icon_url" : "https://server_domain/images/attributes/soybeans-content-unknown.svg",
"id" : "allergens_no_soybeans",
"name" : "Soybeans",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Soybeans"
},
Expand All @@ -134,6 +141,7 @@
"icon_url" : "https://server_domain/images/attributes/celery-content-unknown.svg",
"id" : "allergens_no_celery",
"name" : "Celery",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Celery"
},
Expand All @@ -143,6 +151,7 @@
"icon_url" : "https://server_domain/images/attributes/mustard-content-unknown.svg",
"id" : "allergens_no_mustard",
"name" : "Mustard",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Mustard"
},
Expand All @@ -152,6 +161,7 @@
"icon_url" : "https://server_domain/images/attributes/lupin-content-unknown.svg",
"id" : "allergens_no_lupin",
"name" : "Lupin",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Lupin"
},
Expand All @@ -161,6 +171,7 @@
"icon_url" : "https://server_domain/images/attributes/fish-content-unknown.svg",
"id" : "allergens_no_fish",
"name" : "Fish",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Fish"
},
Expand All @@ -170,6 +181,7 @@
"icon_url" : "https://server_domain/images/attributes/crustaceans-content-unknown.svg",
"id" : "allergens_no_crustaceans",
"name" : "Crustaceans",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Crustaceans"
},
Expand All @@ -179,6 +191,7 @@
"icon_url" : "https://server_domain/images/attributes/molluscs-content-unknown.svg",
"id" : "allergens_no_molluscs",
"name" : "Molluscs",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Molluscs"
},
Expand All @@ -188,6 +201,7 @@
"icon_url" : "https://server_domain/images/attributes/sulphur-dioxide-and-sulphites-content-unknown.svg",
"id" : "allergens_no_sulphur_dioxide_and_sulphites",
"name" : "Sulphur dioxide and sulphites",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Presence unknown: Sulphur dioxide and sulphites"
}
Expand All @@ -203,7 +217,7 @@
"icon_url" : "https://server_domain/images/attributes/vegan-status-unknown.svg",
"id" : "vegan",
"name" : "Vegan",
"panel_id" : "ingredients_analysis_en:vegan-status-unknown",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Vegan status unknown"
},
Expand All @@ -212,7 +226,7 @@
"icon_url" : "https://server_domain/images/attributes/vegetarian-status-unknown.svg",
"id" : "vegetarian",
"name" : "Vegetarian",
"panel_id" : "ingredients_analysis_en:vegetarian-status-unknown",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Vegetarian status unknown"
},
Expand All @@ -221,7 +235,7 @@
"icon_url" : "https://server_domain/images/attributes/palm-oil-content-unknown.svg",
"id" : "palm_oil_free",
"name" : "Palm oil free",
"panel_id" : "ingredients_analysis_en:palm-oil-content-unknown",
"panel_id" : "ingredients",
"status" : "unknown",
"title" : "Palm oil content unknown"
}
Expand Down
Loading