~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to lucene/contrib/analyzers/common/src/java/org/apache/lucene/analysis/cz/CzechStemFilter.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.lucene.analysis.cz;
2
 
 
3
 
import java.io.IOException;
4
 
 
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;
10
 
 
11
 
/**
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
18
 
 *
19
 
 *     http://www.apache.org/licenses/LICENSE-2.0
20
 
 *
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.
26
 
 */
27
 
 
28
 
/**
29
 
 * A {@link TokenFilter} that applies {@link CzechStemmer} to stem Czech words.
30
 
 * <p>
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}.
34
 
 * </p>
35
 
 * <p><b>NOTE</b>: Input is expected to be in lowercase, 
36
 
 * but with diacritical marks</p>
37
 
 * @see KeywordMarkerFilter
38
 
 */
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);
43
 
  
44
 
  public CzechStemFilter(TokenStream input) {
45
 
    super(input);
46
 
  }
47
 
 
48
 
  @Override
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);
54
 
      }
55
 
      return true;
56
 
    } else {
57
 
      return false;
58
 
    }
59
 
  }
60
 
}