add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / analyzers / common / src / java / org / apache / lucene / analysis / ru / RussianStemFilter.java
1 package org.apache.lucene.analysis.ru;
2
3 /**
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
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
28
29 import java.io.IOException;
30
31 /**
32  * A {@link TokenFilter} that stems Russian words. 
33  * <p>
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.
37  * </p>
38  * <p>
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}.
42  * </p>
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
47  */
48 @Deprecated
49 public final class RussianStemFilter extends TokenFilter
50 {
51     /**
52      * The actual token in the input stream.
53      */
54     private RussianStemmer stemmer = new RussianStemmer();
55
56     private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
57     private final KeywordAttribute keywordAttr = addAttribute(KeywordAttribute.class);
58
59     public RussianStemFilter(TokenStream in)
60     {
61         super(in);
62     }
63     /**
64      * Returns the next token in the stream, or null at EOS
65      */
66     @Override
67     public final boolean incrementToken() throws IOException
68     {
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);
75         }
76         return true;
77       } else {
78         return false;
79       }
80     }
81
82
83     /**
84      * Set a alternative/custom {@link RussianStemmer} for this filter.
85      */
86     public void setStemmer(RussianStemmer stemmer)
87     {
88         if (stemmer != null)
89         {
90             this.stemmer = stemmer;
91         }
92     }
93 }