<<

NAME

ProductOpener::TaxonomiesEnhancer - analyze ingredients and other fields to enrich the taxonomies

SYNOPSIS

ProductOpener::TaxonomiesEnhancer analyze analyze ingredients and other fields to enrich the taxonomies

    use ProductOpener::TaxonomiesEnhancer qw/:all/;

        [..]

        check_ingredients_between_languages($product_ref);

DESCRIPTION

[..]

flatten_ingredients ( ingredients )

This function recursively flattens a nested list of ingredients. If an ingredient contains sub-ingredients, they are flattened into a single-level array.

Arguments

ingredients

An array reference of ingredients that may contain nested sub-ingredients.

Return value

An array of flattened ingredients, each represented as a hash reference.

parse_ingredients_for_language ( ingredients_hash, key )

This function parses and flattens the ingredient list for a specific language based on the provided key.

Arguments

ingredients_hash

A hash reference to the product data containing the ingredient text for various languages.

key

A string representing the language-specific ingredient text key (e.g., "ingredients_text_cs").

Return value

This function does not return a value but modifies the product reference to store the flattened ingredient list under a new key (e.g., "ingredients_cs").

not_enough_known_ingredients ( ingredients1, ingredients2 )

This function checks if all or a certain percentage of ingredients in the first language (reference) overlap with ingredients in second language (to analyze).

Arguments

ingredients1

An array reference of ingredients in the first language (reference).

ingredients2

An array reference of ingredients in the second language (to analyze).

Return value

Returns 1 if the overlap of ingredients between the two lists is below a certain threshold, otherwise returns 0.

detect_missing_stop_words_before_list ( ingredients1, ingredients2, lang1, lang2, missing_stop_words_before )

This function detects missing stop words before the first known ingredient in a list of ingredients.

Arguments

ingredients1

An array reference of ingredients in the first language (reference).

ingredients2

An array reference of ingredients in the second language (to analyze).

lang1

A string representing the language code for the first language.

lang2

A string representing the language code for the second language.

missing_stop_words_before

A hash reference to store the missing stop words before the first known ingredient.

Return value

This function does not return a value but modifies the `missing_stop_words_before` hash reference to store the missing stop words.

get_ingredient_index ( ingredients, ingredient_id )

This function finds the index of a specific ingredient in a list of ingredients based on its ID.

Arguments

ingredients

An array reference of ingredients, where each ingredient is represented as a hash reference.

ingredient_id

A string representing the ID of the ingredient to find.

Return value

Returns the index of the ingredient if found, otherwise returns -1.

detect_missing_stop_words_after_list ( ingredients1, ingredients2, lang1, lang2, missing_stop_words_after )

This function detects missing stop words after the last known ingredient in a list of ingredients.

Arguments

ingredients1

An array reference of ingredients in the first language (reference).

ingredients2

An array reference of ingredients in the second language (to analyze).

lang1

A string representing the language code for the first language.

lang2

A string representing the language code for the second language.

missing_stop_words_after

A hash reference to store the missing stop words after the last known ingredient.

Return value

This function does not return a value but modifies the `missing_stop_words_after` hash reference to store the missing stop words.

remove_duplicates ( @array )

This function removes duplicate elements from an array.

Arguments

@array

An array of elements from which duplicates need to be removed.

Return value

Returns an array with duplicate elements removed.

find_smallest_value_key ( hashmap )

This function finds the key with the smallest value in a hashmap. If multiple keys have the same smallest value, it returns the first key in alphabetical order.

Arguments

hashmap

A hash reference where the keys are strings and the values are numeric.

Return value

Returns the key with the smallest value. If multiple keys have the same smallest value, returns the first key in alphabetical order.

get_sorted_strings ( string1, string2 )

This function returns two strings in alphabetical order.

Arguments

string1

A string to be compared.

string2

A string to be compared.

Return value

Returns a list of two strings sorted in lexicographical order.

detect_missing_ingredients ( ingredients1, ingredients2, lang1, lang2, missing_ingredients, ingredients_typo, mismatch_in_taxonomy )

This function detects missing ingredients and potential typos between two lists of ingredients in different languages.

Arguments

ingredients1

An array reference of ingredients in the first language (reference).

ingredients2

An array reference of ingredients in the second language (to analyze).

lang1

A string representing the language code for the first language.

lang2

A string representing the language code for the second language.

missing_ingredients

A hash reference to store missing ingredients.

ingredients_typo

A hash reference to store potential typos in ingredients.

mismatch_in_taxonomy

A hash reference to store mismatches in the taxonomy between the two languages.

Return value

This function does not return a value but modifies the `missing_ingredients`, `ingredients_typo`, and `mismatch_in_taxonomy` hash references to store the detected issues.

check_ingredients_between_languages ( product_ref )

This function extracts data for each language from the provided product reference. It then detects failed extractions (missing stop words) and identifies missing translations.

Arguments

product_ref

A reference to the product data, which is expected to be a hash reference containing the necessary information.

Return value

This function does not return any value. It performs the extraction and detection internally.

<<