import java.io.*;
import java.util.Scanner; //needed for the
Scanner function
class Converter{
/*
Main method */
public static void main(String[] args) throws IOException {
FileReader file1 = new FileReader("dictionary.txt"); //reads
in the file "dictionary.txt"
BufferedReader fileInput = new BufferedReader(file1); //creates a buffer
to parse teh dictionary
String Words = "{ ";
String Sounds = "{ ";
String t = "";
int i=2;
int j;
Scanner s = null;
Scanner s1;
Scanner s2;
String temp, temp1;
int firstword=0;
int newl=0;
String text;
final int NUMBER_OF_LINES_IN_FILE = 112162;
Boolean first = true; //variable to indicate if it's the first word
// Read file and output
//Creates 52 files. 26 for the
sounds and 26 for the words
FileWriter filea = new FileWriter("CMUSoundsa.txt");
PrintWriter
fileOutputa = new PrintWriter(filea);
FileWriter filea1 = new FileWriter("CMUWordsa.txt");
PrintWriter fileOutputa1 = new PrintWriter(filea1);
FileWriter fileb = new FileWriter("CMUSoundsb.txt");
PrintWriter fileOutputb = new PrintWriter(fileb);
FileWriter fileb1 = new FileWriter("CMUWordsb.txt");
PrintWriter fileOutputb1 = new PrintWriter(fileb1);
FileWriter filec = new FileWriter("CMUSoundsc.txt");
PrintWriter fileOutputc = new PrintWriter(filec);
FileWriter filec1 = new FileWriter("CMUWordsc.txt");
PrintWriter fileOutputc1 = new PrintWriter(filec1);
FileWriter filed = new FileWriter("CMUSoundsd.txt");
PrintWriter fileOutputd = new PrintWriter(filed);
FileWriter filed1 = new FileWriter("CMUWordsd.txt");
PrintWriter fileOutputd1 = new PrintWriter(filed1);
FileWriter filee = new FileWriter("CMUSoundse.txt");
PrintWriter fileOutpute = new PrintWriter(filee);
FileWriter filee1 = new FileWriter("CMUWordse.txt");
PrintWriter fileOutpute1 = new PrintWriter(filee1);
FileWriter filef = new FileWriter("CMUSoundsf.txt");
PrintWriter fileOutputf = new PrintWriter(filef);
FileWriter filef1 = new FileWriter("CMUWordsf.txt");
PrintWriter fileOutputf1 = new PrintWriter(filef1);
FileWriter fileg = new FileWriter("CMUSoundsg.txt");
PrintWriter
fileOutputg = new PrintWriter(fileg);
FileWriter fileg1 = new FileWriter("CMUWordsg.txt");
PrintWriter fileOutputg1 = new PrintWriter(fileg1);
FileWriter fileh = new FileWriter("CMUSoundsh.txt");
PrintWriter fileOutputh = new PrintWriter(fileh);
FileWriter fileh1 = new FileWriter("CMUWordsh.txt");
PrintWriter fileOutputh1 = new PrintWriter(fileh1);
FileWriter filei = new FileWriter("CMUSoundsi.txt");
PrintWriter fileOutputi = new PrintWriter(filei);
FileWriter filei1 = new FileWriter("CMUWordsi.txt");
PrintWriter fileOutputi1 = new PrintWriter(filei1);
FileWriter filej = new FileWriter("CMUSoundsj.txt");
PrintWriter fileOutputj = new PrintWriter(filej);
FileWriter filej1 = new FileWriter("CMUWordsj.txt");
PrintWriter fileOutputj1 = new PrintWriter(filej1);
FileWriter filek = new FileWriter("CMUSoundsk.txt");
PrintWriter fileOutputk = new PrintWriter(filek);
FileWriter filek1 = new FileWriter("CMUWordsk.txt");
PrintWriter fileOutputk1 = new PrintWriter(filek1);
FileWriter filel = new FileWriter("CMUSoundsl.txt");
PrintWriter fileOutputl = new PrintWriter(filel);
FileWriter filel1 = new FileWriter("CMUWordsl.txt");
PrintWriter fileOutputl1 = new PrintWriter(filel1);
FileWriter filem = new FileWriter("CMUSoundsm.txt");
PrintWriter fileOutputm = new PrintWriter(filem);
FileWriter filem1 = new FileWriter("CMUWordsm.txt");
PrintWriter fileOutputm1 = new PrintWriter(filem1);
FileWriter filen = new FileWriter("CMUSoundsn.txt");
PrintWriter
fileOutputn = new PrintWriter(filen);
FileWriter filen1 = new FileWriter("CMUWordsn.txt");
PrintWriter fileOutputn1 = new PrintWriter(filen1);
FileWriter fileo = new FileWriter("CMUSoundso.txt");
PrintWriter fileOutputo = new PrintWriter(fileo);
FileWriter fileo1 = new FileWriter("CMUWordso.txt");
PrintWriter fileOutputo1 = new PrintWriter(fileo1);
FileWriter filep = new FileWriter("CMUSoundsp.txt");
PrintWriter fileOutputp = new PrintWriter(filep);
FileWriter filep1 = new FileWriter("CMUWordsp.txt");
PrintWriter fileOutputp1 = new PrintWriter(filep1);
FileWriter fileq = new FileWriter("CMUSoundsq.txt");
PrintWriter fileOutputq = new PrintWriter(fileq);
FileWriter fileq1 = new FileWriter("CMUWordsq.txt");
PrintWriter fileOutputq1 = new PrintWriter(fileq1);
FileWriter filer = new FileWriter("CMUSoundsr.txt");
PrintWriter fileOutputr = new PrintWriter(filer);
FileWriter filer1 = new FileWriter("CMUWordsr.txt");
PrintWriter fileOutputr1 = new PrintWriter(filer1);
FileWriter files = new FileWriter("CMUSoundss.txt");
PrintWriter fileOutputs = new PrintWriter(files);
FileWriter files1 = new FileWriter("CMUWordss.txt");
PrintWriter fileOutputs1 = new PrintWriter(files1);
FileWriter filet = new FileWriter("CMUSoundst.txt");
PrintWriter fileOutputt = new PrintWriter(filet);
FileWriter filet1 = new FileWriter("CMUWordst.txt");
PrintWriter fileOutputt1 = new PrintWriter(filet1);
FileWriter fileu = new FileWriter("CMUSoundsu.txt");
PrintWriter
fileOutputu = new PrintWriter(fileu);
FileWriter fileu1 = new FileWriter("CMUWordsu.txt");
PrintWriter fileOutputu1 = new PrintWriter(fileu1);
FileWriter filev = new FileWriter("CMUSoundsv.txt");
PrintWriter fileOutputv = new PrintWriter(filev);
FileWriter filev1 = new FileWriter("CMUWordsv.txt");
PrintWriter fileOutputv1 = new PrintWriter(filev1);
FileWriter filew = new FileWriter("CMUSoundsw.txt");
PrintWriter fileOutputw = new PrintWriter(filew);
FileWriter filew1 = new FileWriter("CMUWordsw.txt");
PrintWriter fileOutputw1 = new PrintWriter(filew1);
FileWriter filex = new FileWriter("CMUSoundsx.txt");
PrintWriter fileOutputx = new PrintWriter(filex);
FileWriter filex1 = new FileWriter("CMUWordsx.txt");
PrintWriter fileOutputx1 = new PrintWriter(filex1);
FileWriter filey = new FileWriter("CMUSoundsy.txt");
PrintWriter fileOutputy = new PrintWriter(filey);
FileWriter filey1 = new FileWriter("CMUWordsy.txt");
PrintWriter fileOutputy1 = new PrintWriter(filey1);
FileWriter filez = new FileWriter("CMUSoundsz.txt");
PrintWriter fileOutputz = new PrintWriter(filez);
FileWriter filez1 = new FileWriter("CMUWordsz.txt");
PrintWriter fileOutputz1 = new PrintWriter(filez1);
//Tranverses through the file line by line
//until the NUMBER_OF_LINES_IN_FILE is reached
for(int counter=0; counter <
NUMBER_OF_LINES_IN_FILE; counter++) {
Sounds=""; //resets the string for the allophones
Words=""; //resets the
string for the words
first=true;
temp
= fileInput.readLine(); //reads in the next line
temp1 = new String(temp); //creates a new String that is the same as
temp
//creates two similar Scanners that do not point to one another
s =
new Scanner(temp);
s2 =
new Scanner(temp1);
if((s2.next()).length()<6){ //checks if the word's length is < 6
while (s.hasNext()) {
t=s.next(); //takes in
the next token/word
i = t.length();
if(first){ //if first word of
line (the word to be placed in the dictionary)
newl++;
t = t.toLowerCase();
for(j=0; j<t.length();
j++){
Words+=("'" +
t.charAt(j)+ "' ,");
}
first=false;
Words+="'*'," ;
Sounds+="'*',";
//creates a new line 15 words
//for ease of pasting into
Cadence
if(newl==15){
Words+="\r\n";
Sounds+="\r\n";
newl=0;
}
}
//Additional Code that was used to parse through
//the Phrase-A-Lator Dictionary
/*
else if(t.equals("=")){
//System.out.println(prevWord);
//System.out.println(t);
for(j=0;
j<prevWord.length(); j++){
Words+=("'" + prevWord.charAt(j)+
"',");
}
Words+="'*',";
Sounds+="'*',";
}
else if(((i>0)&&(t.charAt(i-1))==('='))){
System.out.println(i);
System.out.println(t);
for(j=0; j<i-1; j++){
Words+=("'" +
t.charAt(j)+ "',");
}
Words+="'*',";
Sounds+="'*',";
}
*/
//converts the phonmes in the CMU dictionary to their
//corresponding control signal for the SpeakJet
//these are for the CMU dictionary
else
if(t.equals("AA0")){
Sounds+=" 136,";
}
else
if(t.equals("AA1")){
Sounds+=" 136,";
}
else
if(t.equals("AA2")){
Sounds+=" 136,";
}
else
if(t.equals("AE0")){
Sounds+=" 132,";
}else
if(t.equals("AE1")){
Sounds+=" 132,";
}
else
if(t.equals("AE2")){
Sounds+=" 132,";
}
else
if(t.equals("AH0")){
Sounds+=" 130,";
}
else
if(t.equals("AH1")){
Sounds+=" 134,";
}
else
if(t.equals("AH2")){
Sounds+=" 134,";
}
else
if(t.equals("AO0")){
Sounds+=" 135,";
}
else
if(t.equals("AO1")){
Sounds+=" 136, 136
,";
}
else
if(t.equals("AO2")){
Sounds+=" 136, 136
,";
}
else
if(t.equals("AW0")){
Sounds+=" 137,";
}
else
if(t.equals("AW1")){
Sounds+=" 161,";
}
else
if(t.equals("AW2")){
Sounds+=" 161,";
}
else
if(t.equals("AY0")){
Sounds+=" 157,";
}
else
if(t.equals("AY1")){
Sounds+=" 157,";
}
else if(t.equals("AY2
")){
Sounds+=" 157,";
}
else
if(t.equals("B")){
Sounds+=" 172,";
}
else
if(t.equals("CH")){
Sounds+=" 182,";
}
else
if(t.equals("D")){
Sounds+=" 176,";
}
else
if(t.equals("DH")){
Sounds+=" 169,";
}
else
if(t.equals("EH0")){
Sounds+=" 131,";
}
else if(t.equals("EH1
")){
Sounds+=" 131,";
}
else
if(t.equals("EH2")){
Sounds+=" 131,";
}
else
if(t.equals("ER0")){
Sounds+=" 151,";
}
else
if(t.equals("ER1")){
Sounds+=" 151,";
}
else if(t.equals("ER2")){
Sounds+=" 151,";
}
else
if(t.equals("EY0")){
Sounds+=" 130,";
}
else
if(t.equals("EY1")){
Sounds+=" 154,";
}
else
if(t.equals("EY2")){
Sounds+=" 154,";
}
else
if(t.equals("F")){
Sounds+=" 186,";
}
else
if(t.equals("G")){
Sounds+=" 178,";
}
else
if(t.equals("HH")){
Sounds+=" 183,";
}
else
if(t.equals("IH0")){
Sounds+=" 129,";
}
else if(t.equals("IH1")){
Sounds+=" 129,";
}
else
if(t.equals("IH2")){
Sounds+=" 129,
129,";
}
else
if(t.equals("IY0")){
Sounds+=" 128,";
}
else
if(t.equals("IY1")){
Sounds+=" 128,
128,";
}
else
if(t.equals("IY2")){
Sounds+=" 128, 128,
128,";
}
else if(t.equals("JH")){
Sounds+=" 165,";
}
else
if(t.equals("K")){
Sounds+=" 194,";
}
else
if(t.equals("L")){
Sounds+=" 145,";
}
else
if(t.equals("M")){
Sounds+=" 140,";
}
else
if(t.equals("N")){
Sounds+=" 141,";
}
else
if(t.equals("NG")){
Sounds+=" 143,";
}
else
if(t.equals("OW0")){
Sounds+=" 135,";
}
else
if(t.equals("OW1")){
Sounds+=" 137,
137,";
}
else if(t.equals("OW2")){
Sounds+=" 137,
137,";
}
else
if(t.equals("OY0")){
Sounds+=" 156,";
}
else
if(t.equals("OY1")){
Sounds+=" 156,";
}
else
if(t.equals("OY2")){
Sounds+=" 156,";
}
else
if(t.equals("P")){
Sounds+=" 199,";
}
else
if(t.equals("R")){
Sounds+="
148,";
}
else
if(t.equals("S")){
Sounds+=" 187,";
}
else
if(t.equals("SH")){
Sounds+=" 189,";
}
else if(t.equals("T")){
Sounds+=" 191,";
}
else
if(t.equals("TH")){
Sounds+=" 169,";
}
else
if(t.equals("UH0")){
Sounds+=" 138,";
}
else
if(t.equals("UH1")){
Sounds+=" 138,
138,";
}
else
if(t.equals("UH2")){
Sounds+=" 138,
138,";
}
else
if(t.equals("UW0")){
Sounds+=" 139,";
}
else
if(t.equals("UW1")){
Sounds+=" 139,
139,";
}
else
if(t.equals("UW2")){
Sounds+=" 139, 139,
139,";
}
else
if(t.equals("V")){
Sounds+=" 166,";
}
else
if(t.equals("W")){
Sounds+=" 147,";
}
else
if(t.equals("Y")){
Sounds+=" 158,";
}
else
if(t.equals("Z")){
Sounds+=" 167,";
}
else
if(t.equals("ZH")){
Sounds+=" 168,";
}
//converts the phonmes in the
Phrase-A-Lator dictionary to their
//corresponding control signal for the SpeakJet
//these are for the Phrase-A-Lator dictionary
else
if(t.equals("IY")){
Sounds+=" 128,";
}
else
if(t.equals("IH")){
Sounds+=" 129,";
}
else
if(t.equals("EY")){
Sounds+=" 130,";
}
else if(t.equals("EH")){
Sounds+=" 131,";
}
else
if(t.equals("AY")){
Sounds+=" 132,";
}
else
if(t.equals("AX")){
Sounds+=" 133,";
}
else
if(t.equals("UX")){
Sounds+=" 134,";
}
else
if(t.equals("OH")){
Sounds+=" 135,";
}
else
if(t.equals("AW")){
Sounds+=" 136,";
}
else
if(t.equals("OW")){
Sounds+=" 137,";
}
else
if(t.equals("UH")){
Sounds+=" 138,";
}
else if(t.equals("UW")){
Sounds+=" 139,";
}
else
if(t.equals("MM")){
Sounds+=" 140,";
}
else
if(t.equals("NE")){
Sounds+=" 141,";
}
else
if(t.equals("NO")){
Sounds+=" 142,";
}
else
if(t.equals("NGE")){
Sounds+=" 143,";
}
else
if(t.equals("NGO")){
Sounds+=" 144,";
}
else
if(t.equals("LE")){
Sounds+=" 145,";
}
else
if(t.equals("LO")){
Sounds+=" 146,";
}
else
if(t.equals("WW")){
Sounds+=" 147,";
}
else
if(t.equals("RR")){
Sounds+=" 148,";
}
else
if(t.equals("IYRR")){
Sounds+=" 149,";
}
else
if(t.equals("EYRR")){
Sounds+=" 150,";
}
else
if(t.equals("AXRR")){
Sounds+=" 151,";
}
else
if(t.equals("AWRR")){
Sounds+=" 152,";
}
else
if(t.equals("OWRR")){
Sounds+=" 153,";
}
else
if(t.equals("EYIY")){
Sounds+=" 154,";
}
else
if(t.equals("OHIY")){
Sounds+="
155,";
}
else
if(t.equals("OWIY")){
Sounds+=" 156,";
}
else
if(t.equals("OHIH")){
Sounds+=" 157,";
}
else
if(t.equals("IYEH")){
Sounds+=" 158,";
}
else
if(t.equals("EHLL")){
Sounds+=" 159,";
}
else
if(t.equals("IYUW")){
Sounds+=" 160,";
}
else
if(t.equals("AXUW")){
Sounds+=" 161,";
}
else
if(t.equals("IHWW")){
Sounds+=" 162,";
}
else
if(t.equals("AYWW")){
Sounds+=" 163,";
}
else
if(t.equals("OWWW")){
Sounds+=" 164,";
}
else
if(t.equals("JH")){
Sounds+=" 165,";
}
else
if(t.equals("VV")){
Sounds+=" 166,";
}
else
if(t.equals("ZZ")){
Sounds+=" 167,";
}
else
if(t.equals("ZH")){
Sounds+=" 168,";
}
else
if(t.equals("DH")){
Sounds+=" 169,";
}
else
if(t.equals("BE")){
Sounds+=" 170,";
}
else
if(t.equals("BO")){
Sounds+=" 171,";
}
else
if(t.equals("EB")){
Sounds+=" 172,";
}
else
if(t.equals("OB")){
Sounds+=" 173,";
}
else if(t.equals("DE")){
Sounds+=" 174,";
}
else
if(t.equals("DO")){
Sounds+=" 175,";
}
else
if(t.equals("ED")){
Sounds+=" 176,";
}
else if(t.equals("OD")){
Sounds+=" 177,";
}
else
if(t.equals("GE")){
Sounds+=" 178,";
}
else
if(t.equals("GO")){
Sounds+=" 179,";
}
else
if(t.equals("EG")){
Sounds+=" 180,";
}
else
if(t.equals("OG")){
Sounds+=" 181,";
}
else
if(t.equals("CH")){
Sounds+=" 182,";
}
else
if(t.equals("HE")){
Sounds+=" 183,";
}
else
if(t.equals("HO")){
Sounds+=" 184,";
}
else if(t.equals("WH")){
Sounds+=" 185,";
}
else
if(t.equals("FF")){
Sounds+=" 186,";
}
else
if(t.equals("SE")){
Sounds+=" 187,";
}
else
if(t.equals("SO")){
Sounds+=" 188,";
}
else
if(t.equals("SH")){
Sounds+=" 189,";
}
else
if(t.equals("TH")){
Sounds+=" 190,";
}
else
if(t.equals("TT")){
Sounds+=" 191,";
}
else
if(t.equals("TU")){
Sounds+=" 192,";
}
else if(t.equals("TS")){
Sounds+=" 193,";
}
else
if(t.equals("KE")){
Sounds+=" 194,";
}
else
if(t.equals("KO")){
Sounds+=" 195,";
}
else
if(t.equals("EK")){
Sounds+=" 196,";
}
else
if(t.equals("OK")){
Sounds+=" 197,";
}
else
if(t.equals("PE")){
Sounds+=" 198,";
}
else
if(t.equals("PO")){
Sounds+=" 199,";
}
}
//writes the words and allophones to their respective files
//based on their first character
//the first character in "Words" is '{', so the first
character of the word
//is at position 1
if(Words.charAt(1)=='a'){
filea.write(Sounds);
filea1.write(Words);
}
else if(Words.charAt(1)=='b'){
fileb.write(Sounds);
fileb1.write(Words);
}
else if(Words.charAt(1)=='c'){
filec.write(Sounds);
filec1.write(Words);
}
else if(Words.charAt(1)=='d'){
filed.write(Sounds);
filed1.write(Words);
}
else if(Words.charAt(1)=='e'){
filee.write(Sounds);
filee1.write(Words);
}
else if(Words.charAt(1)=='f'){
filef.write(Sounds);
filef1.write(Words);
}
else if(Words.charAt(1)=='g'){
fileg.write(Sounds);
fileg1.write(Words);
}
else if(Words.charAt(1)=='h'){
fileh.write(Sounds);
fileh1.write(Words);
}
else if(Words.charAt(1)=='i'){
filei.write(Sounds);
filei1.write(Words);
} else if(Words.charAt(1)=='j'){
filej.write(Sounds);
filej1.write(Words);
} else if(Words.charAt(1)=='k'){
filek.write(Sounds);
filek1.write(Words);
} else if(Words.charAt(1)=='l'){
filel.write(Sounds);
filel1.write(Words);
} else if(Words.charAt(1)=='m'){
filem.write(Sounds);
filem1.write(Words);
}
else if(Words.charAt(1)=='n'){
filen.write(Sounds);
filen1.write(Words);
} else if(Words.charAt(1)=='o'){
fileo.write(Sounds);
fileo1.write(Words);
} else if(Words.charAt(1)=='p'){
filep.write(Sounds);
filep1.write(Words);
} else if(Words.charAt(1)=='q'){
fileq.write(Sounds);
fileq1.write(Words);
} else if(Words.charAt(1)=='r'){
filer.write(Sounds);
filer1.write(Words);
} else if(Words.charAt(1)=='s'){
files.write(Sounds);
files1.write(Words);
} else if(Words.charAt(1)=='t'){
filet.write(Sounds);
filet1.write(Words);
} else if(Words.charAt(1)=='u'){
fileu.write(Sounds);
fileu1.write(Words);
} else if(Words.charAt(1)=='v'){
filev.write(Sounds);
filev1.write(Words);
} else if(Words.charAt(1)=='w'){
filew.write(Sounds);
filew1.write(Words);
} else if(Words.charAt(1)=='x'){
filex.write(Sounds);
filex1.write(Words);
} else if(Words.charAt(1)=='y'){
filey.write(Sounds);
filey1.write(Words);
} else if(Words.charAt(1)=='z'){
filez.write(Sounds);
filez1.write(Words);
}
}
}//
for loop
//closes all 52 files
fileOutputa.close();
fileOutputa1.close();
fileOutputb.close();
fileOutputb1.close();
fileOutputc.close();
fileOutputc1.close();
fileOutputd.close();
fileOutputd1.close();
fileOutpute.close();
fileOutpute1.close();
fileOutputf.close();
fileOutputf1.close();
fileOutputg.close();
fileOutputg1.close();
fileOutputh.close();
fileOutputh1.close();
fileOutputi.close();
fileOutputi1.close();
fileOutputj.close();
fileOutputj1.close();
fileOutputk.close();
fileOutputk1.close();
fileOutputl.close();
fileOutputl1.close();
fileOutputm.close();
fileOutputm1.close();
fileOutputn.close();
fileOutputn1.close();
fileOutputo.close();
fileOutputo1.close();
fileOutputp.close();
fileOutputp1.close();
fileOutputq.close();
fileOutputq1.close();
fileOutputr.close();
fileOutputr1.close();
fileOutputs.close();
fileOutputs1.close();
fileOutputt.close();
fileOutputt1.close();
fileOutputu.close();
fileOutputu1.close();
fileOutputv.close();
fileOutputv1.close();
fileOutputw.close();
fileOutputw1.close();
fileOutputx.close();
fileOutputx1.close();
fileOutputy.close();
fileOutputy1.close();
fileOutputz.close();
fileOutputz1.close();
}//main
}//class