"""A program that deciphers the transcripts from the Loebner Prize Contest 2006. This program is free software. Version 2006.10.24: The first-version transcripts let me figure out the conversations well enough to realize that it should be split into "left" and "right" halves. So in this version the two are given sequentially rather than being interleaved. And they're no longer the "20006" edition. 8) """ 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 2006 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.\n" transcript += "--- Transcript follows: ---\n" ll, lr, rl, rr = "","","","" transcript_left, transcript_right = "", "" SPEAKERS = {"local left":(ll,transcript_left), "local right":(lr,transcript_right), "remote left":(rl,transcript_left), "remote right":(rr,transcript_right) } for line in lines[3:]: ## Ignore file header. if line[:16] == "starting session": ## This line is a new-session mark. ## Write completed transcripts for left and right sides. ## If this is the first session, never mind. if transcript_left: transcript += transcript_left +"\n\n" transcript_left = "" if transcript_right: transcript += transcript_right+"\n\n" transcript_right = "" transcript += "\n\n--- "+line.title()+" --- \n" elif not line: pass 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": ## Send finished line to transcript_left or transcript_right. SPEAKERS[s][1] += s.upper()+": "+SPEAKERS[s][0] + "\n" SPEAKERS[s][0] = "" elif actual_key_pressed == "space": SPEAKERS[s][0] += " " elif actual_key_pressed == "BackSpace": SPEAKERS[s][0] += "~" else: SPEAKERS[s][0] += words[-1] output = open("output.txt","w") output.write(transcript) output.close()