1 package org.apache.lucene.analysis.de;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.io.InputStream;
21 import java.io.Reader;
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;
30 import static org.apache.lucene.analysis.VocabularyAssert.*;
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.
38 public class TestGermanStemFilter extends BaseTokenStreamTestCase {
39 Analyzer analyzer = new ReusableAnalyzerBase() {
41 protected TokenStreamComponents createComponents(String fieldName,
43 Tokenizer t = new KeywordTokenizer(reader);
44 return new TokenStreamComponents(t,
45 new GermanStemFilter(new LowerCaseFilter(TEST_VERSION_CURRENT, t)));
49 public void testStemming() throws Exception {
50 InputStream vocOut = getClass().getResourceAsStream("data.txt");
51 assertVocabulary(analyzer, vocOut);
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[] { "" });
61 /** blast some random strings through the analyzer */
62 public void testRandomStrings() throws Exception {
63 checkRandomData(random, analyzer, 10000*RANDOM_MULTIPLIER);