def write(self,vb=voicebox):
        if not vb.voices:
            print("Cannot write with an empty Voicebox!")
            return

        self.chooseVoiceMenu(vb)

        scriptlog =[]
        cur = 0
        linelog = []
        hashtable = {}

        while 1:
            before = linelog[:cur]
            after = linelog[cur:]

            if vb.vision >= len(before):
                recent_words = before
            else:
                firstword = len(before) - vb.vision
                recent_words = before[firstword:]

            # hash check on this set of recent words
            if "".join(recent_words) in hashtable:
                options = hashtable["".join(recent_words)]
            else:
                options = vb.getOptions(recent_words)[0:vb.num_opts]
                hashtable["".join(recent_words)] = options

            self.printOptions(options)

            try:
                response = raw_input('Choose one\n')
            except __HOLE__:
                response = input('Choose one\n')
            if response.isdigit():
                response = int(response)
                if response >= 1 and response <= vb.num_opts:
                    before += [options[response-1][0]]
                    linelog = before + after
                    cur += 1
                    print(self.voiceHeader(vb))
                    self.printLog(scriptlog+linelog,cur)
                elif response == 0:
                    scriptlog = scriptlog + linelog
                    print('Final output: ')
                    print(' '.join(scriptlog))
                    return scriptlog
                else:
                    print("Number out of range!")
                    self.printLog(scriptlog+linelog,cur)
            elif response == 'x':
                if len(before) == 0:
                    print("Cannot delete the start of the sentence!")
                else:
                    cur -= 1
                    del before[-1] # remove last element of current line
                    linelog = before + after
                self.printLog(scriptlog+linelog,cur)
            elif response == 'z':
                cur -= 1
                self.printLog(scriptlog+linelog,cur)
            elif response == 'c':
                if cur == len(linelog):
                    print("Already at end of sentence!")
                else:
                    cur += 1
                self.printLog(scriptlog+linelog,cur)
            elif response == '.' or response=='?':        # starts a new sentence
                before[-1] += response
                linelog = before + after
                scriptlog = scriptlog + linelog
                linelog = []
                self.printLog(scriptlog+linelog,cur)
            elif response in ['m','menu']:
                self.writing_menu(vb)
                self.printLog(scriptlog+linelog,cur)
            #elif re.compile('v\d',response):
            #    number = response[1]
            #    print "here"
            elif isinstance(response, str):
                before = before + [response]
                linelog = before + after
                cur += 1
                self.printLog(scriptlog+linelog,cur)
            else:
                print("Invalid input. Choose a number between 1 and " + str(vb.num_opts) + " or enter a word manually.")
                self.printLog(scriptlog+linelog,cur)
dataset/ETHPy150Open jbrew/pt-voicebox/writer.py/Writer.write