detectSentiment method
Future<DetectSentimentResponse>
detectSentiment({
- required LanguageCode languageCode,
- required String text,
Inspects text and returns an inference of the prevailing sentiment
(POSITIVE
, NEUTRAL
, MIXED
, or
NEGATIVE
).
May throw InvalidRequestException. May throw TextSizeLimitExceededException. May throw UnsupportedLanguageException. May throw InternalServerException.
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.
Parameter text
:
A UTF-8 text string. Each string must contain fewer that 5,000 bytes of
UTF-8 encoded characters.
Implementation
Future<DetectSentimentResponse> detectSentiment({
required LanguageCode languageCode,
required String text,
}) async {
ArgumentError.checkNotNull(languageCode, 'languageCode');
ArgumentError.checkNotNull(text, 'text');
_s.validateStringLength(
'text',
text,
1,
1152921504606846976,
isRequired: true,
);
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'Comprehend_20171127.DetectSentiment'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'LanguageCode': languageCode.toValue(),
'Text': text,
},
);
return DetectSentimentResponse.fromJson(jsonResponse.body);
}