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 * A LetterTokenizer is a tokenizer that divides text at non-letters. That's to
27 * say, it defines tokens as maximal strings of adjacent letters, as defined by
28 * java.lang.Character.isLetter() predicate.
30 * Note: this does a decent job for most European languages, but does a terrible
31 * job for some Asian languages, where words are not separated by spaces.
35 * You must specify the required {@link Version} compatibility when creating
36 * {@link LetterTokenizer}:
38 * <li>As of 3.1, {@link CharTokenizer} uses an int based API to normalize and
39 * detect token characters. See {@link CharTokenizer#isTokenChar(int)} and
40 * {@link CharTokenizer#normalize(int)} for details.</li>
45 public class LetterTokenizer extends CharTokenizer {
48 * Construct a new LetterTokenizer.
51 * Lucene version to match See {@link <a href="#version">above</a>}
53 * the input to split up into tokens
55 public LetterTokenizer(Version matchVersion, Reader in) {
56 super(matchVersion, in);
60 * Construct a new LetterTokenizer using a given {@link AttributeSource}.
63 * Lucene version to match See {@link <a href="#version">above</a>}
65 * the attribute source to use for this {@link Tokenizer}
67 * the input to split up into tokens
69 public LetterTokenizer(Version matchVersion, AttributeSource source, Reader in) {
70 super(matchVersion, source, in);
74 * Construct a new LetterTokenizer using a given
75 * {@link org.apache.lucene.util.AttributeSource.AttributeFactory}.
78 * Lucene version to match See {@link <a href="#version">above</a>}
80 * the attribute factory to use for this {@link Tokenizer}
82 * the input to split up into tokens
84 public LetterTokenizer(Version matchVersion, AttributeFactory factory, Reader in) {
85 super(matchVersion, factory, in);
89 * Construct a new LetterTokenizer.
91 * @deprecated use {@link #LetterTokenizer(Version, Reader)} instead. This
92 * will be removed in Lucene 4.0.
95 public LetterTokenizer(Reader in) {
96 super(Version.LUCENE_30, in);
100 * Construct a new LetterTokenizer using a given {@link AttributeSource}.
102 * use {@link #LetterTokenizer(Version, AttributeSource, Reader)} instead.
103 * This will be removed in Lucene 4.0.
106 public LetterTokenizer(AttributeSource source, Reader in) {
107 super(Version.LUCENE_30, source, in);
111 * Construct a new LetterTokenizer using a given
112 * {@link org.apache.lucene.util.AttributeSource.AttributeFactory}.
114 * @deprecated use {@link #LetterTokenizer(Version, AttributeSource.AttributeFactory, Reader)}
115 * instead. This will be removed in Lucene 4.0.
118 public LetterTokenizer(AttributeFactory factory, Reader in) {
119 super(Version.LUCENE_30, factory, in);
122 /** Collects only characters which satisfy
123 * {@link Character#isLetter(int)}.*/
125 protected boolean isTokenChar(int c) {
126 return Character.isLetter(c);