|
|
|
@ -2,15 +2,16 @@ import spellchecker |
|
|
|
import pathlib |
|
|
|
import concurrent |
|
|
|
from concurrent.futures import ThreadPoolExecutor |
|
|
|
|
|
|
|
EXECUTOR = ThreadPoolExecutor() |
|
|
|
DEFAULT = spellchecker.WordFrequency() |
|
|
|
ALTERNATE = spellchecker.WordFrequency() |
|
|
|
|
|
|
|
|
|
|
|
package_root = pathlib.Path(spellchecker.__file__) / '..' |
|
|
|
english = package_root / 'resources' / 'en.json.gz' |
|
|
|
package_root = pathlib.Path(spellchecker.__file__) / ".." |
|
|
|
english = package_root / "resources" / "en.json.gz" |
|
|
|
|
|
|
|
extra_words = pathlib.Path(__file__, '..', 'extra_words.txt') |
|
|
|
extra_words = pathlib.Path(__file__, "..", "extra_words.txt") |
|
|
|
|
|
|
|
|
|
|
|
def do_operation(bound_method, *args, **kwargs): |
|
|
|
@ -19,10 +20,10 @@ def do_operation(bound_method, *args, **kwargs): |
|
|
|
return obj |
|
|
|
|
|
|
|
|
|
|
|
default_load_future = EXECUTOR.submit( |
|
|
|
do_operation, DEFAULT.load_dictionary, english) |
|
|
|
default_load_future = EXECUTOR.submit(do_operation, DEFAULT.load_dictionary, english) |
|
|
|
alternate_load_future = EXECUTOR.submit( |
|
|
|
do_operation, ALTERNATE.load_text_file, extra_words) |
|
|
|
do_operation, ALTERNATE.load_text_file, extra_words |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
class Dictionary: |
|
|
|
@ -40,11 +41,14 @@ class Dictionary: |
|
|
|
"""Finds words that are in the dictionary""" |
|
|
|
if excludes is None: |
|
|
|
|
|
|
|
def filter_func(word): return word in self.word_frequency |
|
|
|
def filter_func(word): |
|
|
|
return word in self.word_frequency |
|
|
|
|
|
|
|
else: |
|
|
|
def filter_func( |
|
|
|
word): |
|
|
|
|
|
|
|
def filter_func(word): |
|
|
|
return word not in excludes and word in self.word_frequency |
|
|
|
|
|
|
|
return set(filter(filter_func, wordlist)) |
|
|
|
|
|
|
|
|
|
|
|
|