add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / analyzers / common / src / test / org / apache / lucene / analysis / en / TestKStemmer.java
1 package org.apache.lucene.analysis.en;
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 static org.apache.lucene.analysis.VocabularyAssert.assertVocabulary;
21
22 import java.io.Reader;
23
24 import org.apache.lucene.analysis.Analyzer;
25 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
26 import org.apache.lucene.analysis.MockTokenizer;
27 import org.apache.lucene.analysis.Tokenizer;
28 import org.apache.lucene.analysis.ReusableAnalyzerBase;
29
30 /**
31  * Tests for {@link KStemmer}
32  */
33 public class TestKStemmer extends BaseTokenStreamTestCase {
34   Analyzer a = new ReusableAnalyzerBase() {
35     @Override
36     protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
37       Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, true);
38       return new TokenStreamComponents(tokenizer, new KStemFilter(tokenizer));
39     }
40   };
41  
42   /** blast some random strings through the analyzer */
43   public void testRandomStrings() throws Exception {
44     checkRandomData(random, a, 10000*RANDOM_MULTIPLIER);
45   }
46   
47   /** 
48    * test the kstemmer optimizations against a bunch of words
49    * that were stemmed with the original java kstemmer (generated from
50    * testCreateMap, commented out below).
51    */
52   public void testVocabulary() throws Exception {
53     assertVocabulary(a, getDataFile("kstemTestData.zip"), "kstem_examples.txt");
54   }
55
56   /****** requires original java kstem source code to create map
57   public void testCreateMap() throws Exception {
58     String input = getBigDoc();
59     Reader r = new StringReader(input);
60     TokenFilter tf = new LowerCaseFilter(new LetterTokenizer(r));
61     // tf = new KStemFilter(tf);
62
63     KStemmer kstem = new KStemmer();
64     Map<String,String> map = new TreeMap<String,String>();
65     for(;;) {
66       Token t = tf.next();
67       if (t==null) break;
68       String s = t.termText();
69       if (map.containsKey(s)) continue;
70       map.put(s, kstem.stem(s));
71     }
72
73     Writer out = new BufferedWriter(new FileWriter("kstem_examples.txt"));
74     for (String key : map.keySet()) {
75       out.write(key);
76       out.write('\t');
77       out.write(map.get(key));
78       out.write('\n');
79     }
80     out.close();
81   }
82   ******/
83
84 }