How to Rephrase or Paraphrase Text Using AI in Java
Automatically rephrase or paraphrase input English text by leveraging Deep Learning AI and Neural Natural Language Processing technology.
Join the DZone community and get the full member experience.
Join For FreeIf you’ve ever been stuck for hours wondering how to translate source material into your own personalized content, we feel your pain. Writer’s block is a condition that affects almost all of us at some point in our lives and can be very difficult to escape. Fortunately, the age of technology has developed some incredibly useful tools to solve even this persistent problem. Whether the goal is to refresh a business document, rephrase a blog post, or paraphrase for a term paper, our Rephrase/Paraphrase API will be able to provide the necessary boost to overcome the internal obstacles we construct in our minds.
Leveraging Deep Learning and Natural Language Processing AI technology, this creative solution will take any input English text and create 1-10 rephrased outputs of the original sentence. The function is designed to preserve the original semantic meaning, so while the wording will change, the core message remains the same.
To use this API, we will need to enter the target sentence/text in English, then call the function. It is important to note that the number of calls the API will consume is in direct relation to how many rephrasing options are generated per sentence. For example, if you enter one sentence and receive two options back, the function will consume 2-3 calls; the average is 1-2 calls consumed per generated option, per sentence.
To begin the process, we can install the SDK using Maven or Gradle. For this example we will be using Maven, so we will add a reference to the repository in pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then, add a reference to the dependency:
xxxxxxxxxx
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.54</version>
</dependency>
</dependencies>
At this point, we are ready to add the imports and call the function using the following code:
xxxxxxxxxx
// 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.RephraseApi;
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");
RephraseApi apiInstance = new RephraseApi();
RephraseRequest input = new RephraseRequest(); // RephraseRequest | Input rephrase request
try {
RephraseResponse result = apiInstance.rephraseTranslateDeuToEng(input);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling RephraseApi#rephraseTranslateDeuToEng");
e.printStackTrace();
}
For a successful result, you will need to ensure the following parameters have been input correctly:
- Rephrase request – this includes the text to translate and target rephrasing count
- API key – this can be retrieved by creating an account on the Cloudmersive website; the free plan includes 800 calls/month across our library of APIs
And that's all, folks! We hope this innovative language tool will be helpful as you continue to craft and adapt stories to meet requirements.
Opinions expressed by DZone contributors are their own.
Comments