<<

NAME

ProductOpener::Misspellings - Generic misspelling correction module

SYNOPSIS

  use ProductOpener::Misspellings qw/apply_misspelling_replacements/;

  # Apply corrections from misspellings/ingredients_misspellings.txt
  apply_misspelling_replacements("misspellings", $lc, \$text);

DESCRIPTION

This module provides generic misspelling correction functionality that can be used across different fields (ingredients, brands, etc.) to fix common misspellings found in product data.

Data files are stored in the misspellings/ directory, one file per field. The filename is derived from the $field parameter: $field . ".txt".

init_misspellings($field)

Loads the misspelling data file misspellings/$field.txt into a cache. Returns early if already loaded.

apply_misspelling_replacements($field, $lc, $text_ref)

Applies misspelling corrections from misspellings/$field.txt to $text_ref.

Parameters: - $field: the data file name (without .txt), e.g. "ingredients_misspellings" - $lc: the language code of the text being processed - $text_ref: reference to the text string to modify

Matching is case-insensitive. If the target string has mixed case (e.g. "Marks & Spencers"), it is output as-is regardless of the source case. Otherwise, the source case is preserved.

apply_case_to_misspelling($matched, $replacement)

Determines the correct case for the replacement string based on the matched text.

If the replacement has mixed case, it is returned as-is. Otherwise, the case pattern of the matched text is applied to the replacement: - all uppercase -> all uppercase replacement - all lowercase -> all lowercase replacement - title case -> ucfirst replacement - otherwise -> per-character case preservation

<<