Table of Contents

YuStemmer

YuStemmer is a natural language stemming library for 15 languages. It reduces an inflected word to a common root form. YuStemmer is algorithmic, which makes it small and fast.

Overview

Word stemming is usually applied to query and search systems. It enables them to return related results with similar meaning but slightly different spelling. As an example, the English stemmer returns “write” for “write”, “writes”, “writing”, and “writings”.

Stemmers are available for these languages:

YuStemmer is fully algorithmic. No extensive lookup dictionaries are needed. This results in small memory footprint and excellent performance.

YuStemmer was initially developed for the DISQLite3 Full Text Search (FTS) engine which is prepared to use it out of the box. Besides that, YuStemmer fits many other purposes.

YuStemmer is organized into different classes, each of them optimized for a particular string type and text encoding:

Make sure to choose the stemmer class matching your string type and character set. Otherwise you will suffer a performance penalty caused by avoidable string conversions. In Delphi, such conversions usually happen implicitly and go unnoticed by most developers. Therefore, pay close attention here to make the most of YuStemmer!

Example – stem a single word

The Stem() method does the work for all of the above classes. It expects a single word and returns its stem. If there is no stem, the original word is returned unchanged.

function StemFrench(const AWord: AnsiString): AnsiString;
var
  Stemmer: TYuStemmer;
begin
  Stemmer := TYuStemmer_French.Create;
  Result := Stemmer.Stem(AWord);
  Stemmer.Free;
end;

Example – stem multiple words in a TStringList

To improve performance when stemming a great number of words, it is safe to reuse the same instance of a stemmer class multiple times.

procedure StemItalian(const AWords: TStringList);
var
  i: Integer;
  { TStringList is UTF-16 in Unicode Delphis. }
  Stemmer: {$IFDEF Unicode}TYuStemmer_16{$ELSE}TYuStemmer{$ENDIF};
begin
  {$IFDEF Unicode}
  Stemmer := TYuStemmer_Italian_16.Create;
  {$ELSE Unicode}
  Stemmer := TYuStemmer_Italian.Create;
  {$ENDIF Unicode}
  for i := 0 to AWords.Count - 1 do
    AWords[i] := Stemmer.Stem(AWords[i]);
  Stemmer.Free;
end;