def __init__(self): self.autoComplete = autocomplete_factory(content_files={ 'words': { 'filepath': 'resources/words.json', 'compress': True } })
def init_ac_fac(): cfg = settings['cfg'] # with open(cfg['UNIGRAM_FILE_FULL'], 'r') as f: # settings['ngrams'].update(json.load(f)) # with open(cfg['BIGRAM_FILE_FULL'], 'r') as f: # settings['ngrams'].update(json.load(f)) # with open(cfg['TRIGRAM_FILE'], 'r') as f: # settings['ngrams'].update(json.load(f)) # with open('res/uni_bi_ngrams.json', 'w') as f: # json.dump(settings['ngrams'],f) # with open(cfg[cfg['AC_DIC']], 'r') as f: settings['unigram'].update(json.load(f)) settings['unigram']['walid magdy'] = [{}, "", 10000] settings['unigram']['walid'] = [{}, "", 10000] settings['unigram']['magdy'] = [{}, "", 10000] with open(cfg[cfg['AC_DIC']], 'w') as f: json.dump(settings['unigram'], f) content_files = { 'words': { 'filepath': cfg[cfg['AC_DIC']], 'compress': True # means compress the graph data in memory } } autocomplete = autocomplete_factory(content_files=content_files) ac = lambda word, s: autocomplete.search(word, size=s) return ac
from fast_autocomplete import autocomplete_factory content_files = { 'words': { 'filepath': 'count.json', 'compress': True # means compress the graph data in memory } } autocomplete = autocomplete_factory(content_files=content_files) def wpredict(inp,x): return(autocomplete.search(word=inp,size=x))
import os import pytest from fast_autocomplete import autocomplete_factory, AutoComplete current_dir = os.path.dirname(os.path.abspath(__file__)) fixture_dir = os.path.join(current_dir, 'fixtures') content_files = { 'words': { 'filepath': os.path.join(fixture_dir, 'sample_words.json'), 'compress': True # means compress the graph data in memory } } autocomplete = autocomplete_factory(content_files=content_files) class AutoCompleteIgnoreCount(AutoComplete): SHOULD_INCLUDE_COUNT = False autocomplete_ignore_count = autocomplete_factory(content_files=content_files, module=AutoCompleteIgnoreCount) class TestLoader: @pytest.mark.parametrize('word, expected_result, expected_unsorted_result', [ ('acu', [['acura'], ['acura mdx'], ['acura rdx']], [['acura'], ['acura rlx'], ['acura rdx']]), ])
def __init__(self, distance: int = 3, size: int = 15): self._distance = distance self._size = size self._autocomplete = autocomplete_factory( content_files=self._get_content_files())