1 package org.apache.lucene.analysis.cz;
3 import java.io.IOException;
5 import org.apache.lucene.analysis.KeywordMarkerFilter;// for javadoc
6 import org.apache.lucene.analysis.TokenFilter;
7 import org.apache.lucene.analysis.TokenStream;
8 import org.apache.lucene.analysis.tokenattributes.KeywordAttribute;
9 import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed with
14 * this work for additional information regarding copyright ownership.
15 * The ASF licenses this file to You under the Apache License, Version 2.0
16 * (the "License"); you may not use this file except in compliance with
17 * the License. You may obtain a copy of the License at
19 * http://www.apache.org/licenses/LICENSE-2.0
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 * See the License for the specific language governing permissions and
25 * limitations under the License.
29 * A {@link TokenFilter} that applies {@link CzechStemmer} to stem Czech words.
31 * To prevent terms from being stemmed use an instance of
32 * {@link KeywordMarkerFilter} or a custom {@link TokenFilter} that sets
33 * the {@link KeywordAttribute} before this {@link TokenStream}.
35 * <p><b>NOTE</b>: Input is expected to be in lowercase,
36 * but with diacritical marks</p>
37 * @see KeywordMarkerFilter
39 public final class CzechStemFilter extends TokenFilter {
40 private final CzechStemmer stemmer = new CzechStemmer();
41 private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
42 private final KeywordAttribute keywordAttr = addAttribute(KeywordAttribute.class);
44 public CzechStemFilter(TokenStream input) {
49 public boolean incrementToken() throws IOException {
50 if (input.incrementToken()) {
51 if(!keywordAttr.isKeyword()) {
52 final int newlen = stemmer.stem(termAtt.buffer(), termAtt.length());
53 termAtt.setLength(newlen);