|
|
|
@ -1,10 +1,11 @@ |
|
|
|
from string import ascii_lowercase as alphabet |
|
|
|
import codecs |
|
|
|
import hashlib |
|
|
|
import json |
|
|
|
import multiprocessing |
|
|
|
import os |
|
|
|
import pickle |
|
|
|
import re |
|
|
|
from string import ascii_lowercase as alphabet |
|
|
|
import sys |
|
|
|
#32 or 64 bit platform? |
|
|
|
if sys.maxsize > 2**32: |
|
|
|
@ -70,10 +71,21 @@ def generate_letter_frequency(word_list): |
|
|
|
if cached is None: |
|
|
|
save_freq_cache(word_list,ret) |
|
|
|
return ret |
|
|
|
|
|
|
|
def filter_wordlist(input,remaining_letters,word_list): |
|
|
|
class bool_regex: |
|
|
|
def __init__(self,expr): |
|
|
|
self.expr = expr |
|
|
|
def __call__(self,arg): |
|
|
|
return bool(self.expr.match(arg)) |
|
|
|
def filter_wordlist(input,remaining_letters,word_list,mp=True): |
|
|
|
regex = re.compile(input.replace('.','[{}]'.format(''.join(remaining_letters))) + '$') |
|
|
|
matches = map(regex.match,word_list) |
|
|
|
if mp and len(word_list) > 1000: |
|
|
|
regex = bool_regex(regex) |
|
|
|
pool = multiprocessing.Pool() |
|
|
|
matches = pool.map(regex,word_list,100_000) |
|
|
|
pool.close() |
|
|
|
pool.join() |
|
|
|
else: |
|
|
|
matches = map(regex.match,word_list) |
|
|
|
remaining_words = (group[1] for group in filter(lambda group: group[0],zip(matches,word_list))) |
|
|
|
return list(remaining_words) |
|
|
|
|
|
|
|
@ -156,7 +168,7 @@ def iterate(word_list,let_freq,prev_word = None): |
|
|
|
entered_letters.update(re.findall('[a-z]',word)) |
|
|
|
remaining_letters = (ALPHABET & set(let_freq.keys())) - entered_letters - negatives |
|
|
|
for i,word in enumerate(entered_words): |
|
|
|
remaining_possibilities = filter_wordlist(word,remaining_letters,word_list[i]) |
|
|
|
remaining_possibilities = filter_wordlist(word,remaining_letters,word_list[i],mp=True) |
|
|
|
word_list[i] = remaining_possibilities |
|
|
|
print('Matches found:', '\n'.join(multi_word(word_list,10)),sep='\n') |
|
|
|
print_likely_chars(remaining_letters,let_freq) |
|
|
|
|