Check if Sentence is Spelled Correctly in Python
Cloudmersive’s NLP API v2 allows you to easily add Spellcheck functionality to your application — either for an individual word, or for an entire sentence string. In this article, we’re going to walk through how you can take advantage of the latter iteration in Python and empower your application to check if a sentence is spelled correctly & return a JSON result.
The first step is to copy in the Python SDK installation command:
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
Now, you can copy in this next snippet which will authorize your Cloudmersive API key (you can get your API key by creating 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 the final step, all that’s left is to copy in the remainder of the callback function:
# 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.CheckSentenceRequest() # CheckSentenceRequest | Input sentencetry:
# Check if sentence is spelled correctly
api_response = api_instance.spellcheck_check_sentence(value)
pprint(api_response)
except ApiException as e:
print("Exception when calling SpellcheckApi->spellcheck_check_sentence: %s\n" % e)