Text 0.6.0 hungariansnowballstemmer stem - CyrilB1531/lodestar GitHub Wiki

Lodestar.Text 0.6.0. This page is frozen at that release. Read the current documentation for what main says now. A link to a decision or a migration page follows main, and leaves the archive.

HungarianSnowballStemmer.Stem

The Snowball stem of one Hungarian word.

public static string Stem(string word)

Parametersword is a single Hungarian word. It is lowercased and NFC-normalised before the rules run, which matters more here than elsewhere: ő and ű are the letters the algorithm is most often got wrong on, and a decomposed one would not be recognised as a vowel.

Returnsstring, the stem, always lowercase, with every accent it carried still on it. Nothing is folded: á and a are different letters to this algorithm.

ExceptionsArgumentNullException when word is null. An empty string, or a word of one character, is returned lowercased and otherwise untouched.

Example — the two long vowels that make Hungarian awkward, stemmed correctly.

using Lodestar.Text.Stemming;

string singular = HungarianSnowballStemmer.Stem("gyűrű");  // => gyűrű
string plural = HungarianSnowballStemmer.Stem("gyűrűk");  // => gyűrű
string vine = HungarianSnowballStemmer.Stem("szőlők");  // => szőlő

Remarks — those three are the reason this stemmer is checked against snowballstemmer and not against nltk like its siblings. ő and ű are missing from nltk 3.10.1's Hungarian vowel set, so R1 lands past the end of the word and nothing is stripped: gyűrű and gyűrűk stay two different keys there, which is the one thing a stemmer exists to prevent. See decision 0091.

A word can lose several layers in one call, because the nine steps run in sequence and each may fire. erdőből is erdő plus the elative -ből, and comes back as the bare noun:

using Lodestar.Text.Stemming;

string elative = HungarianSnowballStemmer.Stem("erdőből");  // => erdő
string plural = HungarianSnowballStemmer.Stem("erdők");  // => erdő
string bare = HungarianSnowballStemmer.Stem("erdő");  // => erdő

Applies to — net10.0, netstandard2.0.

See alsoHungarianSnowballStemmer, the stemming index.