use of com.amazonaws.services.comprehend.model.DetectEntitiesRequest in project knime-cloud by knime.
the class EntityTagger method tagEntities.
@Override
protected List<TaggedEntity> tagEntities(final Sentence sentence) {
final String textValue = sentence.getTextWithWsSuffix();
final DetectEntitiesRequest request = new DetectEntitiesRequest().withText(textValue).withLanguageCode(m_languageCode);
final DetectEntitiesResult result = m_client.detectEntities(request);
return //
result.getEntities().stream().map(//
entity -> new TaggedEntity(entity.getText(), entity.getType())).collect(Collectors.toList());
}
use of com.amazonaws.services.comprehend.model.DetectEntitiesRequest in project amplify-android by aws-amplify.
the class AWSComprehendService method fetchEntities.
private List<Entity> fetchEntities(String text, LanguageType language) throws PredictionsException {
// Skip if configuration specifies NOT entities
if (!isResourceConfigured(InterpretTextConfiguration.InterpretType.ENTITIES)) {
return null;
}
DetectEntitiesRequest request = new DetectEntitiesRequest().withText(text).withLanguageCode(language.getLanguageCode());
// Detect entities from given text via AWS Comprehend
final DetectEntitiesResult result;
try {
result = comprehend.detectEntities(request);
} catch (AmazonClientException serviceException) {
throw new PredictionsException("AWS Comprehend encountered an error while detecting entities.", serviceException, "See attached service exception for more details.");
}
// Convert AWS Comprehend's detection result to Amplify-compatible format
List<Entity> entities = new ArrayList<>();
for (com.amazonaws.services.comprehend.model.Entity comprehendEntity : result.getEntities()) {
EntityType entityType = EntityTypeAdapter.fromComprehend(comprehendEntity.getType());
Entity amplifyEntity = Entity.builder().value(entityType).confidence(comprehendEntity.getScore() * PERCENT).targetText(comprehendEntity.getText()).startIndex(comprehendEntity.getBeginOffset()).build();
entities.add(amplifyEntity);
}
return entities;
}
Aggregations