Table of Contents

Public classSealed KStemmer

Namespace
Rowles.LeanCorpus.Analysis.Stemmers
Assembly
Rowles.LeanCorpus.dll

Lexicon-validated English stemmer inspired by Krovetz stemming.

public sealed class KStemmer : ISpanStemmer
KStemmer
Implements

Constructors

Public constructor KStemmer(IKStemLexicon)

Initialises a new KStemmer with the supplied base-form lexicon.

Fields

Private fieldStaticRead-onlyPrivate DerivationalRules
Private fieldStaticRead-onlyPrivate Exceptions
Private fieldStaticRead-onlyPrivate InflectionalRules
Private fieldStaticRead-onlyPrivate ProtectedWords
Private fieldRead-onlyPrivate _derivationalBySuffix
Private fieldRead-onlyPrivate _inflectionalBySuffix
Private fieldRead-onlyPrivate _lexicon

Methods

Private methodPrivate ApplyRulesCore(Span<char>, int)

Applies inflectional and derivational rules without re-checking exceptions or the lexicon (caller has already done so).

Private methodStaticPrivate BuildRuleLookup(MorphRule[])

Builds a lookup dictionary keyed by the last 2 characters of each rule's suffix.

Private methodStaticPrivate ContainsVowel(string)
Private methodStaticPrivate ContainsVowelSpan(ReadOnlySpan<char>)
Private methodStaticPrivate IsVowel(char)
Public method Stem(ReadOnlySpan<char>, Span<char>)

Stems word into output. Returns the length of the stemmed result, or -1 if output is too small. The caller must ensure output.Length >= word.Length for guaranteed success.

Public method Stem(string)

Convenience overload returning a stemmed string.

Private methodPrivate StemCore(Span<char>, int)

Core stemming logic operating on the already-lowered word in output. Called from Stem(ReadOnlySpan{char}, Span{char}) which hasn't pre-checked exceptions or the lexicon.

Public method StemPreLowered(ReadOnlySpan<char>, Span<char>)

Same as Stem(ReadOnlySpan{char}, Span{char}) but assumes the input is already lowercased. Callers who have already lowercased via LowercaseFilter can use this to avoid a redundant per-character ToLowerInvariant pass.

Private methodPrivate TryRulesSpan(Span<char>, int, FrozenDictionary<string, MorphRule[]>, out int)
Private methodStaticPrivate UndoubleTrailingConsonantSpan(Span<char>, int)