Get Words from a String in Java: NLP API

Cloudmersive
2 min readApr 11, 2022

--

The field of Natural Language Processing is all about helping our dutifully rule-based accomplices (computers) understand the relative chaos of human languages. Segmentation is one of the key processes to accomplish this: it allows computers to break down input strings of human language into its individual words, which through NLP training can lead computers to a better understanding of grammar, semantics, and more.

Our Sentence Segmentation API will divide each word from an input text string by separating them with commas, as such:

Sample Response Body for input string: “What happened here”

You can incorporate this API easily into your application using code in Java from our API console below, and do so freely by creating a free account on our website (www.cloudmersive.com) which will provide a limit of 800 API calls per month.

For Java SDK installation with Maven, start by adding a reference to the pom.xml repository:

<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>

Then complete the process by copying in the below, supplying your API key and inputs where indicated in the documentation:

// 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.WordsApi;
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");
WordsApi apiInstance = new WordsApi();
String input = "input_example"; // String | Input string
try {
String result = apiInstance.wordsGetWordsString(input);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling WordsApi#wordsGetWordsString");
e.printStackTrace();
}

Now you’re all set. Check our other articles or visit our API console page for dozens of additional NLP API options available to integrate for free.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet