Find Spelling Corrections in Python
No matter how much time we spend writing and posting papers, blogs, etc., spelling every word correctly is still a tall task. Thankfully, NLP makes it possible to find spelling correction suggestions for any given word and quickly return those results. The Cloudmersive NLP API v2 has a Spellcheck iteration which can add this NLP functionality to your application. Let’s run through how you can use it in Python.
You can begin by installing the Python SDK using the below snippet:
pip install cloudmersive-nlp-api-clientfrom __future__ import print_function
import time
import cloudmersive_nlp_api_client
from cloudmersive_nlp_api_client.rest import ApiException
from pprint import pprint
After that, you can add in code to authorize our API key for access (this key can be obtained by making a free account on the Cloudmersive website):
# Configure API key authorization: Apikey
configuration = cloudmersive_nlp_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
For your last step, simply copy in the rest of the callback function below & you’re all set:
# create an instance of the API class
api_instance = cloudmersive_nlp_api_client.SpellcheckApi(cloudmersive_nlp_api_client.ApiClient(configuration))
value = cloudmersive_nlp_api_client.CheckWordRequest() # CheckWordRequest | Input stringtry:
# Find spelling corrections
api_response = api_instance.spellcheck_correct_json(value)
pprint(api_response)
except ApiException as e:
print("Exception when calling SpellcheckApi->spellcheck_correct_json: %s\n" % e)