0

I am attempting to load a personal word list dictionary to complete spellchecks and hope to have an output list displaying suggested probability percentages like those from Textblob.

Here is my base code for checks:

#!pip install pyenchant
#spell-checker.py
import enchant
import sys

#load the personal word list dictionary
toppings_dict = enchant.request_pwl_dict("toppings_list.txt")

"""
toppings_list.txt:
corn
cornmeal
cucumber
pickles
"""

suggestion_dict = {}

def spck(input_topping_word):
    #check if the word exists in the dictionary
    word_exists = toppings_dict.check(input_topping_word)

    if not word_exists:
        #get suggestions for the input word
        suggestions = toppings_dict.suggest(input_topping_word)
        if suggestions:
            suggestion_dict[input_topping_word] = suggestions
file = open("new_entries.txt", "r")

"""

new_entries.txt:
pickers
picklers
cucumners
curcumin
corny
corm
corn
cucumber
pickles
picklez
cornmeat
cornml
"""
contents = file.read()
spck_list = contents.split("\n")
for word_sp in spck_list:
    spck(word_sp)
#view list of suggestions
suggestion_dict

Here is what the output currently looks like:

#Output:
"""
{'pickers': ['pickles'],
 'picklers': ['pickles'],
 'cucumners': ['cucumber'],
 'corny': ['corn'],
 'corm': ['corn'],
 'picklez': ['pickles'],
 'cornmeat': ['cornmeal'],
 'cornml': ['cornmeal', 'corn']}
"""

However, I noticed in an example (from Dipanjan Sarkar's book) that Textblob can present spell-check suggestions with percentages.

#Textblob Code:

from textblob import Word
w = Word('flaot')
w.spellcheck() 


#Output [('flat', 0.85), ('float', 0.15)]

Is there a way to use pyenchant to provide an output list of suggested matches containing probability percentages like those from Textblob? Or is there a way to have Textblob list as much detail as pyenchant?

0 Answers0