mammothb / symspellpy

Python port of SymSpell: 1 million times faster spelling correction & fuzzy search through Symmetric Delete spelling correction algorithm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support python native dictionary object in `load_dictionary()`

katkamrachanaso opened this issue · comments

Is there a way to pass a Python dictionary object like following:

dict_obj = {'test': 100, "testing": 200, "test-again": 300}

Something like: sym_spell.load_dictionary(dict_obj)
instead of txt file word-frequency

commented

I have added a wrapper for Python dictionary objects on the dev branch which can used with load_dictionary_stream like

from symspellpy import SymSpell
from symspellpy.helpers import DictIO

sym_spell = SymSpell(max_dictionary_edit_distance=2, prefix_length=7)
dict_obj = {"test": 100, "testing": 200, "test-again": 300}
dict_stream = DictIO(dict_obj)

sym_spell.load_dictionary_stream(dict_stream, 0, 1)

Would something like this match your needs?

Yes, that is definitely helpful. I will test this. Thank you!