Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading JSON files #155

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions symspellpy/symspellpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,26 @@ def load_bigram_dictionary(
infile, term_index, count_index, separator
)

def load_json(self, corpus: Dict[str, int]) -> None:
"""Loads dictionary data from a JSON object.

Args:
corpus: A dictionary where keys are words and values are their frequencies.
"""
self._words = corpus
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bypasses create_dictionary_entry which contains logic to handle only adding to _words if it reaches above the count_threshold.

create_dictionary_entry should be used so that the behavior of loading a dictionary from .txt or .json file is consistent

self._max_length = max(map(len, self._words.keys()), default=0)

# Use a dictionary to collect all deletes first
deletes_dict = defaultdict(list)
for key in self._words:
for delete in self._edits_prefix(key):
deletes_dict[delete].append(key)

# Update self._deletes in one go
self._deletes = deletes_dict
return True


def load_dictionary(
self,
corpus: Union[Path, str],
Expand Down