1 package org.apache.lucene.analysis.ru;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import org.apache.lucene.analysis.KeywordMarkerFilter;// for javadoc
21 import org.apache.lucene.analysis.LowerCaseFilter; // for javadoc
22 import org.apache.lucene.analysis.TokenFilter;
23 import org.apache.lucene.analysis.TokenStream;
24 import org.apache.lucene.analysis.tokenattributes.KeywordAttribute;
25 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
26 import org.apache.lucene.analysis.ru.RussianStemmer;//javadoc @link
27 import org.apache.lucene.analysis.snowball.SnowballFilter; // javadoc @link
29 import java.io.IOException;
32 * A {@link TokenFilter} that stems Russian words.
34 * The implementation was inspired by GermanStemFilter.
35 * The input should be filtered by {@link LowerCaseFilter} before passing it to RussianStemFilter ,
36 * because RussianStemFilter only works with lowercase characters.
39 * To prevent terms from being stemmed use an instance of
40 * {@link KeywordMarkerFilter} or a custom {@link TokenFilter} that sets
41 * the {@link KeywordAttribute} before this {@link TokenStream}.
43 * @see KeywordMarkerFilter
44 * @deprecated Use {@link SnowballFilter} with
45 * {@link org.tartarus.snowball.ext.RussianStemmer} instead, which has the
46 * same functionality. This filter will be removed in Lucene 4.0
49 public final class RussianStemFilter extends TokenFilter
52 * The actual token in the input stream.
54 private RussianStemmer stemmer = new RussianStemmer();
56 private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
57 private final KeywordAttribute keywordAttr = addAttribute(KeywordAttribute.class);
59 public RussianStemFilter(TokenStream in)
64 * Returns the next token in the stream, or null at EOS
67 public final boolean incrementToken() throws IOException
69 if (input.incrementToken()) {
70 if(!keywordAttr.isKeyword()) {
71 final String term = termAtt.toString();
72 final String s = stemmer.stem(term);
73 if (s != null && !s.equals(term))
74 termAtt.setEmpty().append(s);
84 * Set a alternative/custom {@link RussianStemmer} for this filter.
86 public void setStemmer(RussianStemmer stemmer)
90 this.stemmer = stemmer;