How to find Spelling Corrections for a Word in Python with NLP

I don’t think anybody really wants to deal with manually setting up a spell correction system. That’s fine, because I have a lovely API that will be able to give us exactly this functionality with a bare minimum of effort required.

Pip install will get us started with out client installation:

pip install git+https://github.com/Cloudmersive/Cloudmersive.APIClient.Python.NLP.git

Now we just need to set up spell_check_correct_json, which is going to take in a word as a string and provide a list of different spelling suggestions. This is going to look a bit like this:

from __future__ import print_functionimport timeimport cloudmersive_nlp_api_clientfrom cloudmersive_nlp_api_client.rest import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_nlp_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_nlp_api_client.SpellCheckApi(cloudmersive_nlp_api_client.ApiClient(configuration))value = 'value_example' # str | Input stringtry:# Find spelling correctionsapi_response = api_instance.spell_check_correct_json(value)pprint(api_response)except ApiException as e:print("Exception when calling SpellCheckApi->spell_check_correct_json: %s\n" % e)

Done!

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store