de.aitools.ie.stemming
Class PorterStemmer

java.lang.Object
  extended by de.aitools.ie.stemming.PorterStemmer
All Implemented Interfaces:
Stemmer

public class PorterStemmer
extends java.lang.Object
implements Stemmer

Implementation of the Porter Stemming Algorithm.

This 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, or process(String) respectively.

Author Martin Porter, Source: http://www.tartarus.org/~martin/PorterStemmer.

Modified by webis:

- Method process(String) added to implement the Stemmer interface.

Version:
aitools 2.0 Created on 11.08.2008 $Id: PorterStemmer.java,v 1.1 2010/05/02 15:08:11 poma1006 Exp $
Author:
maik.anderka@medien.uni-weimar.de

Constructor Summary
PorterStemmer()
           
 
Method Summary
 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(java.lang.String[] args)
          Test program for demonstrating the Stemmer.
 java.lang.String process(java.lang.String word)
          Builds the stem of the specified word.
 void stem()
          Stem the word placed into the Stemmer buffer through calls to add().
 java.lang.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.)
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PorterStemmer

public PorterStemmer()
Method Detail

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 java.lang.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 java.lang.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.


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().


process

public java.lang.String process(java.lang.String word)
Description copied from interface: Stemmer
Builds the stem of the specified word.

Specified by:
process in interface Stemmer
Parameters:
word - Word to be stemmed.
Returns:
Stem of the specified word.

main

public static void main(java.lang.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 ...