sym_spell.lookup_compound('whereis', 2)
//output: where is, 360468344, 2
However the distance should be just 1 (add a single whitespace).
# create object
initial_capacity = 83000
# maximum edit distance per dictionary precalculation
max_edit_distance_dictionary = 2
prefix_length = 7
sym_spell = SymSpell(initial_capacity, max_edit_distance_dictionary,
prefix_length)
# load dictionary
dictionary_path = os.path.join(os.path.dirname(__file__),
"frequency_dictionary_en_82_765.txt")
term_index = 0 # column of the term in the dictionary text file
count_index = 1 # column of the term frequency in the dictionary text file
if not sym_spell.load_dictionary(dictionary_path, term_index, count_index):
print("Dictionary file not found")
# lookup suggestions for multi-word input strings (supports compound
# splitting & merging)
input_term = "whereis"
# max edit distance per lookup (per single word, not per whole input string)
max_edit_distance_lookup = 2
suggestions = sym_spell.lookup_compound(input_term,
max_edit_distance_lookup)
# display suggestion term, edit distance, and term frequency
for suggestion in suggestions:
print("{}, {}, {}".format(suggestion.term, suggestion.count,
suggestion.distance))
suggestion = SuggestItem(joined_term.rstrip(),
distance_comparer.compare(
phrase, joined_term, 2 ** 31 - 1),
joined_count)