Skip to content

Instantly share code, notes, and snippets.

@maxgr0
Last active March 30, 2020 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxgr0/9ad39d6daba60cdf62d50013b71883f5 to your computer and use it in GitHub Desktop.
Save maxgr0/9ad39d6daba60cdf62d50013b71883f5 to your computer and use it in GitHub Desktop.
import { ComprehendClient, DetectDominantLanguageCommand, DetectEntitiesCommand } from '@aws-sdk/client-comprehend';
import { Comprehend } from 'aws-sdk';
const comprehendClientv3 = new ComprehendClient(Container.get(ConfigurationProviderService).comprehend);
const comprehendClientv2 = new Comprehend(Container.get(ConfigurationProviderService).comprehend);
const text = 'Bob lives in Seattle. He is a software engineer at Amazon.'; //the example text from aws docs
try{
const result = await this.comprehendClientv2.detectDominantLanguage({Text: text}).promise();
console.log('result v2', result);
}catch(reject){
console.log('reject', reject);
}
try{
const command = new DetectDominantLanguageCommand({Text: text});
const result = await this.comprehendClientv3.send(command);
console.log('result v3', result);
}catch(reject){
console.log('reject', reject);
}
//result v2:
{ Languages: [ { LanguageCode: 'en', Score: 0.9909641146659851 } ] }
//result v3:
Error: com.amazonaws.comprehend#ValidationException
at deserializeAws_json1_1DetectDominantLanguageCommandError (/Users/maxgr/Documents/example/node_modules/@aws-sdk/client-comprehend/protocols/Aws_json1_1.ts:3501:39)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
__type: 'com.amazonaws.comprehend#ValidationException',
'$fault': 'client',
'$metadata': {
httpStatusCode: 400,
httpHeaders: {
'x-amzn-requestid': '1d8398cd-6ee2-45cf-9064-679b8418e749',
'content-type': 'application/x-amz-json-1.1',
'content-length': '148',
date: 'Mon, 30 Mar 2020 15:21:09 GMT',
connection: 'close'
},
requestId: '1d8398cd-6ee2-45cf-9064-679b8418e749',
retries: 0,
totalRetryDelay: 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment