pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / analyzers / common / src / test / org / apache / lucene / analysis / el / GreekAnalyzerTest.java
1 package org.apache.lucene.analysis.el;
2
3 /**
4  * Copyright 2005 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
20 import org.apache.lucene.analysis.Analyzer;
21 import org.apache.lucene.util.Version;
22
23 /**
24  * A unit test class for verifying the correct operation of the GreekAnalyzer.
25  *
26  */
27 public class GreekAnalyzerTest extends BaseTokenStreamTestCase {
28
29   /**
30    * Test the analysis of various greek strings.
31    *
32    * @throws Exception in case an error occurs
33    */
34   public void testAnalyzer() throws Exception {
35     Analyzer a = new GreekAnalyzer(TEST_VERSION_CURRENT);
36     // Verify the correct analysis of capitals and small accented letters, and
37     // stemming
38     assertAnalyzesTo(a, "Μία εξαιρετικά καλή και πλούσια σειρά χαρακτήρων της Ελληνικής γλώσσας",
39         new String[] { "μια", "εξαιρετ", "καλ", "πλουσ", "σειρ", "χαρακτηρ",
40         "ελληνικ", "γλωσσ" });
41     // Verify the correct analysis of small letters with diaeresis and the elimination
42     // of punctuation marks
43     assertAnalyzesTo(a, "Προϊόντα (και)     [πολλαπλές] - ΑΝΑΓΚΕΣ",
44         new String[] { "προιοντ", "πολλαπλ", "αναγκ" });
45     // Verify the correct analysis of capital accented letters and capital letters with diaeresis,
46     // as well as the elimination of stop words
47     assertAnalyzesTo(a, "ΠΡΟΫΠΟΘΕΣΕΙΣ  Άψογος, ο μεστός και οι άλλοι",
48         new String[] { "προυποθεσ", "αψογ", "μεστ", "αλλ" });
49   }
50   
51         /**
52          * Test the analysis of various greek strings.
53          *
54          * @throws Exception in case an error occurs
55          * @deprecated Remove this test when support for 3.0 is no longer needed
56          */
57   @Deprecated
58         public void testAnalyzerBWCompat() throws Exception {
59                 Analyzer a = new GreekAnalyzer(Version.LUCENE_30);
60                 // Verify the correct analysis of capitals and small accented letters
61                 assertAnalyzesTo(a, "Μία εξαιρετικά καλή και πλούσια σειρά χαρακτήρων της Ελληνικής γλώσσας",
62                                 new String[] { "μια", "εξαιρετικα", "καλη", "πλουσια", "σειρα", "χαρακτηρων",
63                                 "ελληνικησ", "γλωσσασ" });
64                 // Verify the correct analysis of small letters with diaeresis and the elimination
65                 // of punctuation marks
66                 assertAnalyzesTo(a, "Προϊόντα (και)     [πολλαπλές] - ΑΝΑΓΚΕΣ",
67                                 new String[] { "προιοντα", "πολλαπλεσ", "αναγκεσ" });
68                 // Verify the correct analysis of capital accented letters and capital letters with diaeresis,
69                 // as well as the elimination of stop words
70                 assertAnalyzesTo(a, "ΠΡΟΫΠΟΘΕΣΕΙΣ  Άψογος, ο μεστός και οι άλλοι",
71                                 new String[] { "προυποθεσεισ", "αψογοσ", "μεστοσ", "αλλοι" });
72         }
73         
74   public void testReusableTokenStream() throws Exception {
75     Analyzer a = new GreekAnalyzer(TEST_VERSION_CURRENT);
76     // Verify the correct analysis of capitals and small accented letters, and
77     // stemming
78     assertAnalyzesToReuse(a, "Μία εξαιρετικά καλή και πλούσια σειρά χαρακτήρων της Ελληνικής γλώσσας",
79         new String[] { "μια", "εξαιρετ", "καλ", "πλουσ", "σειρ", "χαρακτηρ",
80         "ελληνικ", "γλωσσ" });
81     // Verify the correct analysis of small letters with diaeresis and the elimination
82     // of punctuation marks
83     assertAnalyzesToReuse(a, "Προϊόντα (και)     [πολλαπλές] - ΑΝΑΓΚΕΣ",
84         new String[] { "προιοντ", "πολλαπλ", "αναγκ" });
85     // Verify the correct analysis of capital accented letters and capital letters with diaeresis,
86     // as well as the elimination of stop words
87     assertAnalyzesToReuse(a, "ΠΡΟΫΠΟΘΕΣΕΙΣ  Άψογος, ο μεστός και οι άλλοι",
88         new String[] { "προυποθεσ", "αψογ", "μεστ", "αλλ" });
89   }
90         
91         /**
92          * Greek Analyzer didn't call standardFilter, so no normalization of acronyms.
93          * check that this is preserved.
94          * @deprecated remove this test in Lucene 4.0
95          */
96         @Deprecated
97         public void testAcronymBWCompat() throws Exception {
98           Analyzer a = new GreekAnalyzer(Version.LUCENE_30);
99           assertAnalyzesTo(a, "Α.Π.Τ.", new String[] { "α.π.τ." });
100         }
101   
102   /** blast some random strings through the analyzer */
103   public void testRandomStrings() throws Exception {
104     checkRandomData(random, new GreekAnalyzer(TEST_VERSION_CURRENT), 10000*RANDOM_MULTIPLIER);
105   }
106 }