From cf7a05d3dfcb01d5aa2af0de72e45aa8d8eee7b9 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Thu, 23 May 2019 01:08:05 -0500 Subject: [PATCH] Renamed cmd_loop_main.py to main.py --- cmd_loop_main.py | 13 ---------- main.py | 66 ++++++------------------------------------------ 2 files changed, 8 insertions(+), 71 deletions(-) delete mode 100644 cmd_loop_main.py diff --git a/cmd_loop_main.py b/cmd_loop_main.py deleted file mode 100644 index 0c09afd..0000000 --- a/cmd_loop_main.py +++ /dev/null @@ -1,13 +0,0 @@ -import cmd2 - - -class MainLoop(cmd2.Cmd): - """Loop for wordscape commands - - """ - - def __init__(self): - letters = None - removed = set() - - super().__init__() diff --git a/main.py b/main.py index bcdfa45..0c09afd 100755 --- a/main.py +++ b/main.py @@ -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__()