1 package org.apache.lucene.analysis.ru; 2 3 18 19 import org.apache.lucene.analysis.Token; 20 import org.apache.lucene.analysis.TokenFilter; 21 import org.apache.lucene.analysis.TokenStream; 22 import java.io.IOException ; 23 24 32 public final class RussianStemFilter extends TokenFilter 33 { 34 37 private Token token = null; 38 private RussianStemmer stemmer = null; 39 40 public RussianStemFilter(TokenStream in, char[] charset) 41 { 42 super(in); 43 stemmer = new RussianStemmer(charset); 44 } 45 46 49 public final Token next() throws IOException 50 { 51 if ((token = input.next()) == null) 52 { 53 return null; 54 } 55 else 56 { 57 String s = stemmer.stem(token.termText()); 58 if (!s.equals(token.termText())) 59 { 60 return new Token(s, token.startOffset(), token.endOffset(), 61 token.type()); 62 } 63 return token; 64 } 65 } 66 67 70 public void setStemmer(RussianStemmer stemmer) 71 { 72 if (stemmer != null) 73 { 74 this.stemmer = stemmer; 75 } 76 } 77 } 78 | Popular Tags |