How to get Component Words in an Input String using Java: NLP API

Cloudmersive
1 min readApr 8, 2022

--

Take advantage of our NLP Sentence Segmentation API to easily break input sentences down into their component words and get details including each word’s start position and end position within the sentence. To incorporate this API using Java, follow steps below (SDK installation with Maven).

First add a reference to the pom.xml repository:

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

Next add one to the dependency:

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

To finish out, 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.SegmentationApi;
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");
SegmentationApi apiInstance = new SegmentationApi();
GetWordsRequest input = new GetWordsRequest(); // GetWordsRequest | String to process
try {
GetWordsResponse result = apiInstance.segmentationGetWords(input);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling SegmentationApi#segmentationGetWords");
e.printStackTrace();
}

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet