Class PorterStemmer

java.lang.Object
org.ujmp.core.util.PorterStemmer

public 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.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private char[]
     
    private int
     
    private int
     
    private static final int
     
    private int
     
    private int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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.
    private final boolean
    cons(int i)
     
    private final boolean
    cvc(int i)
     
    private final boolean
    doublec(int j)
     
    private final boolean
     
    char[]
    Returns a reference to a character buffer containing the results of the stemming process.
    int
    Returns the length of the word resulting from the stemming process.
    private final int
    m()
     
    static void
    main(String[] args)
    Test program for demonstrating the Stemmer.
    private final void
    r(String s)
     
    private final void
     
    void
    Stem the word placed into the Stemmer buffer through calls to add().
    Stem a word provided as a String.
    private final void
     
    private final void
     
    private final void
     
    private final void
     
    private final void
     
    private final void
     
    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.)
    private final boolean
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • b

      private char[] b
    • i

      private int i
    • i_end

      private int i_end
    • j

      private int j
    • k

      private int k
    • INC

      private static final int INC
      See Also:
  • Constructor Details

    • PorterStemmer

      public PorterStemmer()
  • Method Details

    • 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.
    • 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.
    • 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
    • getResultLength

      public int getResultLength()
      Returns the length of the word resulting from the stemming process.
    • 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.
    • cons

      private final boolean cons(int i)
    • m

      private final int m()
    • vowelinstem

      private final boolean vowelinstem()
    • doublec

      private final boolean doublec(int j)
    • cvc

      private final boolean cvc(int i)
    • ends

      private final boolean ends(String s)
    • setto

      private final void setto(String s)
    • r

      private final void r(String s)
    • step1

      private final void step1()
    • step2

      private final void step2()
    • step3

      private final void step3()
    • step4

      private final void step4()
    • step5

      private final void step5()
    • step6

      private final void step6()
    • stem

      public String stem(String s)
      Stem a word provided as a String. Returns the result as a String.
    • 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().
    • 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 ...