"""A program that deciphers the transcripts from the Loebner Prize Contest. This program is free software. Version 2009.9.30. Bugfix in latest version: Last round wasn't getting written to the file, because the program was waiting for another start-of-round mark. Fixed.""" f = open( raw_input("Please type the name of the file to translate: "),"r") text_raw = f.read() f.close() class Transcriber: def __init__(self): self.transcript = "" self.transcript = "Loebner Prize 2009, Brighton UK\n" self.transcript += "Translated from machinespeak by Kris Schnee and his Python utility program.\nThis transcript is unofficial and is in the public domain.\n" self.transcript += "This contest involved a human judge (\"Local\") speaking simultaneously with a human and an AI, and trying to decide which is which. So, the \"Left\" and \"Right\" sections are the two parallel conversations in each round -- one with a human, one with an AI. Can you tell which is which?\n" self.transcript += "This was a version of the Turing Test meant to test for AI intelligence, implemented annually by Hugh Loebner, with prize money at stake both for actual victory and for having the best bot when they all fail the main test.\n" self.transcript += "'~' indicates a backspace.\nTiming information is omitted, so this text may differ from the official transcripts. The messy formatting is due both to my coding skills and to the unusual communications protocol.\n" self.transcript += "--- Transcript follows: ---\n" def WriteCurrentRound(self): if self.left_transcript or self.right_transcript: self.transcript += "\n\n---LEFT: ---\n" + "\n".join(self.left_transcript) self.transcript += "\n\n---RIGHT: ---\n" + "\n".join(self.right_transcript) def Main(self,text): lines = text_raw.split("\n") main_transcript = [] self.left_transcript = [] self.right_transcript = [] ll = "" lr = "" rl = "" rr = "" for line in lines[3:]: ## Ignore file header. if not line: pass elif line[:2] == "**": self.transcript += "\n"+line elif line[0] == "*": ## This line is a new-session mark. self.WriteCurrentRound() self.transcript += "\n\n"+line self.left_transcript = [] self.right_trancript = [] ll = "" lr = "" rl = "" rr = "" else: words = line.split()[-3:] key_pressed = words[-1] local = (words[-3] == "local") left = (words[-2] == "left") if key_pressed == "space": t = " " elif key_pressed == "CR": t = "[RETURN]" elif key_pressed == "BackSpace": t = "~" else: t = words[-1] if not key_pressed == "CR": if left and local: ll += t elif left: lr += t elif not left and local: rl += t else: rr += t else: if left: if local: self.left_transcript.append("Local: "+ll) ll = "" else: self.left_transcript.append("Remote: "+lr) lr = "" else: if local: self.right_transcript.append("Local: "+rl) rl = "" else: self.right_transcript.append("Remote: "+rr) rr = "" ## Write the last round's transcript. self.WriteCurrentRound() ## Autorun t = Transcriber() t.Main(text_raw) output = open("output.txt","w") output.write(t.transcript) output.close()