How to Check if a Sentence is Spelled Correctly using Java: NLP API

Cloudmersive
2 min readApr 8, 2022

--

Our Sentence Spellcheck API will analyze each word within an input sentence and identify whether the words are spelled correctly. Details about each word including their index, start position & end position will also be provided.

Easily take advantage of this API in Java using code provided below or visit our API console page to find code available in 12 additional programming languages.

To start Java SDK installation with Maven, first add a reference to the repository in pom.xml:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

After that, add one to the dependency in pom.xml:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

Almost done — just add the import classes and call the function:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.SpellcheckApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");
SpellcheckApi apiInstance = new SpellcheckApi();
CheckSentenceRequest value = new CheckSentenceRequest(); // CheckSentenceRequest | Input sentence
try {
CheckSentenceResponse result = apiInstance.spellcheckCheckSentence(value);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling SpellcheckApi#spellcheckCheckSentence");
e.printStackTrace();
}

Make sure to add your Cloudmersive API key where indicated in the documentation, and you’re all set to go.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet