1 package org.apache.lucene.analysis.bg;
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.util.Collections;
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;
29 * Test the Bulgarian analyzer
31 public class TestBulgarianAnalyzer extends BaseTokenStreamTestCase {
34 * This test fails with NPE when the stopwords file is missing in classpath
36 public void testResourcesAvailable() {
37 new BulgarianAnalyzer(TEST_VERSION_CURRENT);
40 public void testStopwords() throws IOException {
41 Analyzer a = new BulgarianAnalyzer(TEST_VERSION_CURRENT);
42 assertAnalyzesTo(a, "Как се казваш?", new String[] {"казваш"});
45 public void testCustomStopwords() throws IOException {
46 Analyzer a = new BulgarianAnalyzer(TEST_VERSION_CURRENT, Collections
48 assertAnalyzesTo(a, "Как се казваш?",
49 new String[] {"как", "се", "казваш"});
52 public void testReusableTokenStream() throws IOException {
53 Analyzer a = new BulgarianAnalyzer(TEST_VERSION_CURRENT);
54 assertAnalyzesToReuse(a, "документи", new String[] {"документ"});
55 assertAnalyzesToReuse(a, "документ", new String[] {"документ"});
59 * Test some examples from the paper
61 public void testBasicExamples() throws IOException {
62 Analyzer a = new BulgarianAnalyzer(TEST_VERSION_CURRENT);
63 assertAnalyzesTo(a, "енергийни кризи", new String[] {"енергийн", "криз"});
64 assertAnalyzesTo(a, "Атомната енергия", new String[] {"атомн", "енерг"});
66 assertAnalyzesTo(a, "компютри", new String[] {"компютр"});
67 assertAnalyzesTo(a, "компютър", new String[] {"компютр"});
69 assertAnalyzesTo(a, "градове", new String[] {"град"});
72 public void testWithStemExclusionSet() throws IOException {
73 CharArraySet set = new CharArraySet(Version.LUCENE_31, 1, true);
75 Analyzer a = new BulgarianAnalyzer(TEST_VERSION_CURRENT, CharArraySet.EMPTY_SET, set);
76 assertAnalyzesTo(a, "строевете строеве", new String[] { "строй", "строеве" });
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);