import itertools as it import wordlists import lev WORDS = wordlists.get_wordlist('dictionaries', wordlists.WORDLIST_URL, lengths=(6, 7, 8), predicate=str.isalpha) WORD = 'fighter' assert WORD in WORDS print len(WORDS) for w in WORDS: if lev.fast_lev(WORD, w) <= 1: print w
w1 = w1.strip() w2 = w2.strip() print "'%s'-'%s'" % (w1, w2), print lev(w1, w2), print fast_lev(w1, w2) if __name__ == '__main__': DICT_COMPONENT = 'dictionaries' try: DICTIONARY = sys.argv[1] except IndexError: DICTIONARY = path.join(os.getcwd(), DICT_COMPONENT) WORDLIST_URL = 'ftp://ftp.ox.ac.uk/pub/wordlists/american/dic-0294.tar.gz' start = time.clock() wordlist = wordlists.get_wordlist(DICTIONARY, WORDLIST_URL, 5, lengths=[3, 5, 7, 8, 10, 11, 13, 14, 20]) print 'Got wordlist in %s seconds.' % (time.clock() - start) print '%d words available.' % len(wordlist) start = time.clock() for w1, w2 in it.product(wordlist, wordlist): fast_lev(w1, w2) print 'Computed %d fast_lev in %s seconds.' % (len(wordlist)**2, time.clock() - start) start = time.clock() for w1, w2 in it.product(wordlist, wordlist): functional_lev(w1, w2) print 'Computed %d functional_lev in %s seconds.' % (len(wordlist)**2, time.clock() - start)