Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / Analysis / StopFilter.cs
blob08a3fcd83f5351f5f9705e909f7db2feebf3e963
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> Removes stop words from a token stream.</summary>
22 public sealed class StopFilter : TokenFilter
25 private System.Collections.Hashtable stopWords;
27 /// <summary> Constructs a filter which removes words from the input
28 /// TokenStream that are named in the array of words.
29 /// </summary>
30 public StopFilter(TokenStream in_Renamed, System.String[] stopWords) : base(in_Renamed)
32 this.stopWords = MakeStopSet(stopWords);
35 /// <summary> Constructs a filter which removes words from the input
36 /// TokenStream that are named in the Hashtable.
37 ///
38 /// </summary>
39 /// <deprecated> Use {@link #StopFilter(TokenStream, Set)} instead
40 /// </deprecated>
41 public StopFilter(TokenStream in_Renamed, System.Collections.Hashtable stopTable) : base(in_Renamed)
43 stopWords = new System.Collections.Hashtable(new System.Collections.Hashtable(stopTable));
46 /// <summary> Builds a Hashtable from an array of stop words,
47 /// appropriate for passing into the StopFilter constructor.
48 /// This permits this table construction to be cached once when
49 /// an Analyzer is constructed.
50 ///
51 /// </summary>
52 /// <deprecated> Use {@link #MakeStopSet(String[])} instead.
53 /// </deprecated>
54 public static System.Collections.Hashtable MakeStopTable(System.String[] stopWords)
56 System.Collections.Hashtable stopTable = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable(stopWords.Length));
57 for (int i = 0; i < stopWords.Length; i++)
58 stopTable[stopWords[i]] = stopWords[i];
59 return stopTable;
62 /// <summary> Builds a Set from an array of stop words,
63 /// appropriate for passing into the StopFilter constructor.
64 /// This permits this stopWords construction to be cached once when
65 /// an Analyzer is constructed.
66 /// </summary>
67 public static System.Collections.Hashtable MakeStopSet(System.String[] stopWords)
69 System.Collections.Hashtable stopTable = new System.Collections.Hashtable(stopWords.Length);
70 for (int i = 0; i < stopWords.Length; i++)
71 stopTable.Add(stopWords[i], stopWords[i]);
72 return stopTable;
75 /// <summary> Returns the next input Token whose termText() is not a stop word.</summary>
76 public override Token Next()
78 // return the first non-stop word found
79 for (Token token = input.Next(); token != null; token = input.Next())
80 if (!stopWords.Contains(token.termText))
81 return token;
82 // reached EOS -- return null
83 return null;