use of com.amazonaws.services.comprehend.model.DetectSyntaxResult in project knime-cloud by knime.
the class SyntaxTagger method tagEntities.
@Override
protected List<TaggedEntity> tagEntities(final Sentence sentence) {
final String textValue = sentence.getTextWithWsSuffix();
// Create the delete syntax request
final DetectSyntaxRequest request = new DetectSyntaxRequest().withText(textValue).withLanguageCode(m_languageCode);
final DetectSyntaxResult result = m_client.detectSyntax(request);
return //
result.getSyntaxTokens().stream().map(//
token -> new TaggedEntity(token.getText(), token.getPartOfSpeech().getTag())).collect(Collectors.toList());
}
use of com.amazonaws.services.comprehend.model.DetectSyntaxResult in project amplify-android by aws-amplify.
the class AWSComprehendService method fetchSyntax.
private List<Syntax> fetchSyntax(String text, LanguageType language) throws PredictionsException {
// Skip if configuration specifies NOT syntax
if (!isResourceConfigured(InterpretTextConfiguration.InterpretType.SYNTAX)) {
return null;
}
DetectSyntaxRequest request = new DetectSyntaxRequest().withText(text).withLanguageCode(language.getLanguageCode());
// Detect syntax from given text via AWS Comprehend
final DetectSyntaxResult result;
try {
result = comprehend.detectSyntax(request);
} catch (AmazonClientException serviceException) {
throw new PredictionsException("AWS Comprehend encountered an error while detecting syntax.", serviceException, "See attached service exception for more details.");
}
// Convert AWS Comprehend's detection result to Amplify-compatible format
List<Syntax> syntaxTokens = new ArrayList<>();
for (com.amazonaws.services.comprehend.model.SyntaxToken comprehendSyntax : result.getSyntaxTokens()) {
PartOfSpeechTag comprehendPartOfSpeech = comprehendSyntax.getPartOfSpeech();
SpeechType partOfSpeech = SpeechTypeAdapter.fromComprehend(comprehendPartOfSpeech.getTag());
Syntax amplifySyntax = Syntax.builder().id(comprehendSyntax.getTokenId().toString()).value(partOfSpeech).confidence(comprehendPartOfSpeech.getScore() * PERCENT).targetText(comprehendSyntax.getText()).startIndex(comprehendSyntax.getBeginOffset()).build();
syntaxTokens.add(amplifySyntax);
}
return syntaxTokens;
}
Aggregations