add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / analyzers / common / src / test / org / apache / lucene / analysis / snowball / TestSnowballVocab.java
1 package org.apache.lucene.analysis.snowball;
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.IOException;
21 import java.io.Reader;
22
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;
28
29 import static org.apache.lucene.analysis.VocabularyAssert.*;
30
31 /**
32  * Test the snowball filters against the snowball data tests
33  */
34 public class TestSnowballVocab extends LuceneTestCase {
35   /**
36    * Run all languages against their snowball vocabulary tests.
37    */
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");
62   }
63     
64   /**
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
67    */
68   private void assertCorrectOutput(final String snowballLanguage, String dataDirectory)
69       throws IOException {
70     if (VERBOSE) System.out.println("checking snowball language: " + snowballLanguage);
71     
72     Analyzer a = new ReusableAnalyzerBase() {
73       @Override
74       protected TokenStreamComponents createComponents(String fieldName,
75           Reader reader) {
76         Tokenizer t = new KeywordTokenizer(reader);
77         return new TokenStreamComponents(t, new SnowballFilter(t, snowballLanguage));
78       }  
79     };
80     
81     assertVocabulary(a, getDataFile("TestSnowballVocabData.zip"), 
82         dataDirectory + "/voc.txt", dataDirectory + "/output.txt");
83   }
84 }