Text porterstemmer stem - CyrilB1531/lodestar GitHub Wiki

Development build. This page describes main, not a released package. The latest published Lodestar.Text is 0.7.0 — read its documentation.

Home › Text › Stemming

PorterStemmer.Stem

The Porter stem of one English word.

public static string Stem(string word)
public static string Stem(string word, PorterStemmerMode mode)

Parameters — word is a single word, not a sentence. It is lowercased before the first step runs. mode picks the published form: PorterStemmerMode.OriginalAlgorithm, what the first overload applies, or PorterStemmerMode.MartinExtensions.

Returns — string, the stem, always lowercase.

Exceptions — ArgumentNullException when word is null; ArgumentException when mode is not a defined PorterStemmerMode. An empty string is returned unchanged. A word of one or two letters is stemmed like any other by the paper — "as" becomes "a" — and returned lowercased and unchanged under Martin's extensions.

Example — the same word under both English stemmers, which is the only reason to prefer this one.

using Lodestar.Text.Stemming;

string original = PorterStemmer.Stem("ties");  // => ti
string revised = EnglishSnowballStemmer.Stem("ties");  // => tie

Remarks — ti is not a mistake in this implementation; it is what the 1980 algorithm specifies, and nltk returns it too. Preserving that is the point of shipping the original at all. If the answer looks wrong, the fix is EnglishSnowballStemmer.Stem, not a patch here.

The two modes part on three rules, and only there: the paper turns abli into able where Martin's implementation turns any bli into ble, only Martin's turns logi into log, and only Martin's leaves a word of two letters alone.

using Lodestar.Text.Stemming;

string paper = PorterStemmer.Stem("analogy");  // => analogi
string martin = PorterStemmer.Stem("analogy", PorterStemmerMode.MartinExtensions);  // => analog

Only ASCII letters are treated as letters. Accented input is neither rejected nor folded — it is simply not what the rules were written for, and another language's stemmer is the right answer for another language's text.

Applies to — net10.0, netstandard2.0.

See also — PorterStemmer, PorterStemmerMode, EnglishSnowballStemmer.Stem, the stemming index.