def testLoop(): global mainConfig,vit while True: drawTest() ans = raw_input("* Select an option: ") if (ans == ""): break elif (ans == '1'): w = raw_input("Enter a whole word to predict next word: ") if isValidInput(w): mirror_functions.getTopNext(w,'word',mainConfig['rslts']) else: print "ERROR: Please use only [a-z] or apostrophe" wait() elif (ans == '2'): w = raw_input("Enter a prefix to predict word: ") if isValidInput(w): mirror_functions.getTopPrefix(w,mainConfig['rslts']) else: print "ERROR: Please use only [a-z] or apostrophe" wait() elif (ans == '3'): w = raw_input("Enter a mirrored prefix or word to predict word: ") if isValidInput(w,False): mirror_functions.getTopNext(w,'tran',mainConfig['rslts'],"") else: print "ERROR: Please use only [qwertasdfgzxcvb], apostrophe, or pipe" wait() elif (ans == '4'): w = raw_input("Enter a mirrored word to predict word: ") if isValidInput(w,False): print vit.runViterbi(w) else: print "ERROR: Only use [qwertasdfgzxcvb] or apostrophe" wait()
def runTest(s,n): startTime = time.time() infile = open("test"+ path_separator + s,"r") outfile = open("test" + path_separator + "results.csv", "w") outfile.write("word,mirror,length,numMirrors,predIndx,correct\n\n") ## Initialize testing counts wordCount = 0 correctWords = 0 allRslts = {} for line in infile: words = line.split() firstword = ' ' secondword = ' ' endOfSentence = False for w in words: wordCount += 1 word = build.sanitizeWord(w) mirror = mirror_functions.mirror(word) #specify how to get these results results = mirror_functions.getTopNext(mirror+'|','tran',n,"",True) outfile.write(word + ',' + mirror + ',' + str(len(word)) + ',' + \ str(mirror_functions.mirrorCount(word)) + ',') # Correct prediction if (word in results): correctWords += 1 indx = results.index(word) incrementDict(word + '|' + str(indx),allRslts) outfile.write(str(indx) + ",1,\n") else: outfile.write(" ,0,\n") infile.close() outfile.close() ## Print results print "Seconds: ", time.time() - startTime print "Total words tested:", wordCount print "Total correctly predicted:", correctWords