You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.7 KiB
63 lines
1.7 KiB
#!/usr/bin/python
|
|
import re
|
|
import itertools
|
|
from spellchecker import SpellChecker
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
POOL = ThreadPoolExecutor()
|
|
SPELL = None
|
|
|
|
|
|
def init_spell_checker():
|
|
global SPELL
|
|
SPELL = SpellChecker()
|
|
SPELL.word_frequency.load_text_file('extra_words.txt')
|
|
|
|
|
|
future = POOL.submit(init_spell_checker)
|
|
|
|
|
|
def canidates(letters, min=2):
|
|
pos = []
|
|
for length in range(min, len(letters)+1):
|
|
for comb in itertools.combinations(letters, length):
|
|
for perm in itertools.permutations(comb):
|
|
word = ''.join(perm)
|
|
pos.append(word)
|
|
return set(SPELL.known(pos))
|
|
|
|
|
|
def filter_pos(pos, regex):
|
|
pat = re.compile(regex + '$')
|
|
return set(filter(pat.match, pos))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
while True:
|
|
letters = input('Enter letters: ')
|
|
if letters == ":quit:":
|
|
break
|
|
if SPELL is None:
|
|
future.result()
|
|
pos = canidates(letters)
|
|
inp = None
|
|
guessed = set()
|
|
while inp not in (":quit:", ":new:"):
|
|
if inp == ":enter:":
|
|
inp = None
|
|
while inp != ":done:":
|
|
if inp is not None:
|
|
guessed.add(inp)
|
|
inp = input("Enter guessed word, :done: to exit: ")
|
|
elif inp is not None:
|
|
fpos = filter_pos(pos, inp)
|
|
for word in fpos-guessed:
|
|
print('>>>', word)
|
|
print('Letters: ', ','.join(letters))
|
|
prompt = """\
|
|
Enter pattern,
|
|
':new:' for new letters,
|
|
':enter:' to fill in guessed words, or
|
|
':quit:' to exit: """
|
|
inp = input(prompt)
|
|
if inp == ":quit:":
|
|
break
|