1 package org.apache.lucene.analysis;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.io.Reader;
22 import org.apache.lucene.util.AttributeSource;
23 import org.apache.lucene.util.Version;
26 * LowerCaseTokenizer performs the function of LetterTokenizer
27 * and LowerCaseFilter together. It divides text at non-letters and converts
28 * them to lower case. While it is functionally equivalent to the combination
29 * of LetterTokenizer and LowerCaseFilter, there is a performance advantage
30 * to doing the two tasks at once, hence this (redundant) implementation.
32 * Note: this does a decent job for most European languages, but does a terrible
33 * job for some Asian languages, where words are not separated by spaces.
37 * You must specify the required {@link Version} compatibility when creating
38 * {@link LowerCaseTokenizer}:
40 * <li>As of 3.1, {@link CharTokenizer} uses an int based API to normalize and
41 * detect token characters. See {@link CharTokenizer#isTokenChar(int)} and
42 * {@link CharTokenizer#normalize(int)} for details.</li>
46 public final class LowerCaseTokenizer extends LetterTokenizer {
49 * Construct a new LowerCaseTokenizer.
52 * Lucene version to match See {@link <a href="#version">above</a>}
55 * the input to split up into tokens
57 public LowerCaseTokenizer(Version matchVersion, Reader in) {
58 super(matchVersion, in);
62 * Construct a new LowerCaseTokenizer using a given {@link AttributeSource}.
65 * Lucene version to match See {@link <a href="#version">above</a>}
67 * the attribute source to use for this {@link Tokenizer}
69 * the input to split up into tokens
71 public LowerCaseTokenizer(Version matchVersion, AttributeSource source, Reader in) {
72 super(matchVersion, source, in);
76 * Construct a new LowerCaseTokenizer using a given
77 * {@link org.apache.lucene.util.AttributeSource.AttributeFactory}.
80 * Lucene version to match See {@link <a href="#version">above</a>}
82 * the attribute factory to use for this {@link Tokenizer}
84 * the input to split up into tokens
86 public LowerCaseTokenizer(Version matchVersion, AttributeFactory factory, Reader in) {
87 super(matchVersion, factory, in);
91 * Construct a new LowerCaseTokenizer.
93 * @deprecated use {@link #LowerCaseTokenizer(Version, Reader)} instead. This will be
94 * removed in Lucene 4.0.
97 public LowerCaseTokenizer(Reader in) {
98 super(Version.LUCENE_30, in);
102 * Construct a new LowerCaseTokenizer using a given {@link AttributeSource}.
104 * @deprecated use {@link #LowerCaseTokenizer(Version, AttributeSource, Reader)}
105 * instead. This will be removed in Lucene 4.0.
108 public LowerCaseTokenizer(AttributeSource source, Reader in) {
109 super(Version.LUCENE_30, source, in);
113 * Construct a new LowerCaseTokenizer using a given
114 * {@link org.apache.lucene.util.AttributeSource.AttributeFactory}.
116 * @deprecated use {@link #LowerCaseTokenizer(Version, AttributeSource.AttributeFactory, Reader)}
117 * instead. This will be removed in Lucene 4.0.
120 public LowerCaseTokenizer(AttributeFactory factory, Reader in) {
121 super(Version.LUCENE_30, factory, in);
124 /** Converts char to lower case
125 * {@link Character#toLowerCase(int)}.*/
127 protected int normalize(int c) {
128 return Character.toLowerCase(c);