cvsimport
[beagle.git] / beagled / Lucene.Net / Analysis / PorterStemFilter.cs
blob7dc2e29a336d44c10f3bcf3de478320711f73da0
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.
17 using System;
19 namespace Lucene.Net.Analysis
22 /// <summary>Transforms the token stream as per the Porter stemming algorithm.
23 /// Note: the input to the stemming filter must already be in lower case,
24 /// so you will need to use LowerCaseFilter or LowerCaseTokenizer farther
25 /// down the Tokenizer chain in order for this to work properly!
26 /// <P>
27 /// To use this filter with other analyzers, you'll want to write an
28 /// Analyzer class that sets up the TokenStream chain as you want it.
29 /// To use this with LowerCaseTokenizer, for example, you'd write an
30 /// analyzer like this:
31 /// <P>
32 /// <PRE>
33 /// class MyAnalyzer extends Analyzer {
34 /// public final TokenStream tokenStream(String fieldName, Reader reader) {
35 /// return new PorterStemFilter(new LowerCaseTokenizer(reader));
36 /// }
37 /// }
38 /// </PRE>
39 /// </summary>
40 public sealed class PorterStemFilter : TokenFilter
42 private PorterStemmer stemmer;
44 public PorterStemFilter(TokenStream in_Renamed) : base(in_Renamed)
46 stemmer = new PorterStemmer();
49 /// <summary>Returns the next input Token, after being stemmed </summary>
50 public override Token Next()
52 Token token = input.Next();
53 if (token == null)
54 return null;
55 else
57 System.String s = stemmer.Stem(token.termText);
58 if ((System.Object) s != (System.Object) token.termText)
59 // Yes, I mean object reference comparison here
60 token.termText = s;
61 return token;