2 * Copyright 2004 The Apache Software Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 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.
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.
39 /// <deprecated> Use {@link #StopFilter(TokenStream, Set)} instead
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.
52 /// <deprecated> Use {@link #MakeStopSet(String[])} instead.
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
];
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.
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
]);
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
))
82 // reached EOS -- return null