<<

NAME

ProductOpener::Ingredients - process and analyze ingredients lists

SYNOPSIS

ProductOpener::IngredientsStrings contains some strings and regular expressions used in ProductOpener::Ingredients.

DESCRIPTION

[..]

FUNCTIONS

init_percent_or_quantity_regexps($ingredients_lc) - initialize regular expressions needed for ingredients parsing

This function creates regular expressions that match quantities or percent of an ingredient, including localized strings like "minimum"

_compound_unit_regexp_alternatives ()

Build regex alternatives for compound units: numerator + solidus + denominator (e.g. mg/kg, IU/kg, UFC/g).

protect_compound_unit_slashes ($text)

Replace the solidus inside known compound units (e.g. mg/kg, IU/kg, UFC/g) with Unicode fraction slash U+2044 so that ingredient separator matching does not split on it.

Additive enumerations such as E322/E333 are left unchanged because the pattern only matches known unit names from the shared unit vocabulary.

isolate_compound_unit_quantities ($ingredients_lc, $text)

Wrap compound-unit quantities (450 mg/kg, 500 IU/kg, ...) in list separators when they are glued between two words, so that the parser's existing quantity extraction can pick them up: quantities are only consumed at segment boundaries (after a separator, or at the start/end of an ingredient). Protecting the solidus in protect_compound_unit_slashes removed the accidental / splits that used to create those boundaries, so "L-carnitine 450 mg/kg sulfate de glucosamine" otherwise stays one segment whose middle quantity glues into the ingredient name and breaks taxonomy matching (#6132 follow-up).

Only compound units are isolated: simple units and percents have established boundary behaviors (e.g. "12% de matière grasse") that must not change. Localized minimum and maximum qualifiers after a quantity are kept at the segment end so the existing quantity parser can consume them.

unit_only_string( $ingredients_lc, $string )

Return true if the string is only a dosage context: a unit, optionally preceded by a solidus ("/kg", or U+2044 after protect_compound_unit_slashes) or a "per" word ("par kg", "pro kg"), or a list of such units ("mg, kg"), so that parenthesized dosage contexts like "Additifs nutritionnels (/kg)" or "Additifs (par kg)" are not turned into sub-ingredients.

<<