import java.io.*; public class TestDictionary { public static void createDictionary(Dictionary dict,String source) throws IOException { BufferedReader in = new BufferedReader(new FileReader(source)); String line = in.readLine(); while(!line.equals("end")) { int index = line.indexOf('@'); String wordEng = line.substring(0,index); String wordBul = line.substring(index + 1); dict.put(wordEng,wordBul); line = in.readLine(); } } public static void createFrequencyDictionary(FrequencyDictionaryImp dict, String source) throws IOException { BufferedReader in = new BufferedReader(new FileReader(source)); String word = ""; int c; while((c = in.read()) !=- 1) { for(; (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); c = in.read()) word = word + (char)c; if(word.compareTo("") != 0) { dict.put(word,new Double(1)); word = ""; } if(c == -1) break; } dict.create(); } public static void main(String[] args) { try { String s = File.separator; String source = System.getProperty("user.dir") + s + "testDictData.txt"; System.out.println("Read text from the file " + source); Function table; table = new ListTable(); //table = new TreeTable(new BinarySearchTree(new EntryComparator())); //table = new HashTable(); Dictionary dict1 = new DictionaryImp(table); createDictionary(dict1,source); System.out.println(" English-Bulgarian Dictionary:" + "\n" + dict1); source = System.getProperty("user.dir") + s + "testFreqDictData.txt"; System.out.println("Read text from the file " + source); table = new ListTable(); //table = new TreeTable(new BinarySearchTree(new EntryComparator())); //table = new HashTable(); FrequencyDictionaryImp dict2 = new FrequencyDictionaryImp(table); createFrequencyDictionary(dict2,source); System.out.println(" Frequency Dictionary:" + "\n" + dict2); }catch (IOException e) {} } }