pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / analyzers / common / src / test / org / apache / lucene / analysis / bg / TestBulgarianAnalyzer.java
1 package org.apache.lucene.analysis.bg;
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.util.Collections;
22
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.util.Version;
27
28 /**
29  * Test the Bulgarian analyzer
30  */
31 public class TestBulgarianAnalyzer extends BaseTokenStreamTestCase {
32   
33   /**
34    * This test fails with NPE when the stopwords file is missing in classpath
35    */
36   public void testResourcesAvailable() {
37     new BulgarianAnalyzer(TEST_VERSION_CURRENT);
38   }
39   
40   public void testStopwords() throws IOException {
41     Analyzer a = new BulgarianAnalyzer(TEST_VERSION_CURRENT);
42     assertAnalyzesTo(a, "Как се казваш?", new String[] {"казваш"});
43   }
44   
45   public void testCustomStopwords() throws IOException {
46     Analyzer a = new BulgarianAnalyzer(TEST_VERSION_CURRENT, Collections
47         .emptySet());
48     assertAnalyzesTo(a, "Как се казваш?", 
49         new String[] {"как", "се", "казваш"});
50   }
51   
52   public void testReusableTokenStream() throws IOException {
53     Analyzer a = new BulgarianAnalyzer(TEST_VERSION_CURRENT);
54     assertAnalyzesToReuse(a, "документи", new String[] {"документ"});
55     assertAnalyzesToReuse(a, "документ", new String[] {"документ"});
56   }
57   
58   /**
59    * Test some examples from the paper
60    */
61   public void testBasicExamples() throws IOException {
62     Analyzer a = new BulgarianAnalyzer(TEST_VERSION_CURRENT);
63     assertAnalyzesTo(a, "енергийни кризи", new String[] {"енергийн", "криз"});
64     assertAnalyzesTo(a, "Атомната енергия", new String[] {"атомн", "енерг"});
65     
66     assertAnalyzesTo(a, "компютри", new String[] {"компютр"});
67     assertAnalyzesTo(a, "компютър", new String[] {"компютр"});
68     
69     assertAnalyzesTo(a, "градове", new String[] {"град"});
70   }
71   
72   public void testWithStemExclusionSet() throws IOException {
73     CharArraySet set = new CharArraySet(Version.LUCENE_31, 1, true);
74     set.add("строеве");
75     Analyzer a = new BulgarianAnalyzer(TEST_VERSION_CURRENT, CharArraySet.EMPTY_SET, set);
76     assertAnalyzesTo(a, "строевете строеве", new String[] { "строй", "строеве" });
77   }
78   
79   /** blast some random strings through the analyzer */
80   public void testRandomStrings() throws Exception {
81     checkRandomData(random, new BulgarianAnalyzer(TEST_VERSION_CURRENT), 10000*RANDOM_MULTIPLIER);
82   }
83 }