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.IOException;
21 import java.io.StringReader;
23 import org.apache.lucene.analysis.Analyzer;
24 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
25 import org.apache.lucene.analysis.CharArraySet;
26 import org.apache.lucene.analysis.KeywordMarkerFilter;
27 import org.apache.lucene.analysis.LowerCaseTokenizer;
28 import org.apache.lucene.util.Version;
30 public class TestGermanAnalyzer extends BaseTokenStreamTestCase {
31 public void testReusableTokenStream() throws Exception {
32 Analyzer a = new GermanAnalyzer(TEST_VERSION_CURRENT);
33 checkOneTermReuse(a, "Tisch", "tisch");
34 checkOneTermReuse(a, "Tische", "tisch");
35 checkOneTermReuse(a, "Tischen", "tisch");
38 public void testExclusionTableBWCompat() throws IOException {
39 GermanStemFilter filter = new GermanStemFilter(new LowerCaseTokenizer(TEST_VERSION_CURRENT,
40 new StringReader("Fischen Trinken")));
41 CharArraySet set = new CharArraySet(TEST_VERSION_CURRENT, 1, true);
43 filter.setExclusionSet(set);
44 assertTokenStreamContents(filter, new String[] { "fischen", "trink" });
47 public void testWithKeywordAttribute() throws IOException {
48 CharArraySet set = new CharArraySet(TEST_VERSION_CURRENT, 1, true);
50 GermanStemFilter filter = new GermanStemFilter(
51 new KeywordMarkerFilter(new LowerCaseTokenizer(TEST_VERSION_CURRENT, new StringReader(
52 "Fischen Trinken")), set));
53 assertTokenStreamContents(filter, new String[] { "fischen", "trink" });
56 public void testWithKeywordAttributeAndExclusionTable() throws IOException {
57 CharArraySet set = new CharArraySet(TEST_VERSION_CURRENT, 1, true);
59 CharArraySet set1 = new CharArraySet(TEST_VERSION_CURRENT, 1, true);
62 GermanStemFilter filter = new GermanStemFilter(
63 new KeywordMarkerFilter(new LowerCaseTokenizer(TEST_VERSION_CURRENT, new StringReader(
64 "Fischen Trinken")), set));
65 filter.setExclusionSet(set1);
66 assertTokenStreamContents(filter, new String[] { "fischen", "trinken" });
70 * Test that changes to the exclusion table are applied immediately
71 * when using reusable token streams.
73 public void testExclusionTableReuse() throws Exception {
74 GermanAnalyzer a = new GermanAnalyzer(TEST_VERSION_CURRENT);
75 checkOneTermReuse(a, "tischen", "tisch");
76 a.setStemExclusionTable(new String[] { "tischen" });
77 checkOneTermReuse(a, "tischen", "tischen");
80 /** test some features of the new snowball filter
81 * these only pass with LUCENE_CURRENT, not if you use o.a.l.a.de.GermanStemmer
83 public void testGermanSpecials() throws Exception {
84 GermanAnalyzer a = new GermanAnalyzer(TEST_VERSION_CURRENT);
85 // a/o/u + e is equivalent to the umlaut form
86 checkOneTermReuse(a, "Schaltflächen", "schaltflach");
87 checkOneTermReuse(a, "Schaltflaechen", "schaltflach");
88 // here they are with the old stemmer
89 a = new GermanAnalyzer(Version.LUCENE_30);
90 checkOneTermReuse(a, "Schaltflächen", "schaltflach");
91 checkOneTermReuse(a, "Schaltflaechen", "schaltflaech");
94 /** blast some random strings through the analyzer */
95 public void testRandomStrings() throws Exception {
96 checkRandomData(random, new GermanAnalyzer(TEST_VERSION_CURRENT), 10000*RANDOM_MULTIPLIER);