1 package org.apache.lucene.analysis; 2 3 18 19 import java.io.File ; 20 import java.io.FileReader ; 21 import java.io.IOException ; 22 import java.io.Reader ; 23 import java.io.BufferedReader ; 24 import java.util.HashSet ; 25 import java.util.Hashtable ; 26 import java.util.Iterator ; 27 28 34 public class WordlistLoader { 35 36 45 public static HashSet getWordSet(File wordfile) throws IOException { 46 HashSet result = new HashSet (); 47 FileReader reader = null; 48 try { 49 reader = new FileReader (wordfile); 50 result = getWordSet(reader); 51 } 52 finally { 53 if (reader != null) 54 reader.close(); 55 } 56 return result; 57 } 58 59 68 public static HashSet getWordSet(Reader reader) throws IOException { 69 HashSet result = new HashSet (); 70 BufferedReader br = null; 71 try { 72 if (reader instanceof BufferedReader ) { 73 br = (BufferedReader ) reader; 74 } else { 75 br = new BufferedReader (reader); 76 } 77 String word = null; 78 while ((word = br.readLine()) != null) { 79 result.add(word.trim()); 80 } 81 } 82 finally { 83 if (br != null) 84 br.close(); 85 } 86 return result; 87 } 88 89 95 public static Hashtable getWordtable(String path, String wordfile) throws IOException { 96 return getWordtable(new File (path, wordfile)); 97 } 98 99 104 public static Hashtable getWordtable(String wordfile) throws IOException { 105 return getWordtable(new File (wordfile)); 106 } 107 108 113 public static Hashtable getWordtable(File wordfile) throws IOException { 114 HashSet wordSet = (HashSet )getWordSet(wordfile); 115 Hashtable result = makeWordTable(wordSet); 116 return result; 117 } 118 119 125 private static Hashtable makeWordTable(HashSet wordSet) { 126 Hashtable table = new Hashtable (); 127 for (Iterator iter = wordSet.iterator(); iter.hasNext();) { 128 String word = (String )iter.next(); 129 table.put(word, word); 130 } 131 return table; 132 } 133 } 134 | Popular Tags |