{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Comprehend.BatchDetectSentiment
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Inspects a batch of documents and returns an inference of the prevailing
-- sentiment, @POSITIVE@, @NEUTRAL@, @MIXED@, or @NEGATIVE@, in each one.
module Amazonka.Comprehend.BatchDetectSentiment
  ( -- * Creating a Request
    BatchDetectSentiment (..),
    newBatchDetectSentiment,

    -- * Request Lenses
    batchDetectSentiment_textList,
    batchDetectSentiment_languageCode,

    -- * Destructuring the Response
    BatchDetectSentimentResponse (..),
    newBatchDetectSentimentResponse,

    -- * Response Lenses
    batchDetectSentimentResponse_httpStatus,
    batchDetectSentimentResponse_resultList,
    batchDetectSentimentResponse_errorList,
  )
where

import Amazonka.Comprehend.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newBatchDetectSentiment' smart constructor.
data BatchDetectSentiment = BatchDetectSentiment'
  { -- | A list containing the UTF-8 encoded text of the input documents. The
    -- list can contain a maximum of 25 documents. The maximum size of each
    -- document is 5 KB.
    --
    -- Amazon Comprehend performs real-time sentiment analysis on the first 500
    -- characters of the input text and ignores any additional text in the
    -- input.
    BatchDetectSentiment -> Sensitive (NonEmpty (Sensitive Text))
textList :: Data.Sensitive (Prelude.NonEmpty (Data.Sensitive Prelude.Text)),
    -- | 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.
    BatchDetectSentiment -> LanguageCode
languageCode :: LanguageCode
  }
  deriving (BatchDetectSentiment -> BatchDetectSentiment -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchDetectSentiment -> BatchDetectSentiment -> Bool
$c/= :: BatchDetectSentiment -> BatchDetectSentiment -> Bool
== :: BatchDetectSentiment -> BatchDetectSentiment -> Bool
$c== :: BatchDetectSentiment -> BatchDetectSentiment -> Bool
Prelude.Eq, Int -> BatchDetectSentiment -> ShowS
[BatchDetectSentiment] -> ShowS
BatchDetectSentiment -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchDetectSentiment] -> ShowS
$cshowList :: [BatchDetectSentiment] -> ShowS
show :: BatchDetectSentiment -> String
$cshow :: BatchDetectSentiment -> String
showsPrec :: Int -> BatchDetectSentiment -> ShowS
$cshowsPrec :: Int -> BatchDetectSentiment -> ShowS
Prelude.Show, forall x. Rep BatchDetectSentiment x -> BatchDetectSentiment
forall x. BatchDetectSentiment -> Rep BatchDetectSentiment x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchDetectSentiment x -> BatchDetectSentiment
$cfrom :: forall x. BatchDetectSentiment -> Rep BatchDetectSentiment x
Prelude.Generic)

-- |
-- Create a value of 'BatchDetectSentiment' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'textList', 'batchDetectSentiment_textList' - A list containing the UTF-8 encoded text of the input documents. The
-- list can contain a maximum of 25 documents. The maximum size of each
-- document is 5 KB.
--
-- Amazon Comprehend performs real-time sentiment analysis on the first 500
-- characters of the input text and ignores any additional text in the
-- input.
--
-- 'languageCode', 'batchDetectSentiment_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.
newBatchDetectSentiment ::
  -- | 'textList'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'languageCode'
  LanguageCode ->
  BatchDetectSentiment
newBatchDetectSentiment :: NonEmpty Text -> LanguageCode -> BatchDetectSentiment
newBatchDetectSentiment NonEmpty Text
pTextList_ LanguageCode
pLanguageCode_ =
  BatchDetectSentiment'
    { $sel:textList:BatchDetectSentiment' :: Sensitive (NonEmpty (Sensitive Text))
textList =
        forall a. Iso' (Sensitive a) a
Data._Sensitive
          forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced
          forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pTextList_,
      $sel:languageCode:BatchDetectSentiment' :: LanguageCode
languageCode = LanguageCode
pLanguageCode_
    }

-- | A list containing the UTF-8 encoded text of the input documents. The
-- list can contain a maximum of 25 documents. The maximum size of each
-- document is 5 KB.
--
-- Amazon Comprehend performs real-time sentiment analysis on the first 500
-- characters of the input text and ignores any additional text in the
-- input.
batchDetectSentiment_textList :: Lens.Lens' BatchDetectSentiment (Prelude.NonEmpty Prelude.Text)
batchDetectSentiment_textList :: Lens' BatchDetectSentiment (NonEmpty Text)
batchDetectSentiment_textList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchDetectSentiment' {Sensitive (NonEmpty (Sensitive Text))
textList :: Sensitive (NonEmpty (Sensitive Text))
$sel:textList:BatchDetectSentiment' :: BatchDetectSentiment -> Sensitive (NonEmpty (Sensitive Text))
textList} -> Sensitive (NonEmpty (Sensitive Text))
textList) (\s :: BatchDetectSentiment
s@BatchDetectSentiment' {} Sensitive (NonEmpty (Sensitive Text))
a -> BatchDetectSentiment
s {$sel:textList:BatchDetectSentiment' :: Sensitive (NonEmpty (Sensitive Text))
textList = Sensitive (NonEmpty (Sensitive Text))
a} :: BatchDetectSentiment) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | 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.
batchDetectSentiment_languageCode :: Lens.Lens' BatchDetectSentiment LanguageCode
batchDetectSentiment_languageCode :: Lens' BatchDetectSentiment LanguageCode
batchDetectSentiment_languageCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchDetectSentiment' {LanguageCode
languageCode :: LanguageCode
$sel:languageCode:BatchDetectSentiment' :: BatchDetectSentiment -> LanguageCode
languageCode} -> LanguageCode
languageCode) (\s :: BatchDetectSentiment
s@BatchDetectSentiment' {} LanguageCode
a -> BatchDetectSentiment
s {$sel:languageCode:BatchDetectSentiment' :: LanguageCode
languageCode = LanguageCode
a} :: BatchDetectSentiment)

instance Core.AWSRequest BatchDetectSentiment where
  type
    AWSResponse BatchDetectSentiment =
      BatchDetectSentimentResponse
  request :: (Service -> Service)
-> BatchDetectSentiment -> Request BatchDetectSentiment
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy BatchDetectSentiment
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BatchDetectSentiment)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int
-> [BatchDetectSentimentItemResult]
-> [BatchItemError]
-> BatchDetectSentimentResponse
BatchDetectSentimentResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ResultList" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"ErrorList" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable BatchDetectSentiment where
  hashWithSalt :: Int -> BatchDetectSentiment -> Int
hashWithSalt Int
_salt BatchDetectSentiment' {Sensitive (NonEmpty (Sensitive Text))
LanguageCode
languageCode :: LanguageCode
textList :: Sensitive (NonEmpty (Sensitive Text))
$sel:languageCode:BatchDetectSentiment' :: BatchDetectSentiment -> LanguageCode
$sel:textList:BatchDetectSentiment' :: BatchDetectSentiment -> Sensitive (NonEmpty (Sensitive Text))
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive (NonEmpty (Sensitive Text))
textList
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` LanguageCode
languageCode

instance Prelude.NFData BatchDetectSentiment where
  rnf :: BatchDetectSentiment -> ()
rnf BatchDetectSentiment' {Sensitive (NonEmpty (Sensitive Text))
LanguageCode
languageCode :: LanguageCode
textList :: Sensitive (NonEmpty (Sensitive Text))
$sel:languageCode:BatchDetectSentiment' :: BatchDetectSentiment -> LanguageCode
$sel:textList:BatchDetectSentiment' :: BatchDetectSentiment -> Sensitive (NonEmpty (Sensitive Text))
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Sensitive (NonEmpty (Sensitive Text))
textList
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf LanguageCode
languageCode

instance Data.ToHeaders BatchDetectSentiment where
  toHeaders :: BatchDetectSentiment -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"Comprehend_20171127.BatchDetectSentiment" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON BatchDetectSentiment where
  toJSON :: BatchDetectSentiment -> Value
toJSON BatchDetectSentiment' {Sensitive (NonEmpty (Sensitive Text))
LanguageCode
languageCode :: LanguageCode
textList :: Sensitive (NonEmpty (Sensitive Text))
$sel:languageCode:BatchDetectSentiment' :: BatchDetectSentiment -> LanguageCode
$sel:textList:BatchDetectSentiment' :: BatchDetectSentiment -> Sensitive (NonEmpty (Sensitive Text))
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"TextList" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive (NonEmpty (Sensitive Text))
textList),
            forall a. a -> Maybe a
Prelude.Just (Key
"LanguageCode" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= LanguageCode
languageCode)
          ]
      )

instance Data.ToPath BatchDetectSentiment where
  toPath :: BatchDetectSentiment -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery BatchDetectSentiment where
  toQuery :: BatchDetectSentiment -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newBatchDetectSentimentResponse' smart constructor.
data BatchDetectSentimentResponse = BatchDetectSentimentResponse'
  { -- | The response's http status code.
    BatchDetectSentimentResponse -> Int
httpStatus :: Prelude.Int,
    -- | A list of objects containing the results of the operation. The results
    -- are sorted in ascending order by the @Index@ field and match the order
    -- of the documents in the input list. If all of the documents contain an
    -- error, the @ResultList@ is empty.
    BatchDetectSentimentResponse -> [BatchDetectSentimentItemResult]
resultList :: [BatchDetectSentimentItemResult],
    -- | A list containing one object for each document that contained an error.
    -- The results are sorted in ascending order by the @Index@ field and match
    -- the order of the documents in the input list. If there are no errors in
    -- the batch, the @ErrorList@ is empty.
    BatchDetectSentimentResponse -> [BatchItemError]
errorList :: [BatchItemError]
  }
  deriving (BatchDetectSentimentResponse
-> BatchDetectSentimentResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchDetectSentimentResponse
-> BatchDetectSentimentResponse -> Bool
$c/= :: BatchDetectSentimentResponse
-> BatchDetectSentimentResponse -> Bool
== :: BatchDetectSentimentResponse
-> BatchDetectSentimentResponse -> Bool
$c== :: BatchDetectSentimentResponse
-> BatchDetectSentimentResponse -> Bool
Prelude.Eq, Int -> BatchDetectSentimentResponse -> ShowS
[BatchDetectSentimentResponse] -> ShowS
BatchDetectSentimentResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchDetectSentimentResponse] -> ShowS
$cshowList :: [BatchDetectSentimentResponse] -> ShowS
show :: BatchDetectSentimentResponse -> String
$cshow :: BatchDetectSentimentResponse -> String
showsPrec :: Int -> BatchDetectSentimentResponse -> ShowS
$cshowsPrec :: Int -> BatchDetectSentimentResponse -> ShowS
Prelude.Show, forall x.
Rep BatchDetectSentimentResponse x -> BatchDetectSentimentResponse
forall x.
BatchDetectSentimentResponse -> Rep BatchDetectSentimentResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchDetectSentimentResponse x -> BatchDetectSentimentResponse
$cfrom :: forall x.
BatchDetectSentimentResponse -> Rep BatchDetectSentimentResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchDetectSentimentResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'httpStatus', 'batchDetectSentimentResponse_httpStatus' - The response's http status code.
--
-- 'resultList', 'batchDetectSentimentResponse_resultList' - A list of objects containing the results of the operation. The results
-- are sorted in ascending order by the @Index@ field and match the order
-- of the documents in the input list. If all of the documents contain an
-- error, the @ResultList@ is empty.
--
-- 'errorList', 'batchDetectSentimentResponse_errorList' - A list containing one object for each document that contained an error.
-- The results are sorted in ascending order by the @Index@ field and match
-- the order of the documents in the input list. If there are no errors in
-- the batch, the @ErrorList@ is empty.
newBatchDetectSentimentResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchDetectSentimentResponse
newBatchDetectSentimentResponse :: Int -> BatchDetectSentimentResponse
newBatchDetectSentimentResponse Int
pHttpStatus_ =
  BatchDetectSentimentResponse'
    { $sel:httpStatus:BatchDetectSentimentResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:resultList:BatchDetectSentimentResponse' :: [BatchDetectSentimentItemResult]
resultList = forall a. Monoid a => a
Prelude.mempty,
      $sel:errorList:BatchDetectSentimentResponse' :: [BatchItemError]
errorList = forall a. Monoid a => a
Prelude.mempty
    }

-- | The response's http status code.
batchDetectSentimentResponse_httpStatus :: Lens.Lens' BatchDetectSentimentResponse Prelude.Int
batchDetectSentimentResponse_httpStatus :: Lens' BatchDetectSentimentResponse Int
batchDetectSentimentResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchDetectSentimentResponse' {Int
httpStatus :: Int
$sel:httpStatus:BatchDetectSentimentResponse' :: BatchDetectSentimentResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BatchDetectSentimentResponse
s@BatchDetectSentimentResponse' {} Int
a -> BatchDetectSentimentResponse
s {$sel:httpStatus:BatchDetectSentimentResponse' :: Int
httpStatus = Int
a} :: BatchDetectSentimentResponse)

-- | A list of objects containing the results of the operation. The results
-- are sorted in ascending order by the @Index@ field and match the order
-- of the documents in the input list. If all of the documents contain an
-- error, the @ResultList@ is empty.
batchDetectSentimentResponse_resultList :: Lens.Lens' BatchDetectSentimentResponse [BatchDetectSentimentItemResult]
batchDetectSentimentResponse_resultList :: Lens' BatchDetectSentimentResponse [BatchDetectSentimentItemResult]
batchDetectSentimentResponse_resultList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchDetectSentimentResponse' {[BatchDetectSentimentItemResult]
resultList :: [BatchDetectSentimentItemResult]
$sel:resultList:BatchDetectSentimentResponse' :: BatchDetectSentimentResponse -> [BatchDetectSentimentItemResult]
resultList} -> [BatchDetectSentimentItemResult]
resultList) (\s :: BatchDetectSentimentResponse
s@BatchDetectSentimentResponse' {} [BatchDetectSentimentItemResult]
a -> BatchDetectSentimentResponse
s {$sel:resultList:BatchDetectSentimentResponse' :: [BatchDetectSentimentItemResult]
resultList = [BatchDetectSentimentItemResult]
a} :: BatchDetectSentimentResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list containing one object for each document that contained an error.
-- The results are sorted in ascending order by the @Index@ field and match
-- the order of the documents in the input list. If there are no errors in
-- the batch, the @ErrorList@ is empty.
batchDetectSentimentResponse_errorList :: Lens.Lens' BatchDetectSentimentResponse [BatchItemError]
batchDetectSentimentResponse_errorList :: Lens' BatchDetectSentimentResponse [BatchItemError]
batchDetectSentimentResponse_errorList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchDetectSentimentResponse' {[BatchItemError]
errorList :: [BatchItemError]
$sel:errorList:BatchDetectSentimentResponse' :: BatchDetectSentimentResponse -> [BatchItemError]
errorList} -> [BatchItemError]
errorList) (\s :: BatchDetectSentimentResponse
s@BatchDetectSentimentResponse' {} [BatchItemError]
a -> BatchDetectSentimentResponse
s {$sel:errorList:BatchDetectSentimentResponse' :: [BatchItemError]
errorList = [BatchItemError]
a} :: BatchDetectSentimentResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData BatchDetectSentimentResponse where
  rnf :: BatchDetectSentimentResponse -> ()
rnf BatchDetectSentimentResponse' {Int
[BatchItemError]
[BatchDetectSentimentItemResult]
errorList :: [BatchItemError]
resultList :: [BatchDetectSentimentItemResult]
httpStatus :: Int
$sel:errorList:BatchDetectSentimentResponse' :: BatchDetectSentimentResponse -> [BatchItemError]
$sel:resultList:BatchDetectSentimentResponse' :: BatchDetectSentimentResponse -> [BatchDetectSentimentItemResult]
$sel:httpStatus:BatchDetectSentimentResponse' :: BatchDetectSentimentResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [BatchDetectSentimentItemResult]
resultList
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [BatchItemError]
errorList