Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / Analysis / PorterStemFilter.cs
blob480b682e4728209a314ad4ab9761add2f201fd0a
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 using System;
17 namespace Lucene.Net.Analysis
20 /// <summary>Transforms the token stream as per the Porter stemming algorithm.
21 /// Note: the input to the stemming filter must already be in lower case,
22 /// so you will need to use LowerCaseFilter or LowerCaseTokenizer farther
23 /// down the Tokenizer chain in order for this to work properly!
24 /// <P>
25 /// To use this filter with other analyzers, you'll want to write an
26 /// Analyzer class that sets up the TokenStream chain as you want it.
27 /// To use this with LowerCaseTokenizer, for example, you'd write an
28 /// analyzer like this:
29 /// <P>
30 /// <PRE>
31 /// class MyAnalyzer extends Analyzer {
32 /// public final TokenStream tokenStream(String fieldName, Reader reader) {
33 /// return new PorterStemFilter(new LowerCaseTokenizer(reader));
34 /// }
35 /// }
36 /// </PRE>
37 /// </summary>
38 public sealed class PorterStemFilter : TokenFilter
40 private PorterStemmer stemmer;
42 public PorterStemFilter(TokenStream in_Renamed) : base(in_Renamed)
44 stemmer = new PorterStemmer();
47 /// <summary>Returns the next input Token, after being stemmed </summary>
48 public override Token Next()
50 Token token = input.Next();
51 if (token == null)
52 return null;
53 else
55 System.String s = stemmer.Stem(token.termText);
56 if ((System.Object) s != (System.Object) token.termText)
57 // Yes, I mean object reference comparison here
58 token.termText = s;
59 return token;