2 * Copyright 2004 The Apache Software Foundation
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 using NUnit.Framework;
\r
18 namespace Lucene.Net.Analysis
\r
21 public class TestStopAnalyzer
\r
23 private StopAnalyzer stop = new StopAnalyzer();
\r
25 private System.Collections.Hashtable inValidTokens = new System.Collections.Hashtable();
\r
28 protected virtual void SetUp()
\r
30 for (int i = 0; i < StopAnalyzer.ENGLISH_STOP_WORDS.Length; i++)
\r
32 inValidTokens.Add(StopAnalyzer.ENGLISH_STOP_WORDS[i], StopAnalyzer.ENGLISH_STOP_WORDS[i]);
\r
37 public virtual void TestDefaults()
\r
39 Assert.IsTrue(stop != null);
\r
40 System.IO.StringReader reader = new System.IO.StringReader("This is a test of the english stop analyzer");
\r
41 TokenStream stream = stop.TokenStream("test", reader);
\r
42 Assert.IsTrue(stream != null);
\r
46 while ((token = stream.Next()) != null)
\r
48 Assert.IsTrue(inValidTokens.Contains(token.TermText()) == false);
\r
51 catch (System.IO.IOException e)
\r
53 Assert.IsTrue(false);
\r
58 public virtual void TestStopList()
\r
60 System.Collections.Hashtable stopWordsSet = new System.Collections.Hashtable();
\r
61 stopWordsSet.Add("good", "good");
\r
62 stopWordsSet.Add("test", "test");
\r
63 stopWordsSet.Add("analyzer", "analyzer");
\r
65 // {{Aroush how can we copy 'stopWordsSet' to 'System.String[]'?
\r
66 System.String[] arrStopWordsSet = new System.String[3];
67 arrStopWordsSet[0] = "good";
68 arrStopWordsSet[1] = "test";
69 arrStopWordsSet[2] = "analyzer";
72 StopAnalyzer newStop = new StopAnalyzer(arrStopWordsSet);
\r
73 System.IO.StringReader reader = new System.IO.StringReader("This is a good test of the english stop analyzer");
\r
74 TokenStream stream = newStop.TokenStream("test", reader);
\r
75 Assert.IsTrue(stream != null);
\r
79 while ((token = stream.Next()) != null)
\r
81 System.String text = token.TermText();
\r
82 Assert.IsTrue(stopWordsSet.Contains(text) == false);
\r
85 catch (System.IO.IOException e)
\r
87 Assert.IsTrue(false);
\r