Parts Of Speech is a simple tool for extracting nouns, verbs, adjectives, adverbs, etc. from text. It returns the extracted words based on the part of speech specified.
Add JitPack repository to your root build.gradle:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}Add the dependency:
dependencies {
implementation 'com.github.apiverve:partsofspeech-api:1.1.14'
}import com.apiverve.partsofspeech.PartsOfSpeechAPIClient;
import com.apiverve.partsofspeech.APIResponse;
import com.apiverve.partsofspeech.APIException;
// Initialize the client
PartsOfSpeechAPIClient client = new PartsOfSpeechAPIClient("YOUR_API_KEY");
try {
// Prepare request parameters
Map<String, Object> parameters = new HashMap<>();
parameters.put("text", "My friend from college hails from a small countryside village located at the heart of the state. During the last summer vacation, I had an opportunity to visit my friend in his village. I packed up my belongings and boarded the bus bound for the village");
parameters.put("partofspeech", "verbs");
// Execute the request
APIResponse response = client.execute(parameters);
if (response.isSuccess()) {
// Handle successful response
JSONObject data = response.getData();
System.out.println("Success: " + data.toString());
} else {
// Handle API error
System.err.println("API Error: " + response.getError());
}
} catch (APIException e) {
// Handle exception
e.printStackTrace();
}// Some APIs don't require parameters
APIResponse response = client.execute();The SDK provides detailed error handling:
try {
APIResponse response = client.execute(parameters);
if (response.isSuccess()) {
// Process success
} else {
// Handle API-level errors
System.err.println("Error: " + response.getError());
}
} catch (APIException e) {
if (e.isAuthenticationError()) {
System.err.println("Invalid API key");
} else if (e.isRateLimitError()) {
System.err.println("Rate limit exceeded");
} else if (e.isServerError()) {
System.err.println("Server error");
} else {
System.err.println("Error: " + e.getMessage());
}
}The APIResponse object provides several methods:
APIResponse response = client.execute(params);
// Check status
boolean success = response.isSuccess();
boolean error = response.isError();
// Get data
String status = response.getStatus();
String errorMsg = response.getError();
JSONObject data = response.getData();
int code = response.getCode();
// Get raw response
JSONObject raw = response.getRawResponse();For detailed API documentation, visit: https://docs.apiverve.com/ref/partsofspeech
Get your API key from https://apiverve.com
- Java 8 or higher
- Android API level 21 (Lollipop) or higher
- Documentation: https://docs.apiverve.com/ref/partsofspeech
- Issues: GitHub Issues
- Email: hello@apiverve.com
This SDK is released under the MIT License. See LICENSE for details.
APIVerve provides production-ready REST APIs for developers. Fast, reliable, and easy to integrate.