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 WhitespaceTokenizer is a tokenizer that divides text at whitespace.
27 * Adjacent sequences of non-Whitespace characters form tokens. <a
30 * You must specify the required {@link Version} compatibility when creating
31 * {@link WhitespaceTokenizer}:
33 * <li>As of 3.1, {@link CharTokenizer} uses an int based API to normalize and
34 * detect token characters. See {@link CharTokenizer#isTokenChar(int)} and
35 * {@link CharTokenizer#normalize(int)} for details.</li>
38 public final class WhitespaceTokenizer extends CharTokenizer {
41 * Construct a new WhitespaceTokenizer. * @param matchVersion Lucene version
42 * to match See {@link <a href="#version">above</a>}
45 * the input to split up into tokens
47 public WhitespaceTokenizer(Version matchVersion, Reader in) {
48 super(matchVersion, in);
52 * Construct a new WhitespaceTokenizer using a given {@link AttributeSource}.
55 * Lucene version to match See {@link <a href="#version">above</a>}
57 * the attribute source to use for this {@link Tokenizer}
59 * the input to split up into tokens
61 public WhitespaceTokenizer(Version matchVersion, AttributeSource source, Reader in) {
62 super(matchVersion, source, in);
66 * Construct a new WhitespaceTokenizer using a given
67 * {@link org.apache.lucene.util.AttributeSource.AttributeFactory}.
70 * matchVersion Lucene version to match See
71 * {@link <a href="#version">above</a>}
73 * the attribute factory to use for this {@link Tokenizer}
75 * the input to split up into tokens
77 public WhitespaceTokenizer(Version matchVersion, AttributeFactory factory, Reader in) {
78 super(matchVersion, factory, in);
82 * Construct a new WhitespaceTokenizer.
84 * @deprecated use {@link #WhitespaceTokenizer(Version, Reader)} instead. This will
85 * be removed in Lucene 4.0.
88 public WhitespaceTokenizer(Reader in) {
93 * Construct a new WhitespaceTokenizer using a given {@link AttributeSource}.
95 * @deprecated use {@link #WhitespaceTokenizer(Version, AttributeSource, Reader)}
96 * instead. This will be removed in Lucene 4.0.
99 public WhitespaceTokenizer(AttributeSource source, Reader in) {
104 * Construct a new WhitespaceTokenizer using a given
105 * {@link org.apache.lucene.util.AttributeSource.AttributeFactory}.
107 * @deprecated use {@link #WhitespaceTokenizer(Version, AttributeSource.AttributeFactory, Reader)}
108 * instead. This will be removed in Lucene 4.0.
111 public WhitespaceTokenizer(AttributeFactory factory, Reader in) {
115 /** Collects only characters which do not satisfy
116 * {@link Character#isWhitespace(int)}.*/
118 protected boolean isTokenChar(int c) {
119 return !Character.isWhitespace(c);