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 Summary
ConstructorsConstructorDescriptionCreates a normalizer.
With a comma as the field separator and space as word separator.DefaultStringNormalizer(char fieldSeparator, char wordSeparator) Creates a normalizer. -
Method Summary
Modifier and TypeMethodDescriptionNormalizes a string (phonetically) for use as PDO.normText.Converts special Unicode characters (so-called diacritics) to standard ASCII.
Supports also special German and Northern European "umlauts".
-
Constructor Details
-
DefaultStringNormalizer
public DefaultStringNormalizer(char fieldSeparator, char wordSeparator) Creates a normalizer.- Parameters:
fieldSeparator- separator between text fields, 0 if nonewordSeparator- 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
Description copied from interface:StringNormalizerConverts 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
keepLengthis true, in which case they are replaced by a question mark.- Specified by:
unDiacritin interfaceStringNormalizer- Parameters:
str- the string to be convertedkeepLength- 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
Normalizes a string (phonetically) for use as PDO.normText.- Specified by:
normalizein interfaceStringNormalizer- Parameters:
str- the string to be normalized- Returns:
- the normalized string, null if str is null
-