detectEntities method

Future<DetectEntitiesResponse> detectEntities({
  1. required String text,
  2. String? endpointArn,
  3. LanguageCode? languageCode,
})

Inspects text for named entities, and returns information about them. For more information, about named entities, see how-entities.

May throw InvalidRequestException. May throw ResourceUnavailableException. May throw TextSizeLimitExceededException. May throw UnsupportedLanguageException. May throw InternalServerException.

Parameter text : A UTF-8 text string. Each string must contain fewer that 5,000 bytes of UTF-8 encoded characters.

Parameter endpointArn : The Amazon Resource Name of an endpoint that is associated with a custom entity recognition model. Provide an endpoint if you want to detect entities by using your own custom model instead of the default model that is used by Amazon Comprehend.

If you specify an endpoint, Amazon Comprehend uses the language of your custom model, and it ignores any language code that you provide in your request.

Parameter languageCode : The language of the input documents. You can specify any of the primary languages supported by Amazon Comprehend. All documents must be in the same language.

If your request includes the endpoint for a custom entity recognition model, Amazon Comprehend uses the language of your custom model, and it ignores any language code that you specify here.

Implementation

Future<DetectEntitiesResponse> detectEntities({
  required String text,
  String? endpointArn,
  LanguageCode? languageCode,
}) async {
  ArgumentError.checkNotNull(text, 'text');
  _s.validateStringLength(
    'text',
    text,
    1,
    1152921504606846976,
    isRequired: true,
  );
  _s.validateStringLength(
    'endpointArn',
    endpointArn,
    0,
    256,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Comprehend_20171127.DetectEntities'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'Text': text,
      if (endpointArn != null) 'EndpointArn': endpointArn,
      if (languageCode != null) 'LanguageCode': languageCode.toValue(),
    },
  );

  return DetectEntitiesResponse.fromJson(jsonResponse.body);
}