1 package org.apache.lucene.search.spell;
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.
21 import java.util.Iterator;
26 * Dictionary represented by a text file.
28 * <p/>Format allowed: 1 word per line:<br/>
33 public class PlainTextDictionary implements Dictionary {
35 private BufferedReader in;
37 private boolean hasNextCalled;
39 public PlainTextDictionary(File file) throws FileNotFoundException {
40 in = new BufferedReader(new FileReader(file));
43 public PlainTextDictionary(InputStream dictFile) {
44 in = new BufferedReader(new InputStreamReader(dictFile));
48 * Creates a dictionary based on a reader.
50 public PlainTextDictionary(Reader reader) {
51 in = new BufferedReader(reader);
54 public Iterator<String> getWordsIterator() {
55 return new fileIterator();
58 final class fileIterator implements Iterator<String> {
59 public String next() {
63 hasNextCalled = false;
67 public boolean hasNext() {
71 } catch (IOException ex) {
72 throw new RuntimeException(ex);
74 return (line != null) ? true : false;
77 public void remove() {
78 throw new UnsupportedOperationException();