~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to lucene/src/test/org/apache/lucene/analysis/TestWordlistLoader.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.lucene.analysis;
2
 
 
3
 
/**
4
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
5
 
 * contributor license agreements.  See the NOTICE file distributed with
6
 
 * this work for additional information regarding copyright ownership.
7
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
8
 
 * (the "License"); you may not use this file except in compliance with
9
 
 * the License.  You may obtain a copy of the License at
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
13
 
 * Unless required by applicable law or agreed to in writing, software
14
 
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 
 * See the License for the specific language governing permissions and
17
 
 * limitations under the License.
18
 
 */
19
 
 
20
 
import java.io.BufferedReader;
21
 
import java.io.IOException;
22
 
import java.io.StringReader;
23
 
 
24
 
import org.apache.lucene.util.LuceneTestCase;
25
 
 
26
 
public class TestWordlistLoader extends LuceneTestCase {
27
 
 
28
 
  public void testWordlistLoading() throws IOException {
29
 
    String s = "ONE\n  two \nthree";
30
 
    CharArraySet wordSet1 = WordlistLoader.getWordSet(new StringReader(s), TEST_VERSION_CURRENT);
31
 
    checkSet(wordSet1);
32
 
    CharArraySet wordSet2 = WordlistLoader.getWordSet(new BufferedReader(new StringReader(s)), TEST_VERSION_CURRENT);
33
 
    checkSet(wordSet2);
34
 
  }
35
 
 
36
 
  public void testComments() throws Exception {
37
 
    String s = "ONE\n  two \nthree\n#comment";
38
 
    CharArraySet wordSet1 = WordlistLoader.getWordSet(new StringReader(s), "#", TEST_VERSION_CURRENT);
39
 
    checkSet(wordSet1);
40
 
    assertFalse(wordSet1.contains("#comment"));
41
 
    assertFalse(wordSet1.contains("comment"));
42
 
  }
43
 
 
44
 
 
45
 
  private void checkSet(CharArraySet wordset) {
46
 
    assertEquals(3, wordset.size());
47
 
    assertTrue(wordset.contains("ONE"));                // case is not modified
48
 
    assertTrue(wordset.contains("two"));                // surrounding whitespace is removed
49
 
    assertTrue(wordset.contains("three"));
50
 
    assertFalse(wordset.contains("four"));
51
 
  }
52
 
 
53
 
  /**
54
 
   * Test stopwords in snowball format
55
 
   */
56
 
  public void testSnowballListLoading() throws IOException {
57
 
    String s = 
58
 
      "|comment\n" + // commented line
59
 
      " |comment\n" + // commented line with leading whitespace
60
 
      "\n" + // blank line
61
 
      "  \t\n" + // line with only whitespace
62
 
      " |comment | comment\n" + // commented line with comment
63
 
      "ONE\n" + // stopword, in uppercase
64
 
      "   two   \n" + // stopword with leading/trailing space
65
 
      " three   four five \n" + // multiple stopwords
66
 
      "six seven | comment\n"; //multiple stopwords + comment
67
 
    CharArraySet wordset = WordlistLoader.getSnowballWordSet(new StringReader(s), TEST_VERSION_CURRENT);
68
 
    assertEquals(7, wordset.size());
69
 
    assertTrue(wordset.contains("ONE"));
70
 
    assertTrue(wordset.contains("two"));
71
 
    assertTrue(wordset.contains("three"));
72
 
    assertTrue(wordset.contains("four"));
73
 
    assertTrue(wordset.contains("five"));
74
 
    assertTrue(wordset.contains("six"));
75
 
    assertTrue(wordset.contains("seven"));
76
 
  }
77
 
}