add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / analyzers / common / src / test / org / apache / lucene / analysis / de / TestGermanStemFilter.java
1 package org.apache.lucene.analysis.de;
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.InputStream;
21 import java.io.Reader;
22
23 import org.apache.lucene.analysis.Analyzer;
24 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
25 import org.apache.lucene.analysis.KeywordTokenizer;
26 import org.apache.lucene.analysis.LowerCaseFilter;
27 import org.apache.lucene.analysis.Tokenizer;
28 import org.apache.lucene.analysis.ReusableAnalyzerBase;
29
30 import static org.apache.lucene.analysis.VocabularyAssert.*;
31
32 /**
33  * Test the German stemmer. The stemming algorithm is known to work less 
34  * than perfect, as it doesn't use any word lists with exceptions. We 
35  * also check some of the cases where the algorithm is wrong.
36  *
37  */
38 public class TestGermanStemFilter extends BaseTokenStreamTestCase {
39   Analyzer analyzer = new ReusableAnalyzerBase() {
40     @Override
41     protected TokenStreamComponents createComponents(String fieldName,
42         Reader reader) {
43       Tokenizer t = new KeywordTokenizer(reader);
44       return new TokenStreamComponents(t,
45           new GermanStemFilter(new LowerCaseFilter(TEST_VERSION_CURRENT, t)));
46     }
47   };
48
49   public void testStemming() throws Exception {  
50     InputStream vocOut = getClass().getResourceAsStream("data.txt");
51     assertVocabulary(analyzer, vocOut);
52     vocOut.close();
53   }
54   
55   // LUCENE-3043: we use keywordtokenizer in this test,
56   // so ensure the stemmer does not crash on zero-length strings.
57   public void testEmpty() throws Exception {
58     assertAnalyzesTo(analyzer, "", new String[] { "" });
59   }
60   
61   /** blast some random strings through the analyzer */
62   public void testRandomStrings() throws Exception {
63     checkRandomData(random, analyzer, 10000*RANDOM_MULTIPLIER);
64   }
65 }