1 package org.apache.lucene.analysis.snowball;
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.Reader;
23 import org.apache.lucene.analysis.KeywordTokenizer;
24 import org.apache.lucene.analysis.Analyzer;
25 import org.apache.lucene.analysis.Tokenizer;
26 import org.apache.lucene.analysis.ReusableAnalyzerBase;
27 import org.apache.lucene.util.LuceneTestCase;
29 import static org.apache.lucene.analysis.VocabularyAssert.*;
32 * Test the snowball filters against the snowball data tests
34 public class TestSnowballVocab extends LuceneTestCase {
36 * Run all languages against their snowball vocabulary tests.
38 public void testStemmers() throws IOException {
39 assertCorrectOutput("Danish", "danish");
40 assertCorrectOutput("Dutch", "dutch");
41 assertCorrectOutput("English", "english");
42 // disabled due to snowball java code generation bug:
43 // see http://article.gmane.org/gmane.comp.search.snowball/1139
44 // assertCorrectOutput("Finnish", "finnish");
45 assertCorrectOutput("French", "french");
46 assertCorrectOutput("German", "german");
47 assertCorrectOutput("German2", "german2");
48 assertCorrectOutput("Hungarian", "hungarian");
49 assertCorrectOutput("Italian", "italian");
50 assertCorrectOutput("Kp", "kraaij_pohlmann");
51 // disabled due to snowball java code generation bug:
52 // see http://article.gmane.org/gmane.comp.search.snowball/1139
53 // assertCorrectOutput("Lovins", "lovins");
54 assertCorrectOutput("Norwegian", "norwegian");
55 assertCorrectOutput("Porter", "porter");
56 assertCorrectOutput("Portuguese", "portuguese");
57 assertCorrectOutput("Romanian", "romanian");
58 assertCorrectOutput("Russian", "russian");
59 assertCorrectOutput("Spanish", "spanish");
60 assertCorrectOutput("Swedish", "swedish");
61 assertCorrectOutput("Turkish", "turkish");
65 * For the supplied language, run the stemmer against all strings in voc.txt
66 * The output should be the same as the string in output.txt
68 private void assertCorrectOutput(final String snowballLanguage, String dataDirectory)
70 if (VERBOSE) System.out.println("checking snowball language: " + snowballLanguage);
72 Analyzer a = new ReusableAnalyzerBase() {
74 protected TokenStreamComponents createComponents(String fieldName,
76 Tokenizer t = new KeywordTokenizer(reader);
77 return new TokenStreamComponents(t, new SnowballFilter(t, snowballLanguage));
81 assertVocabulary(a, getDataFile("TestSnowballVocabData.zip"),
82 dataDirectory + "/voc.txt", dataDirectory + "/output.txt");