The Annoying Little Brother Program
March 25, 2008
This program takes in a text file and break it up into words. It then finds, for each word, a different word that sounds like it, and prints them both out. It’s like a little brother following you around….
Here’s the code:
package misc.rita;
import java.io.IOException;
import rita.RiLexicon;
import rita.RiMarkov;
import a2z.A2ZFileReader;
public class Blm272_Week8_Rita {
//static String content;
public static void main(String[] args) throws IOException {
A2ZFileReader fr = new A2ZFileReader(“data/obama.txt”);
RiLexicon lexicon = new RiLexicon(null);
//String regex = “\\b”;
String[] words = fr.getContent().split(” “);
for (int j = 0; j < words.length; j++){
String content = words[j].toString();
System.out.println(“Content:” + ” ” + content);
//markov.loadString(content, 1);
for (int c = 0; c < 1; c++){
String[] rhymes = lexicon.similarBySound(content);
if (rhymes != null) {
String rhyme = rhymes[(int) Math.random()*rhymes.length];
System.out.println(“Sounds like:” + ” ” + rhyme);
//System.out.println(“Sounds like: ” + rhymes[(int) Math.random()*rhymes.length]);
//for (int r = 0; r < rhymes.length; r++) {
//System.out.println(“Sounds like:” + ” ” + rhymes[r]);
//j++;
//}
}
}
}
}
}