filyp / autocorrect

Spelling corrector in python
GNU Lesser General Public License v3.0
447 stars 79 forks source link

How to add new words for autocorrection? #24

Closed nepalprabin closed 3 years ago

nepalprabin commented 3 years ago

I want to add new words for autocorrelation. For example, I want to add strings like 'tive', 'fiue' that autocorrects to string 'five'. How can I achieve that?

filyp commented 3 years ago

We don't support hardcoding corrections like tive -> five, because that would break the correction tive -> time. When multiple corrections are possible (like with tive) autocorrect chooses the most frequent word. If some words are more frequent in the text you use, you can pass your custom frequency dictionary:

spell = Speller(nlp_data=your_dict)

your_dict should be a python dictionary containing pairs word: frequency for example five: 200. You can create this dict automatically based on some text file using:

from autocorrect.word_count import count_words
count_words('your_text.txt', 'en')

it will output this dict into word_count.json