use of software.amazon.awssdk.services.comprehend.model.ComprehendException in project aws-doc-sdk-examples by awsdocs.
the class DetectSentiment method detectSentiments.
// snippet-start:[comprehend.java2.detect_sentiment.main]
public static void detectSentiments(ComprehendClient comClient, String text) {
try {
DetectSentimentRequest detectSentimentRequest = DetectSentimentRequest.builder().text(text).languageCode("en").build();
DetectSentimentResponse detectSentimentResult = comClient.detectSentiment(detectSentimentRequest);
System.out.println("The Neutral value is " + detectSentimentResult.sentimentScore().neutral());
} catch (ComprehendException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.comprehend.model.ComprehendException in project aws-doc-sdk-examples by awsdocs.
the class DocumentClassifierDemo method createDocumentClassifier.
// snippet-start:[comprehend.java2.classifier.main]
public static void createDocumentClassifier(ComprehendClient comClient, String dataAccessRoleArn, String s3Uri, String documentClassifierName) {
try {
DocumentClassifierInputDataConfig config = DocumentClassifierInputDataConfig.builder().s3Uri(s3Uri).build();
CreateDocumentClassifierRequest createDocumentClassifierRequest = CreateDocumentClassifierRequest.builder().documentClassifierName(documentClassifierName).dataAccessRoleArn(dataAccessRoleArn).languageCode("en").inputDataConfig(config).build();
CreateDocumentClassifierResponse createDocumentClassifierResult = comClient.createDocumentClassifier(createDocumentClassifierRequest);
String documentClassifierArn = createDocumentClassifierResult.documentClassifierArn();
System.out.println("Document Classifier ARN: " + documentClassifierArn);
} catch (ComprehendException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.comprehend.model.ComprehendException in project aws-doc-sdk-examples by awsdocs.
the class DetectEntities method detectAllEntities.
// snippet-start:[comprehend.java2.detect_entities.main]
public static void detectAllEntities(ComprehendClient comClient, String text) {
try {
DetectEntitiesRequest detectEntitiesRequest = DetectEntitiesRequest.builder().text(text).languageCode("en").build();
DetectEntitiesResponse detectEntitiesResult = comClient.detectEntities(detectEntitiesRequest);
List<Entity> entList = detectEntitiesResult.entities();
Iterator<Entity> lanIterator = entList.iterator();
while (lanIterator.hasNext()) {
Entity entity = lanIterator.next();
System.out.println("Entity text is " + entity.text());
}
} catch (ComprehendException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.comprehend.model.ComprehendException in project aws-doc-sdk-examples by awsdocs.
the class DetectSyntax method detectAllSyntax.
// snippet-start:[comprehend.java2.detect_syntax.main]
public static void detectAllSyntax(ComprehendClient comClient, String text) {
try {
DetectSyntaxRequest detectSyntaxRequest = DetectSyntaxRequest.builder().text(text).languageCode("en").build();
DetectSyntaxResponse detectSyntaxResult = comClient.detectSyntax(detectSyntaxRequest);
List<SyntaxToken> syntaxTokens = detectSyntaxResult.syntaxTokens();
Iterator<SyntaxToken> syntaxIterator = syntaxTokens.iterator();
while (syntaxIterator.hasNext()) {
SyntaxToken token = syntaxIterator.next();
System.out.println("Language is " + token.text());
System.out.println("Part of speech is " + token.partOfSpeech().tagAsString());
}
} catch (ComprehendException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.comprehend.model.ComprehendException in project aws-doc-sdk-examples by awsdocs.
the class LexService method DetectLanguage.
private String DetectLanguage(String text) {
Region region = Region.US_EAST_1;
ComprehendClient comClient = ComprehendClient.builder().region(region).build();
try {
String lanCode = "";
DetectDominantLanguageRequest request = DetectDominantLanguageRequest.builder().text(text).build();
DetectDominantLanguageResponse resp = comClient.detectDominantLanguage(request);
List<DominantLanguage> allLanList = resp.languages();
Iterator<DominantLanguage> lanIterator = allLanList.iterator();
while (lanIterator.hasNext()) {
DominantLanguage lang = lanIterator.next();
lanCode = lang.languageCode();
}
return lanCode;
} catch (ComprehendException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return "";
}
Aggregations