1 package org.apache.lucene.analysis; 2 3 18 19 import junit.framework.TestCase; 20 21 import java.io.StringReader ; 22 import java.io.IOException ; 23 import java.util.Set ; 24 import java.util.HashSet ; 25 26 public class TestStopAnalyzer extends TestCase { 27 private StopAnalyzer stop = new StopAnalyzer(); 28 29 private Set inValidTokens = new HashSet (); 30 public TestStopAnalyzer(String s) { 31 super(s); 32 } 33 34 protected void setUp() { 35 for (int i = 0; i < StopAnalyzer.ENGLISH_STOP_WORDS.length; i++) { 36 inValidTokens.add(StopAnalyzer.ENGLISH_STOP_WORDS[i]); 37 } 38 } 39 40 public void testDefaults() { 41 assertTrue(stop != null); 42 StringReader reader = new StringReader ("This is a test of the english stop analyzer"); 43 TokenStream stream = stop.tokenStream("test", reader); 44 assertTrue(stream != null); 45 Token token = null; 46 try { 47 while ((token = stream.next()) != null) 48 { 49 assertTrue(inValidTokens.contains(token.termText()) == false); 50 } 51 } catch (IOException e) { 52 assertTrue(false); 53 } 54 } 55 56 public void testStopList() { 57 Set stopWordsSet = new HashSet (); 58 stopWordsSet.add("good"); 59 stopWordsSet.add("test"); 60 stopWordsSet.add("analyzer"); 61 StopAnalyzer newStop = new StopAnalyzer((String [])stopWordsSet.toArray(new String [3])); 62 StringReader reader = new StringReader ("This is a good test of the english stop analyzer"); 63 TokenStream stream = newStop.tokenStream("test", reader); 64 assertTrue(stream != null); 65 Token token = null; 66 try { 67 while ((token = stream.next()) != null) 68 { 69 String text = token.termText(); 70 assertTrue(stopWordsSet.contains(text) == false); 71 } 72 } catch (IOException e) { 73 assertTrue(false); 74 } 75 } 76 } 77 | Popular Tags |