add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / analyzers / common / src / java / org / apache / lucene / analysis / th / ThaiAnalyzer.java
1 package org.apache.lucene.analysis.th;
2
3 /**
4  * Copyright 2006 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 import java.io.Reader;
20
21 import org.apache.lucene.analysis.ReusableAnalyzerBase;
22 import org.apache.lucene.analysis.Analyzer;
23 import org.apache.lucene.analysis.StopAnalyzer;
24 import org.apache.lucene.analysis.StopFilter;
25 import org.apache.lucene.analysis.LowerCaseFilter;
26 import org.apache.lucene.analysis.TokenStream;
27 import org.apache.lucene.analysis.Tokenizer;
28 import org.apache.lucene.analysis.standard.StandardAnalyzer;
29 import org.apache.lucene.analysis.standard.StandardFilter;
30 import org.apache.lucene.analysis.standard.StandardTokenizer;
31 import org.apache.lucene.util.Version;
32
33 /**
34  * {@link Analyzer} for Thai language. It uses {@link java.text.BreakIterator} to break words.
35  * @version 0.2
36  *
37  * <p><b>NOTE</b>: This class uses the same {@link Version}
38  * dependent settings as {@link StandardAnalyzer}.</p>
39  */
40 public final class ThaiAnalyzer extends ReusableAnalyzerBase {
41   private final Version matchVersion;
42
43   public ThaiAnalyzer(Version matchVersion) {
44     this.matchVersion = matchVersion;
45   }
46
47   /**
48    * Creates
49    * {@link org.apache.lucene.analysis.ReusableAnalyzerBase.TokenStreamComponents}
50    * used to tokenize all the text in the provided {@link Reader}.
51    * 
52    * @return {@link org.apache.lucene.analysis.ReusableAnalyzerBase.TokenStreamComponents}
53    *         built from a {@link StandardTokenizer} filtered with
54    *         {@link StandardFilter}, {@link LowerCaseFilter}, {@link ThaiWordFilter}, and
55    *         {@link StopFilter}
56    */
57   @Override
58   protected TokenStreamComponents createComponents(String fieldName,
59       Reader reader) {
60     final Tokenizer source = new StandardTokenizer(matchVersion, reader);
61     TokenStream result = new StandardFilter(matchVersion, source);
62     if (matchVersion.onOrAfter(Version.LUCENE_31))
63       result = new LowerCaseFilter(matchVersion, result);
64     result = new ThaiWordFilter(matchVersion, result);
65     return new TokenStreamComponents(source, new StopFilter(matchVersion,
66         result, StopAnalyzer.ENGLISH_STOP_WORDS_SET));
67   }
68 }