1 package org.apache.lucene.analysis.fr;
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.io.Reader;
23 import org.apache.lucene.analysis.Analyzer;
24 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
25 import org.apache.lucene.analysis.MockTokenizer;
26 import org.apache.lucene.analysis.Tokenizer;
27 import org.apache.lucene.analysis.ReusableAnalyzerBase;
29 import static org.apache.lucene.analysis.VocabularyAssert.*;
32 * Simple tests for {@link FrenchLightStemFilter}
34 public class TestFrenchLightStemFilter extends BaseTokenStreamTestCase {
35 private Analyzer analyzer = new ReusableAnalyzerBase() {
37 protected TokenStreamComponents createComponents(String fieldName,
39 Tokenizer source = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
40 return new TokenStreamComponents(source, new FrenchLightStemFilter(source));
44 /** Test some examples from the paper */
45 public void testExamples() throws IOException {
46 checkOneTerm(analyzer, "chevaux", "cheval");
47 checkOneTerm(analyzer, "cheval", "cheval");
49 checkOneTerm(analyzer, "hiboux", "hibou");
50 checkOneTerm(analyzer, "hibou", "hibou");
52 checkOneTerm(analyzer, "chantés", "chant");
53 checkOneTerm(analyzer, "chanter", "chant");
54 checkOneTerm(analyzer, "chante", "chant");
55 checkOneTerm(analyzer, "chant", "chant");
57 checkOneTerm(analyzer, "baronnes", "baron");
58 checkOneTerm(analyzer, "barons", "baron");
59 checkOneTerm(analyzer, "baron", "baron");
61 checkOneTerm(analyzer, "peaux", "peau");
62 checkOneTerm(analyzer, "peau", "peau");
64 checkOneTerm(analyzer, "anneaux", "aneau");
65 checkOneTerm(analyzer, "anneau", "aneau");
67 checkOneTerm(analyzer, "neveux", "neveu");
68 checkOneTerm(analyzer, "neveu", "neveu");
70 checkOneTerm(analyzer, "affreux", "afreu");
71 checkOneTerm(analyzer, "affreuse", "afreu");
73 checkOneTerm(analyzer, "investissement", "investi");
74 checkOneTerm(analyzer, "investir", "investi");
76 checkOneTerm(analyzer, "assourdissant", "asourdi");
77 checkOneTerm(analyzer, "assourdir", "asourdi");
79 checkOneTerm(analyzer, "pratiquement", "pratiqu");
80 checkOneTerm(analyzer, "pratique", "pratiqu");
82 checkOneTerm(analyzer, "administrativement", "administratif");
83 checkOneTerm(analyzer, "administratif", "administratif");
85 checkOneTerm(analyzer, "justificatrice", "justifi");
86 checkOneTerm(analyzer, "justificateur", "justifi");
87 checkOneTerm(analyzer, "justifier", "justifi");
89 checkOneTerm(analyzer, "educatrice", "eduqu");
90 checkOneTerm(analyzer, "eduquer", "eduqu");
92 checkOneTerm(analyzer, "communicateur", "comuniqu");
93 checkOneTerm(analyzer, "communiquer", "comuniqu");
95 checkOneTerm(analyzer, "accompagnatrice", "acompagn");
96 checkOneTerm(analyzer, "accompagnateur", "acompagn");
98 checkOneTerm(analyzer, "administrateur", "administr");
99 checkOneTerm(analyzer, "administrer", "administr");
101 checkOneTerm(analyzer, "productrice", "product");
102 checkOneTerm(analyzer, "producteur", "product");
104 checkOneTerm(analyzer, "acheteuse", "achet");
105 checkOneTerm(analyzer, "acheteur", "achet");
107 checkOneTerm(analyzer, "planteur", "plant");
108 checkOneTerm(analyzer, "plante", "plant");
110 checkOneTerm(analyzer, "poreuse", "poreu");
111 checkOneTerm(analyzer, "poreux", "poreu");
113 checkOneTerm(analyzer, "plieuse", "plieu");
115 checkOneTerm(analyzer, "bijoutière", "bijouti");
116 checkOneTerm(analyzer, "bijoutier", "bijouti");
118 checkOneTerm(analyzer, "caissière", "caisi");
119 checkOneTerm(analyzer, "caissier", "caisi");
121 checkOneTerm(analyzer, "abrasive", "abrasif");
122 checkOneTerm(analyzer, "abrasif", "abrasif");
124 checkOneTerm(analyzer, "folle", "fou");
125 checkOneTerm(analyzer, "fou", "fou");
127 checkOneTerm(analyzer, "personnelle", "person");
128 checkOneTerm(analyzer, "personne", "person");
130 // algo bug: too short length
131 //checkOneTerm(analyzer, "personnel", "person");
133 checkOneTerm(analyzer, "complète", "complet");
134 checkOneTerm(analyzer, "complet", "complet");
136 checkOneTerm(analyzer, "aromatique", "aromat");
138 checkOneTerm(analyzer, "faiblesse", "faibl");
139 checkOneTerm(analyzer, "faible", "faibl");
141 checkOneTerm(analyzer, "patinage", "patin");
142 checkOneTerm(analyzer, "patin", "patin");
144 checkOneTerm(analyzer, "sonorisation", "sono");
146 checkOneTerm(analyzer, "ritualisation", "rituel");
147 checkOneTerm(analyzer, "rituel", "rituel");
149 // algo bug: masked by rules above
150 //checkOneTerm(analyzer, "colonisateur", "colon");
152 checkOneTerm(analyzer, "nomination", "nomin");
154 checkOneTerm(analyzer, "disposition", "dispos");
155 checkOneTerm(analyzer, "dispose", "dispos");
158 /** Test against a vocabulary from the reference impl */
159 public void testVocabulary() throws IOException {
160 assertVocabulary(analyzer, getDataFile("frlighttestdata.zip"), "frlight.txt");
163 /** blast some random strings through the analyzer */
164 public void testRandomStrings() throws Exception {
165 checkRandomData(random, analyzer, 10000*RANDOM_MULTIPLIER);