cs230 Lecture Notes Hi all. These are my ex post facto notes for the last couple of lectures. I didn't write them ahead of time because I wanted us to discuss the material in real time. Here are some of the topics we have covered: 1) slurpy implementation 2) Alan Turing 3) data structures for the Markov algorithm 4) the space-time continuuuuuum 5) interning Strings Here is the code for interning Strings: public String internWord (String word) { String canon = (String) intern.get (word); if (canon == null) { intern.put (word, word); return word; } return canon; } intern is an instance variable (a Hashtable) that was initialized in the constructor. Also, here is some code for generating random words from a Hashtable (this is way more complicated than we would like): public String randomWord (Hashtable suffixes) { int count = totalSuffixes (suffixes); int x = randInt (0, count-1); Enumeration keys = suffixes.keys (); int total = 0; while (keys.hasMoreElements ()) { Object key = keys.nextElement (); Integer value = (Integer) suffixes.get (key); total += value.intValue (); if (total > x) return (String) key; } // we should never get here return null; } public int totalSuffixes (Hashtable suffixes) { int total = 0; Enumeration keys = suffixes.keys (); while (keys.hasMoreElements ()) { Object key = keys.nextElement (); Integer value = (Integer) suffixes.get (key); total += value.intValue (); } return total; } // randInt: returns a random number between low and high, // including both endpoints public static int randInt (int low, int high) { while (true) { int x = (int)(Math.random() * (high-low+1) + low); if (x >= low && x <= high) return x; } } One other thing we talked about is the possibility of having a "kill list" -- words that appear in the file but that we should not include in the generated text. I created a Hashtable to contain all the bad words: public void makeKillTable () { kill = new Hashtable (); String[] badWords = {"verbatim", ".", ",", "x", "y", "i++", ".eps", "itemize"}; for (int i=0; i< badWords.length; i++) { kill.put (badWords[i], "k"); } }