Skip to content

Commit

Permalink
feat: dq_detect_url_in_ingredients (#9586)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbenben2 authored Jan 30, 2024
1 parent 0708361 commit 5695fb4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ProductOpener/DataQualityFood.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,10 @@ sub check_ingredients ($product_ref) {
"en:ingredients-" . $display_lc . "-unexpected-chars-question-mark";
}

if ($product_ref->{$ingredients_text_lc} =~ /http/i) {
add_tag($product_ref, "data_quality_errors", "en:ingredients-" . $display_lc . "-unexpected-url");
}

# French specific
#if ($display_lc eq 'fr') {

Expand Down
29 changes: 29 additions & 0 deletions tests/unit/dataqualityfood.t
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,35 @@ ok(!has_tag($product_ref, 'data_quality', 'en:nutrition-sugars-plus-starch-great
'sum of sugars and starch greater carbohydrates')
or diag explain $product_ref;

# unexpected character in ingredients
$product_ref = {
languages_codes => {
en => 1
},
lc => 'en',
ingredients_text_en => 'AaaAAa, BbbBBB, $, @, !, ?, Https://,',
};
ProductOpener::DataQuality::check_quality($product_ref);

ok(has_tag($product_ref, 'data_quality', 'en:ingredients-en-5-vowels'), '5 vowel in a row')
or diag explain $product_ref;
ok(has_tag($product_ref, 'data_quality', 'en:ingredients-en-5-consonants'), '5 consonants in a row')
or diag explain $product_ref;
ok(has_tag($product_ref, 'data_quality', 'en:ingredients-en-4-repeated-chars'), '4 repeated characters')
or diag explain $product_ref;
ok(has_tag($product_ref, 'data_quality', 'en:ingredients-en-unexpected-chars-currencies'), '$')
or diag explain $product_ref;
ok(has_tag($product_ref, 'data_quality', 'en:ingredients-en-unexpected-chars-arobase'), '@')
or diag explain $product_ref;
ok(has_tag($product_ref, 'data_quality', 'en:ingredients-en-unexpected-chars-exclamation-mark'), '!')
or diag explain $product_ref;
ok(has_tag($product_ref, 'data_quality', 'en:ingredients-en-unexpected-chars-question-mark'), '?')
or diag explain $product_ref;
ok(has_tag($product_ref, 'data_quality', 'en:ingredients-en-ending-comma'), ',')
or diag explain $product_ref;
ok(has_tag($product_ref, 'data_quality', 'en:ingredients-en-unexpected-url'), 'detected url')
or diag explain $product_ref;

# jam and related categories and fruit (specific ingredients) content
## missing specific ingredients
$product_ref = {
Expand Down

0 comments on commit 5695fb4

Please sign in to comment.