GermanNormalizer
in package
implements
NormalizerInterface
Restores German umlauts written as "ae", "oe" and "ue", so "Muenchen" finds "München".
Follows the rules of Lucene's GermanNormalizationFilter: "ae" and "oe" always become "ä" and "ö", "ue" becomes "ü" unless it follows a vowel or "q", which keeps "Feuer", "Bauer" and "Quelle" intact. Lucene replaces the umlauts by plain vowels right away. Here they are kept for the stemmer and stripped by the tokenizer afterwards, which leads to the same result.
Words of other languages than German are returned unchanged.
Table of Contents
Interfaces
- NormalizerInterface
- Unifies different spellings of the same word before stemming, e.g. "Muenchen" and "München".
Constants
- STATE_DEFAULT = 0
- Ordinary state
- STATE_UMLAUT = 2
- After an "a", "o" or "u" that a following "e" turns into an umlaut
- STATE_VOWEL = 1
- After a vowel or "q", a following "u" does not start an umlaut
- UMLAUTS = ['a' => 'ä', 'o' => 'ö', 'u' => 'ü']
Methods
- normalize() : string
Constants
STATE_DEFAULT
Ordinary state
private
mixed
STATE_DEFAULT
= 0
STATE_UMLAUT
After an "a", "o" or "u" that a following "e" turns into an umlaut
private
mixed
STATE_UMLAUT
= 2
STATE_VOWEL
After a vowel or "q", a following "u" does not start an umlaut
private
mixed
STATE_VOWEL
= 1
UMLAUTS
private
mixed
UMLAUTS
= ['a' => 'ä', 'o' => 'ö', 'u' => 'ü']
Methods
normalize()
public
normalize(string $word, string $locale) : string
Parameters
- $word : string
-
Lowercased and trimmed, accents are kept (they are stripped after stemming)
- $locale : string
-
The language of the word as locale ID or language tag, e.g. "de", "de_CH" or "de-CH". Return the word unchanged for languages the normalizer does not support.