1 package org.apache.lucene.analysis.de; 2 3 18 19 import java.io.File ; 20 import java.io.FileReader ; 21 import java.io.IOException ; 22 import java.io.LineNumberReader ; 23 import java.util.HashSet ; 24 import java.util.Hashtable ; 25 import java.util.Iterator ; 26 27 35 public class WordlistLoader { 36 37 46 public static HashSet getWordSet(File wordfile) throws IOException { 47 HashSet result = new HashSet (); 48 FileReader freader = null; 49 LineNumberReader lnr = null; 50 try { 51 freader = new FileReader (wordfile); 52 lnr = new LineNumberReader (freader); 53 String word = null; 54 while ((word = lnr.readLine()) != null) { 55 result.add(word.trim()); 56 } 57 } 58 finally { 59 if (lnr != null) 60 lnr.close(); 61 if (freader != null) 62 freader.close(); 63 } 64 return result; 65 } 66 67 73 public static Hashtable getWordtable(String path, String wordfile) throws IOException { 74 return getWordtable(new File (path, wordfile)); 75 } 76 77 82 public static Hashtable getWordtable(String wordfile) throws IOException { 83 return getWordtable(new File (wordfile)); 84 } 85 86 91 public static Hashtable getWordtable(File wordfile) throws IOException { 92 HashSet wordSet = (HashSet )getWordSet(wordfile); 93 Hashtable result = makeWordTable(wordSet); 94 return result; 95 } 96 97 103 private static Hashtable makeWordTable(HashSet wordSet) { 104 Hashtable table = new Hashtable (); 105 for (Iterator iter = wordSet.iterator(); iter.hasNext();) { 106 String word = (String )iter.next(); 107 table.put(word, word); 108 } 109 return table; 110 } 111 } 112 | Popular Tags |