1
package org.apache.lucene.analysis.el;
4
* Copyright 2005 The Apache Software Foundation
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
10
* http://www.apache.org/licenses/LICENSE-2.0
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.
19
import org.apache.lucene.analysis.Analyzer;
20
import org.apache.lucene.analysis.StopFilter;
21
import org.apache.lucene.analysis.StopwordAnalyzerBase;
22
import org.apache.lucene.analysis.TokenStream;
23
import org.apache.lucene.analysis.Tokenizer;
24
import org.apache.lucene.analysis.standard.StandardFilter;
25
import org.apache.lucene.analysis.standard.StandardTokenizer;
26
import org.apache.lucene.analysis.standard.StandardAnalyzer; // for javadoc
27
import org.apache.lucene.util.Version;
29
import java.io.IOException;
30
import java.io.Reader;
35
* {@link Analyzer} for the Greek language.
37
* Supports an external list of stopwords (words
38
* that will not be indexed at all).
39
* A default set of stopwords is used unless an alternative list is specified.
43
* <p>You must specify the required {@link Version}
44
* compatibility when creating GreekAnalyzer:
46
* <li> As of 3.1, StandardFilter and GreekStemmer are used by default.
47
* <li> As of 2.9, StopFilter preserves position
51
* <p><b>NOTE</b>: This class uses the same {@link Version}
52
* dependent settings as {@link StandardAnalyzer}.</p>
54
public final class GreekAnalyzer extends StopwordAnalyzerBase {
55
/** File containing default Greek stopwords. */
56
public final static String DEFAULT_STOPWORD_FILE = "stopwords.txt";
59
* Returns a set of default Greek-stopwords
60
* @return a set of default Greek-stopwords
62
public static final Set<?> getDefaultStopSet(){
63
return DefaultSetHolder.DEFAULT_SET;
66
private static class DefaultSetHolder {
67
private static final Set<?> DEFAULT_SET;
71
DEFAULT_SET = loadStopwordSet(false, GreekAnalyzer.class, DEFAULT_STOPWORD_FILE, "#");
72
} catch (IOException ex) {
73
// default set should always be present as it is part of the
75
throw new RuntimeException("Unable to load default stopword set");
81
* Builds an analyzer with the default stop words.
82
* @param matchVersion Lucene compatibility version,
83
* See <a href="#version">above</a>
85
public GreekAnalyzer(Version matchVersion) {
86
this(matchVersion, DefaultSetHolder.DEFAULT_SET);
90
* Builds an analyzer with the given stop words.
92
* <b>NOTE:</b> The stopwords set should be pre-processed with the logic of
93
* {@link GreekLowerCaseFilter} for best results.
95
* @param matchVersion Lucene compatibility version,
96
* See <a href="#version">above</a>
97
* @param stopwords a stopword set
99
public GreekAnalyzer(Version matchVersion, Set<?> stopwords) {
100
super(matchVersion, stopwords);
104
* Builds an analyzer with the given stop words.
105
* @param stopwords Array of stopwords to use.
106
* @deprecated use {@link #GreekAnalyzer(Version, Set)} instead
109
public GreekAnalyzer(Version matchVersion, String... stopwords) {
110
this(matchVersion, StopFilter.makeStopSet(matchVersion, stopwords));
114
* Builds an analyzer with the given stop words.
115
* @deprecated use {@link #GreekAnalyzer(Version, Set)} instead
118
public GreekAnalyzer(Version matchVersion, Map<?,?> stopwords) {
119
this(matchVersion, stopwords.keySet());
124
* {@link org.apache.lucene.analysis.ReusableAnalyzerBase.TokenStreamComponents}
125
* used to tokenize all the text in the provided {@link Reader}.
127
* @return {@link org.apache.lucene.analysis.ReusableAnalyzerBase.TokenStreamComponents}
128
* built from a {@link StandardTokenizer} filtered with
129
* {@link GreekLowerCaseFilter}, {@link StandardFilter},
130
* {@link StopFilter}, and {@link GreekStemFilter}
133
protected TokenStreamComponents createComponents(String fieldName,
135
final Tokenizer source = new StandardTokenizer(matchVersion, reader);
136
TokenStream result = new GreekLowerCaseFilter(matchVersion, source);
137
if (matchVersion.onOrAfter(Version.LUCENE_31))
138
result = new StandardFilter(matchVersion, result);
139
result = new StopFilter(matchVersion, result, stopwords);
140
if (matchVersion.onOrAfter(Version.LUCENE_31))
141
result = new GreekStemFilter(result);
142
return new TokenStreamComponents(source, result);