Class DefaultStringNormalizer

java.lang.Object
org.tentackle.common.DefaultStringNormalizer
All Implemented Interfaces:
StringNormalizer

@Service(StringNormalizer.class) public class DefaultStringNormalizer extends Object implements StringNormalizer
The default normalizer (works sufficiently for most Western languages).

normalize(String) converts diacritics and umlauts, converts to uppercase, keeps only letters, digits and the field separator, and applies some phonetic reductions, such as SCH to S, CH to K, repeated letters to a single one, IE to I and dropping the H between a vowel and a consonant. Words are concatenated, while the field separator is kept (repeated separators collapse into one).

Notice that changing the normalization rules changes the normalized texts persisted in the database.

Author:
harald
  • Constructor Details

    • DefaultStringNormalizer

      public DefaultStringNormalizer(char fieldSeparator, char wordSeparator)
      Creates a normalizer.
      Parameters:
      fieldSeparator - separator between text fields, 0 if none
      wordSeparator - separator between words during reduction
    • DefaultStringNormalizer

      public DefaultStringNormalizer()
      Creates a normalizer.
      With a comma as the field separator and space as word separator.
  • Method Details

    • unDiacrit

      public String unDiacrit(String str, boolean keepLength)
      Description copied from interface: StringNormalizer
      Converts special Unicode characters (so-called diacritics) to standard ASCII.
      Supports also special German and Northern European "umlauts".

      Characters that cannot be converted to the printable ASCII range are dropped, unless keepLength is true, in which case they are replaced by a question mark.

      Specified by:
      unDiacrit in interface StringNormalizer
      Parameters:
      str - the string to be converted
      keepLength - true if the length should be kept, i.e., no Ä to AE, but to A
      Returns:
      the converted string, null if str is null
    • normalize

      public String normalize(String str)
      Normalizes a string (phonetically) for use as PDO.normText.
      Specified by:
      normalize in interface StringNormalizer
      Parameters:
      str - the string to be normalized
      Returns:
      the normalized string, null if str is null