Esempio n. 1
0
    def readWords(self):
        """
        Reads all the words from the file specified in self.filenames. Method
        sanitize specifies the accepted word formatting.
        """

        for index, filename in enumerate(self.filenames):
            if self.readCount > index:
                continue
            self.readCount = self.readCount + 1
            self.fh = openFile(filename)  # exits on failure

            lineno = 0
            for line in self.fh:
                self.linecount = self.linecount + 1
                lineno = lineno + 1

                words = line.split()
                if words == "":
                    continue

                for word in words:
                    newWord = self.sanitize(word)
                    if newWord:
                        self.words.append((newWord, lineno, self.filecount))
                        self.wordcount = self.wordcount + 1

            self.fh.close()
            self.filecount = self.filecount + 1  # preparation for multiple files
Esempio n. 2
0
    runtimes = []
    for i in range(0, repeats):
        word = random.choice(words)
        word = tree.lukija.sanitize(word)
        runtimes.append( boo(tree, word, 1000) )
        time.sleep(0.01)
    if not printout:
        return average(runtimes)
    else:
        print string + '%20.3f ms' %  (sum(runtimes) / repeats)


if __name__ == "__main__":
    print "Hello World"

    trieAddFile = openFile('trieAddToEmpty', 'w')
    punamustaAddFile = openFile('punamustaAddToEmpty', 'w')
    trieFindLengthFile = openFile('trieFindWordLength', 'w')
    punamustaFindLengthFile = openFile('punamustaFindWordLength', 'w')
    trieFindWordCountFile = openFile('trieFindWordCount', 'w')
    punamustaFindWordCountFile = openFile('punamustaFindWordCoun', 'w')

    lukija = WordReader(["../Material/Grimm's Fairy Tales.txt"])
    lukija.readWords()
    punamusta = RedBlack(lukija)
    trie = Trie(lukija)

    words = pickle.load( open( "randomWordList", "rb" ) ) # indexed by word len

    repeats = 100;
    runtimes = []