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

feat: Extract ingredients origins from labels and use them in Eco-Score #6377

Merged
merged 7 commits into from
Feb 4, 2022

Conversation

stephanegigandet
Copy link
Contributor

@stephanegigandet stephanegigandet commented Feb 2, 2022

What

3 changes:

  • There is now a way in the labels taxonomy to specify that a label like "French eggs" means that the origin of the ingredient "en:egg" is "en:france".

en:French eggs, Eggs from France
ingredients:en: en:egg
origins:en: en:france

This info is added to the "specific_ingredients" structure, which can also be populated through parsing the end of the ingredient list (e.g. phrases like "Origin of the milk: United Kingdom").

  • The origins of specific ingredients are now used during ingredients analysis to populate the origins field of matching ingredients.

  • For the Eco-Score, if we don't have an ingredients list (e.g. products that have a single ingredient like eggs often don't have an ingredient list filled), but if we have an ingredient specific origin (French eggs), we use that origin for the whole product.

Part of

@stephanegigandet stephanegigandet requested a review from a team as a code owner February 2, 2022 17:55
@github-actions github-actions bot added 🌱 Eco-Score https://world.openfoodfacts.org/eco-score-the-environmental-impact-of-food-products 🥗 Ingredients labels 🧬 Taxonomies https://wiki.openfoodfacts.org/Global_taxonomies 🧪 tests labels Feb 2, 2022
Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, eventual cosmetic changes possibles

sub has_specific_ingredient_property($$$) {

my $product_ref = shift;
my $ingredient_id = shift;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename as searched_id because it's very hard not to mess things up underneath between ingredient_id ingredient_ref and specific_ingredient_id.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise, underneath use specific rather than ingredient in name: specific_ref, specific_id

lib/ProductOpener/Ingredients.pm Outdated Show resolved Hide resolved
lib/ProductOpener/Ingredients.pm Outdated Show resolved Hide resolved
and ((not defined $ingredient_id) or (is_a("ingredients", $ingredient_id, $specific_ingredient_id)))) {

$value = $ingredient_ref->{origins};
last;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm asking myself in if this kind of treatment we should not continue for sanity checks. Something like:

defined $value and $value = $ingredient_ref->{origins} 
    or log->warning("Got more than one specific ingredient origin ", {product => $product_ref->{id}, ingredient_id => $ingredient_id});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea. I also just noticed that I hardcoded "origins" in this function even though it's passed a $property parameter.

en:French pork
fr:Viande Porcine Française, VPF, viande de porc française, Le Porc Français, Porc Origine France, porc français, porc 100% France
origins:en: en:france
ingredients:en: en:pork
Copy link
Member

@alexgarel alexgarel Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should document that origins can be a list, but not ingredients (from what I understand).

@stephanegigandet stephanegigandet added 🥗🔍 Ingredients analysis https://wiki.openfoodfacts.org/Ingredients_Extraction_and_Analysis and removed 🧬 Taxonomies https://wiki.openfoodfacts.org/Global_taxonomies 🥗 Ingredients labels 🧪 tests labels Feb 3, 2022
@github-actions github-actions bot added 🥗 Ingredients labels 🧬 Taxonomies https://wiki.openfoodfacts.org/Global_taxonomies 🧪 tests labels Feb 4, 2022
@sonarcloud
Copy link

sonarcloud bot commented Feb 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@stephanegigandet stephanegigandet merged commit d5bd976 into main Feb 4, 2022
@stephanegigandet stephanegigandet deleted the ingredient_labels branch February 4, 2022 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌱 Eco-Score https://world.openfoodfacts.org/eco-score-the-environmental-impact-of-food-products 🥗🔍 Ingredients analysis https://wiki.openfoodfacts.org/Ingredients_Extraction_and_Analysis 🥗 Ingredients labels 🧬 Taxonomies https://wiki.openfoodfacts.org/Global_taxonomies 🧪 tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants