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 org.apache.lucene.analysis.KeywordMarkerFilter;// for javadoc
21 import org.apache.lucene.analysis.TokenFilter;
22 import org.apache.lucene.analysis.TokenStream;
23 import org.apache.lucene.analysis.snowball.SnowballFilter;
24 import org.apache.lucene.analysis.tokenattributes.KeywordAttribute;
25 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
27 import java.io.IOException;
32 * A {@link TokenFilter} that stems french words.
34 * The used stemmer can be changed at runtime after the
35 * filter object is created (as long as it is a {@link FrenchStemmer}).
38 * To prevent terms from being stemmed use an instance of
39 * {@link KeywordMarkerFilter} or a custom {@link TokenFilter} that sets
40 * the {@link KeywordAttribute} before this {@link TokenStream}.
42 * @see KeywordMarkerFilter
43 * @deprecated Use {@link SnowballFilter} with
44 * {@link org.tartarus.snowball.ext.FrenchStemmer} instead, which has the
45 * same functionality. This filter will be removed in Lucene 5.0
48 public final class FrenchStemFilter extends TokenFilter {
51 * The actual token in the input stream.
53 private FrenchStemmer stemmer = new FrenchStemmer();
54 private Set<?> exclusions = null;
56 private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
57 private final KeywordAttribute keywordAttr = addAttribute(KeywordAttribute.class);
59 public FrenchStemFilter( TokenStream in ) {
65 * @param in the {@link TokenStream} to filter
66 * @param exclusiontable a set of terms not to be stemmed
67 * @deprecated use {@link KeywordAttribute} with {@link KeywordMarkerFilter} instead.
70 public FrenchStemFilter( TokenStream in, Set<?> exclusiontable ) {
72 exclusions = exclusiontable;
76 * @return Returns true for the next token in the stream, or false at EOS
79 public boolean incrementToken() throws IOException {
80 if (input.incrementToken()) {
81 String term = termAtt.toString();
83 // Check the exclusion table
84 if ( !keywordAttr.isKeyword() && (exclusions == null || !exclusions.contains( term )) ) {
85 String s = stemmer.stem( term );
86 // If not stemmed, don't waste the time adjusting the token.
87 if ((s != null) && !s.equals( term ) )
88 termAtt.setEmpty().append(s);
96 * Set a alternative/custom {@link FrenchStemmer} for this filter.
98 public void setStemmer( FrenchStemmer stemmer ) {
99 if ( stemmer != null ) {
100 this.stemmer = stemmer;
104 * Set an alternative exclusion list for this filter.
105 * @deprecated use {@link KeywordAttribute} with {@link KeywordMarkerFilter} instead.
108 public void setExclusionTable( Map<?,?> exclusiontable ) {
109 exclusions = exclusiontable.keySet();