Skip to content

Commit

Permalink
fix warnings modperl error log
Browse files Browse the repository at this point in the history
  • Loading branch information
benbenben2 committed May 26, 2024
1 parent ae1a1f2 commit c3f3e3f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 50 deletions.
14 changes: 7 additions & 7 deletions lib/ProductOpener/Attributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1177,15 +1177,15 @@ sub compute_attribute_nutrient_level ($product_ref, $target_lc, $level, $nid) {

my $match;

if ($value < $low) {
if (defined $value and $value < $low) {
$match = 80 + 20 * ($low - $value) / $low;
$attribute_ref->{icon_url} = "$static_subdomain/images/attributes/dist/nutrient-level-$nid-low.svg";
}
elsif ($value <= $high) {
elsif (defined $value and $value <= $high) {
$match = 20 + 60 * ($high - $value) / ($high - $low);
$attribute_ref->{icon_url} = "$static_subdomain/images/attributes/dist/nutrient-level-$nid-medium.svg";
}
elsif ($value < $high * 2) {
elsif (defined $value and $value < $high * 2) {
$match = 20 * ($high * 2 - $value) / $high;
$attribute_ref->{icon_url} = "$static_subdomain/images/attributes/dist/nutrient-level-$nid-high.svg";
}
Expand All @@ -1202,10 +1202,10 @@ sub compute_attribute_nutrient_level ($product_ref, $target_lc, $level, $nid) {
display_taxonomy_tag($target_lc, "nutrients", "zz:$nid"),
lang_in_other_lc($target_lc, $product_ref->{nutrient_levels}{$nid} . "_quantity")
);
$attribute_ref->{description_short} = sprintf(
lang_in_other_lc($target_lc, 'g_per_100g'),
(sprintf('%.2e', $product_ref->{nutriments}{$nid . $prepared . '_100g'}) + 0.0)
);
if (defined $value) {
$attribute_ref->{description_short}
= sprintf(lang_in_other_lc($target_lc, 'g_per_100g'), (sprintf('%.2e', $value) + 0.0));
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3808,7 +3808,7 @@ sub display_tag ($request_ref) {

my $weblinks_html = '';
my @wikidata_objects = ();
if ( ($tagtype ne 'additives')
if ( (define $tagtype && $tagtype ne 'additives')
and (not defined $request_ref->{groupby_tagtype}))
{
my @weblinks = ();
Expand Down
84 changes: 44 additions & 40 deletions lib/ProductOpener/Ingredients.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1238,53 +1238,57 @@ sub match_ingredient_origin ($ingredients_lc, $text_ref, $matched_ingredient_ref

# Strawberries: Spain, Italy and Portugal
# Strawberries from Spain, Italy and Portugal
if ($$text_ref
=~ /\s*([^,.;:]+)(?::|$from)\s*((?:$origins_regexp)(?:(?:,|$and_or)(?:\s?)(?:$origins_regexp))*)\s*(?:,|;|\.| - |$)/i
)
{
# Note: the regexp above does not currently match multiple origins with commas (e.g. "Origins of milk: UK, UE")
# in order to not overmatch something like "Origin of milk: UK, some other mention."
# In the future, we could try to be smarter and match more if we can recognize the next words exist in the origins taxonomy.
if (defined $origins_regexp) {
if ($$text_ref
=~ /\s*([^,.;:]+)(?::|$from)\s*((?:$origins_regexp)(?:(?:,|$and_or)(?:\s?)(?:$origins_regexp))*)\s*(?:,|;|\.| - |$)/i
)
{
# Note: the regexp above does not currently match multiple origins with commas (e.g. "Origins of milk: UK, UE")
# in order to not overmatch something like "Origin of milk: UK, some other mention."
# In the future, we could try to be smarter and match more if we can recognize the next words exist in the origins taxonomy.

$matched_ingredient_ref->{ingredient} = $1;
$matched_ingredient_ref->{origins} = $2;
$matched_ingredient_ref->{matched_text} = $&;
$matched_ingredient_ref->{ingredient} = $1;
$matched_ingredient_ref->{origins} = $2;
$matched_ingredient_ref->{matched_text} = $&;

# Remove the matched text
$$text_ref = $` . ' ' . $';
# Remove the matched text
$$text_ref = $` . ' ' . $';

return 1;
}
# Try to match without a "from" marker (e.g. "Strawberry France")
elsif ($$text_ref
=~ /\s*([^,.;:]+)\s+((?:$origins_regexp)(?:(?:,|$and_or)(?:\s?)(?:$origins_regexp))*)\s*(?:,|;|\.| - |$)/i)
{
# Note: the regexp above does not currently match multiple origins with commas (e.g. "Origins of milk: UK, UE")
# in order to not overmatch something like "Origin of milk: UK, some other mention."
# In the future, we could try to be smarter and match more if we can recognize the next words exist in the origins taxonomy.
return 1;
}
# Try to match without a "from" marker (e.g. "Strawberry France")
elsif ($$text_ref
=~ /\s*([^,.;:]+)\s+((?:$origins_regexp)(?:(?:,|$and_or)(?:\s?)(?:$origins_regexp))*)\s*(?:,|;|\.| - |$)/i)
{
# Note: the regexp above does not currently match multiple origins with commas (e.g. "Origins of milk: UK, UE")
# in order to not overmatch something like "Origin of milk: UK, some other mention."
# In the future, we could try to be smarter and match more if we can recognize the next words exist in the origins taxonomy.

$matched_ingredient_ref->{ingredient} = $1;
$matched_ingredient_ref->{origins} = $2;
$matched_ingredient_ref->{matched_text} = $&;
$matched_ingredient_ref->{ingredient} = $1;
$matched_ingredient_ref->{origins} = $2;
$matched_ingredient_ref->{matched_text} = $&;

# keep the matched ingredient only if it is a known ingredient in the taxonomy, in order to avoid false positives
# e.g. "something made in France" should not be turned into ingredient "something made in" + origin "France"
if (
not(
exists_taxonomy_tag(
"ingredients",
canonicalize_taxonomy_tag($ingredients_lc, "ingredients", $matched_ingredient_ref->{ingredient})
# keep the matched ingredient only if it is a known ingredient in the taxonomy, in order to avoid false positives
# e.g. "something made in France" should not be turned into ingredient "something made in" + origin "France"
if (
not(
exists_taxonomy_tag(
"ingredients",
canonicalize_taxonomy_tag(
$ingredients_lc, "ingredients", $matched_ingredient_ref->{ingredient}
)
)
)
)
)
{
$matched_ingredient_ref = {};
}
else {
# Remove the matched text
$$text_ref = $` . ' ' . $';
)
{
$matched_ingredient_ref = {};
}
else {
# Remove the matched text
$$text_ref = $` . ' ' . $';

return 1;
return 1;
}
}
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"text_element": {
"type": "default",
"html": `
<strong>[% lang('ecoscore_environmental_policy') %][% sep %]: [% IF product.ecoscore_data.adjustments.origins_of_ingredients.epi_value > 0 %]+[% END %][% round(product.ecoscore_data.adjustments.origins_of_ingredients.epi_value) %]</strong><br>
<strong>[% lang('ecoscore_transportation') %][% sep %]: [% IF product.ecoscore_data.adjustments.origins_of_ingredients.transportation_value > 0 %]+[% END %][% round(product.ecoscore_data.adjustments.origins_of_ingredients.transportation_value) %]</strong><br>
<strong>[% lang('ecoscore_environmental_policy') %][% sep %]: [% IF product.ecoscore_data.adjustments.origins_of_ingredients.epi_value.defined && product.ecoscore_data.adjustments.origins_of_ingredients.epi_value > 0 %]+[% END %][% round(product.ecoscore_data.adjustments.origins_of_ingredients.epi_value) %]</strong><br>
<strong>[% lang('ecoscore_transportation') %][% sep %]: [% IF product.ecoscore_data.adjustments.origins_of_ingredients.transportation_value.defined && product.ecoscore_data.adjustments.origins_of_ingredients.transportation_value > 0 %]+[% END %][% round(product.ecoscore_data.adjustments.origins_of_ingredients.transportation_value) %]</strong><br>
`
}
},
Expand Down

0 comments on commit c3f3e3f

Please sign in to comment.