Class PorterStemmer


  • public final class PorterStemmer
    extends Object
    Stemmer, implementing the Porter Stemming Algorithm The Stemmer class transforms a word into its root form. The input word can be provided a character at time (by calling add()), or at once by calling one of the various stem(something) methods.
    • Constructor Summary

      Constructors 
      Constructor Description
      PorterStemmer()
      Instantiates a new Porter stemmer.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(char ch)
      Add a character to the word being stemmed.
      void add​(char[] w, int wLen)
      Adds wLen characters to the word being stemmed contained in a portion of a char[] array.
      char[] getResultBuffer()
      Returns a reference to a character buffer containing the results of the stemming process.
      int getResultLength()
      Returns the length of the word resulting from the stemming process.
      static void main​(String[] args)
      Test program for demonstrating the Stemmer.
      void stem()
      Stem the word placed into the Stemmer buffer through calls to add().
      String toString()
      After a word has been stemmed, it can be retrieved by toString(), or a reference to the internal buffer can be retrieved by getResultBuffer and getResultLength (which is generally more efficient.)
    • Constructor Detail

      • PorterStemmer

        public PorterStemmer()
        Instantiates a new Porter stemmer.
    • Method Detail

      • main

        public static void main​(String[] args)
        Test program for demonstrating the Stemmer. It reads text from a a list of files, stems each word, and writes the result to standard output. Note that the word stemmed is expected to be in lower case: forcing lower case must be done outside the Stemmer class. Usage: Stemmer file-name file-name ...
        Parameters:
        args - the input arguments
      • add

        public void add​(char ch)
        Add a character to the word being stemmed. When you are finished adding characters, you can call stem(void) to stem the word.
        Parameters:
        ch - the ch
      • add

        public void add​(char[] w,
                        int wLen)
        Adds wLen characters to the word being stemmed contained in a portion of a char[] array. This is like repeated calls of add(char ch), but faster.
        Parameters:
        w - the w
        wLen - the w len
      • getResultBuffer

        public char[] getResultBuffer()
        Returns a reference to a character buffer containing the results of the stemming process. You also need to consult getResultLength() to determine the length of the result.
        Returns:
        the result buffer
      • getResultLength

        public int getResultLength()
        Returns the length of the word resulting from the stemming process.
        Returns:
        the result length
      • stem

        public void stem()
        Stem the word placed into the Stemmer buffer through calls to add(). Returns true if the stemming process resulted in a word different from the input. You can retrieve the result with getResultLength()/getResultBuffer() or toString().
      • toString

        public String toString()
        After a word has been stemmed, it can be retrieved by toString(), or a reference to the internal buffer can be retrieved by getResultBuffer and getResultLength (which is generally more efficient.)
        Overrides:
        toString in class Object