示例#1
0
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
示例#2
0
def printStats():
        length = {}
        mirrors = {}
        
        for cur in corpus:
                incrementInDict(len(cur),length)
                incrementInDict(mirror_functions.mirrorCount(cur),mirrors)

        length = sorted(length.iteritems(), key=operator.itemgetter(0))
        mirrors = sorted(mirrors.iteritems(), key=operator.itemgetter(0))
        
        print " [Total Unique Words:", str(len(corpus)), "]"
        #print " ======================================"
        print " Length of Word\t Unique Occurrences"
        print " --------------\t ------------------"
        for cur in length:
                print "\t",cur[0], "\t\t", cur[1]

        print "\n # of Mirrors\t Unique Occurrences"
        print " --------------\t -------------------"
        for cur in mirrors:
                print "\t", cur[0], "\t\t", cur[1]