简体   繁体   中英

Are there any auto-correct/auto-complete libraries for Python?

I'm making a chatbot and would like users to spell correctly to make everything on the back end easier. Are there any autocorrect and/or autocomplete libraries out there?

I'm guessing you are making an integration for something like Slack. Using an autocorrect feature might be very dangerous as you could "correct" something from a neutral state to a destructive state. Styling your inputs to be simple and but descriptive would be a lot safer. You could also implement a "did you mean" feature with some simple character counting that would let the user see that they messed up, and offer then the option to correctly input the right key phrase.

Input:

derete file1.jpg

check possible keyword position 0 with existing keyword set...add/remove/delete

0/6 match for add

2/6 match for remove

5/6 match for known keyword 'delete', picking 'delete' as suggestion

Output:

Did you mean delete file1.jpg ?

I think that would be safer and not too painful to code. Just have a function that iterates through each character and increments a counter if the character matches. It's FAR from perfect but would be a step in the right direction if you wanted to make it manually.

What gman said in the other answer is a good idea, sometimes trying to forcefully auto-correct might "correct" right words that fit in the context but are not in the auto-correct database and substitute them for right words that don't make sense in the context.

A python auto-complete lib: https://github.com/phatpiglet/autocorrect

See also: https://github.com/mattalcock/blog/blob/master/2012/12/5/python-spell-checker.rst

Try jamspell - it works pretty well for automatic spelling correction (it consider context):

import jamspell

corrector = jamspell.TSpellCorrector()
corrector.LoadLangModel('en.bin')

corrector.FixFragment('Some sentnec with error')
# u'Some sentence with error'

However it can sometimes break correct words (less than 1% cases, according to their documentation)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM