public String choose(ArrayList al, int i) { // Choose next word based on Hashtable hm = maps[i]; // previous i words in al String prefix = Rewrite.concat(al, i); PrefixEntry e = (PrefixEntry) hm.get(prefix); if (e == null) return ""; return e.choose(); }
void add(String previous, String newWord, int n) { // "now is the" -> <PrefixEntry"time"> Hashtable hm = maps[n]; nEntries[n]++; PrefixEntry e = (PrefixEntry) hm.get(previous); if (e == null) { e = new PrefixEntry(previous); hm.put(previous, e); } e.add(newWord); }
public void calculateStatistics() { // Just a bunch of numbers for (int i = 0; i < Rewrite.MAX; i++) { markerWord = markerWord2; Hashtable hm = maps[i]; Iterator iter = hm.keySet().iterator(); while (iter.hasNext()) { String key = (String) iter.next(); PrefixEntry e = (PrefixEntry) hm.get(key); e.calculateStatistics(this); } } }
public void dump() { System.out.println(this); for (int i = 0; i < Rewrite.MAX; i++) { Hashtable hm = maps[i]; Iterator iter = hm.keySet().iterator(); while (iter.hasNext()) { String key = (String) iter.next(); PrefixEntry e = (PrefixEntry) hm.get(key); e.dump(); } System.out.println("--------------------------------"); } }