Save This Page
Home » lucene-2.4.1-src » org.apache » lucene » analysis » snowball » [javadoc | source]
    1   package org.apache.lucene.analysis.snowball;
    2   
    3   /**
    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
   10    *
   11    *     http://www.apache.org/licenses/LICENSE-2.0
   12    *
   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.
   18    */
   19   
   20   import org.apache.lucene.analysis;
   21   import org.apache.lucene.analysis.standard;
   22   
   23   import java.io.Reader;
   24   import java.util.Set;
   25   
   26   /** Filters {@link StandardTokenizer} with {@link StandardFilter}, {@link
   27    * LowerCaseFilter}, {@link StopFilter} and {@link SnowballFilter}.
   28    *
   29    * Available stemmers are listed in {@link net.sf.snowball.ext}.  The name of a
   30    * stemmer is the part of the class name before "Stemmer", e.g., the stemmer in
   31    * {@link org.tartarus.snowball.ext.EnglishStemmer} is named "English".
   32    */
   33   public class SnowballAnalyzer extends Analyzer {
   34     private String name;
   35     private Set stopSet;
   36   
   37     /** Builds the named analyzer with no stop words. */
   38     public SnowballAnalyzer(String name) {
   39       this.name = name;
   40     }
   41   
   42     /** Builds the named analyzer with the given stop words. */
   43     public SnowballAnalyzer(String name, String[] stopWords) {
   44       this(name);
   45       stopSet = StopFilter.makeStopSet(stopWords);
   46     }
   47   
   48     /** Constructs a {@link StandardTokenizer} filtered by a {@link
   49         StandardFilter}, a {@link LowerCaseFilter} and a {@link StopFilter}. */
   50     public TokenStream tokenStream(String fieldName, Reader reader) {
   51       TokenStream result = new StandardTokenizer(reader);
   52       result = new StandardFilter(result);
   53       result = new LowerCaseFilter(result);
   54       if (stopSet != null)
   55         result = new StopFilter(result, stopSet);
   56       result = new SnowballFilter(result, name);
   57       return result;
   58     }
   59   }

Save This Page
Home » lucene-2.4.1-src » org.apache » lucene » analysis » snowball » [javadoc | source]