FileDocCategorySizeDatePackage
SnowballFilter.javaAPI DocApache Lucene 1.92569Mon Feb 20 09:17:50 GMT 2006org.apache.lucene.analysis.snowball

SnowballFilter

public class SnowballFilter extends TokenFilter
A filter that stems words using a Snowball-generated stemmer. Available stemmers are listed in {@link net.sf.snowball.ext}. The name of a stemmer is the part of the class name before "Stemmer", e.g., the stemmer in {@link EnglishStemmer} is named "English".

Fields Summary
private static final Object[]
EMPTY_ARGS
private net.sf.snowball.SnowballProgram
stemmer
private Method
stemMethod
Constructors Summary
public SnowballFilter(TokenStream in, String name)
Construct the named stemming filter.

param
in the input tokens to stem
param
name the name of a stemmer


                        
       
    super(in);
    try {
      Class stemClass =
        Class.forName("net.sf.snowball.ext." + name + "Stemmer");
      stemmer = (SnowballProgram) stemClass.newInstance();
      // why doesn't the SnowballProgram class have an (abstract?) stem method?
      stemMethod = stemClass.getMethod("stem", new Class[0]);
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
  
Methods Summary
public final org.apache.lucene.analysis.Tokennext()
Returns the next input Token, after being stemmed

    Token token = input.next();
    if (token == null)
      return null;
    stemmer.setCurrent(token.termText());
    try {
      stemMethod.invoke(stemmer, EMPTY_ARGS);
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
    
    Token newToken = new Token(stemmer.getCurrent(),
                      token.startOffset(), token.endOffset(), token.type());
    newToken.setPositionIncrement(token.getPositionIncrement());
    return newToken;