2 changed files with 8 additions and 71 deletions
-
13cmd_loop_main.py
-
66main.py
@ -1,13 +0,0 @@ |
|||
import cmd2 |
|||
|
|||
|
|||
class MainLoop(cmd2.Cmd): |
|||
"""Loop for wordscape commands |
|||
|
|||
""" |
|||
|
|||
def __init__(self): |
|||
letters = None |
|||
removed = set() |
|||
|
|||
super().__init__() |
|||
@ -1,63 +1,13 @@ |
|||
#!/usr/bin/python |
|||
import re |
|||
import itertools |
|||
from spellchecker import SpellChecker |
|||
from concurrent.futures import ThreadPoolExecutor |
|||
POOL = ThreadPoolExecutor() |
|||
SPELL = None |
|||
import cmd2 |
|||
|
|||
|
|||
def init_spell_checker(): |
|||
global SPELL |
|||
SPELL = SpellChecker() |
|||
SPELL.word_frequency.load_text_file('extra_words.txt') |
|||
class MainLoop(cmd2.Cmd): |
|||
"""Loop for wordscape commands |
|||
|
|||
""" |
|||
|
|||
future = POOL.submit(init_spell_checker) |
|||
def __init__(self): |
|||
letters = None |
|||
removed = set() |
|||
|
|||
|
|||
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 |
|||
super().__init__() |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue