01: package org.apache.lucene.analysis.sinks;
02:
03: import org.apache.lucene.analysis.SinkTokenizer;
04: import org.apache.lucene.analysis.Token;
05:
06: import java.io.IOException;
07:
08: /**
09: * Licensed to the Apache Software Foundation (ASF) under one or more
10: * contributor license agreements. See the NOTICE file distributed with
11: * this work for additional information regarding copyright ownership.
12: * The ASF licenses this file to You under the Apache License, Version 2.0
13: * (the "License"); you may not use this file except in compliance with
14: * the License. You may obtain a copy of the License at
15: *
16: * http://www.apache.org/licenses/LICENSE-2.0
17: *
18: * Unless required by applicable law or agreed to in writing, software
19: * distributed under the License is distributed on an "AS IS" BASIS,
20: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21: * See the License for the specific language governing permissions and
22: * limitations under the License.
23: */
24:
25: /**
26: * Counts the tokens as they go by and saves to the internal list those between the range of lower and upper, exclusive of upper
27: *
28: **/
29: public class TokenRangeSinkTokenizer extends SinkTokenizer {
30: private int lower;
31: private int upper;
32: private int count;
33:
34: public TokenRangeSinkTokenizer(int lower, int upper) {
35: this .lower = lower;
36: this .upper = upper;
37: }
38:
39: public TokenRangeSinkTokenizer(int initCap, int lower, int upper) {
40: super (initCap);
41: this .lower = lower;
42: this .upper = upper;
43: }
44:
45: public void add(Token t) {
46: if (count >= lower && count < upper) {
47: super .add(t);
48: }
49: count++;
50: }
51:
52: public void reset() throws IOException {
53: count = 0;
54: }
55: }
|