1 package org.apache.lucene.search.suggest;
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.
23 import org.apache.lucene.search.spell.Dictionary;
24 import org.apache.lucene.search.spell.TermFreqIterator;
28 * Dictionary represented by a text file.
30 * <p/>Format allowed: 1 string per line, optionally with a tab-separated integer value:<br/>
32 * word2 word3 TAB 101<br/>
33 * word4 word5 TAB 102<br/>
35 public class FileDictionary implements Dictionary {
37 private BufferedReader in;
39 private boolean hasNextCalled;
41 public FileDictionary(InputStream dictFile) {
42 in = new BufferedReader(new InputStreamReader(dictFile));
46 * Creates a dictionary based on a reader.
48 public FileDictionary(Reader reader) {
49 in = new BufferedReader(reader);
52 public TermFreqIterator getWordsIterator() {
53 return new fileIterator();
56 final class fileIterator implements TermFreqIterator {
57 private float curFreq;
59 public String next() {
63 hasNextCalled = false;
71 public boolean hasNext() {
76 String[] fields = line.split("\t");
77 if (fields.length > 1) {
78 curFreq = Float.parseFloat(fields[1]);
84 } catch (IOException ex) {
85 throw new RuntimeException(ex);
87 return (line != null) ? true : false;
90 public void remove() {
91 throw new UnsupportedOperationException();