"""A program that deciphers the transcripts from the Loebner Prize Contest 2006. This program is free software. This version is slightly modified to deal with a quirky transcript; you should probably use the other one.""" f = open( raw_input("Please type the name of the file to translate: "),"r") text_raw = f.read() f.close() lines = text_raw.split("\n") transcript = "Loebner Prize 20006 Sept 17, 2006\nUniversity College London\n" transcript += "Translated from "+str(len(lines))+" lines of machinespeak by Kris Schnee.\nThis transcript is unofficial and is in the public domain.\n" transcript += "'~' indicates a backspace.\nTiming information is omitted, so this text may differ from the official transcripts (which are effectively human-unreadable).\n" transcript += "--- Transcript follows: ---\n" ll, lr, rl, rr = "","","","" SPEAKERS = {"local left":ll,"local right":lr,"remote left":rl,"remote right":rr} for line in lines[3:]: if line[:16] == "starting session": transcript += "\n\n--- "+line.title()+" --- \n" elif not line: pass """This bit of code was added to handle an odd formatting difference between the "John" transcript and the others; in that one a line representing a blank character (not a space) would appear after each period.""" elif actual_key_pressed == ".": actual_key_pressed = "" pass ## Handle this line. else: words = line.split()[-3:] actual_key_pressed = words[-1] s = words[-3]+" "+words[-2] speaker = SPEAKERS.get( s ) if speaker == None: raise "Error: Can't figure out who spoke: \""+s+"\"?" if actual_key_pressed == "CR": transcript += s.upper()+": "+SPEAKERS[s] + "\n" SPEAKERS[s] = "" elif actual_key_pressed == "space": SPEAKERS[s] += " " elif actual_key_pressed == "BackSpace": SPEAKERS[s] += "~" else: SPEAKERS[s] += words[-1] output = open("output.txt","w") output.write(transcript) output.close()