{-# 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.BatchDetectEntities
-- 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 the text of a batch of documents for named entities and returns
-- information about them. For more information about named entities, see
-- <https://docs.aws.amazon.com/comprehend/latest/dg/how-entities.html Entities>
-- in the Comprehend Developer Guide.
module Amazonka.Comprehend.BatchDetectEntities
  ( -- * Creating a Request
    BatchDetectEntities (..),
    newBatchDetectEntities,

    -- * Request Lenses
    batchDetectEntities_textList,
    batchDetectEntities_languageCode,

    -- * Destructuring the Response
    BatchDetectEntitiesResponse (..),
    newBatchDetectEntitiesResponse,

    -- * Response Lenses
    batchDetectEntitiesResponse_httpStatus,
    batchDetectEntitiesResponse_resultList,
    batchDetectEntitiesResponse_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:/ 'newBatchDetectEntities' smart constructor.
data BatchDetectEntities = BatchDetectEntities'
  { -- | 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.
    BatchDetectEntities -> 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.
    BatchDetectEntities -> LanguageCode
languageCode :: LanguageCode
  }
  deriving (BatchDetectEntities -> BatchDetectEntities -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchDetectEntities -> BatchDetectEntities -> Bool
$c/= :: BatchDetectEntities -> BatchDetectEntities -> Bool
== :: BatchDetectEntities -> BatchDetectEntities -> Bool
$c== :: BatchDetectEntities -> BatchDetectEntities -> Bool
Prelude.Eq, Int -> BatchDetectEntities -> ShowS
[BatchDetectEntities] -> ShowS
BatchDetectEntities -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchDetectEntities] -> ShowS
$cshowList :: [BatchDetectEntities] -> ShowS
show :: BatchDetectEntities -> String
$cshow :: BatchDetectEntities -> String
showsPrec :: Int -> BatchDetectEntities -> ShowS
$cshowsPrec :: Int -> BatchDetectEntities -> ShowS
Prelude.Show, forall x. Rep BatchDetectEntities x -> BatchDetectEntities
forall x. BatchDetectEntities -> Rep BatchDetectEntities x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchDetectEntities x -> BatchDetectEntities
$cfrom :: forall x. BatchDetectEntities -> Rep BatchDetectEntities x
Prelude.Generic)

-- |
-- Create a value of 'BatchDetectEntities' 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', 'batchDetectEntities_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.
--
-- 'languageCode', 'batchDetectEntities_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.
newBatchDetectEntities ::
  -- | 'textList'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'languageCode'
  LanguageCode ->
  BatchDetectEntities
newBatchDetectEntities :: NonEmpty Text -> LanguageCode -> BatchDetectEntities
newBatchDetectEntities NonEmpty Text
pTextList_ LanguageCode
pLanguageCode_ =
  BatchDetectEntities'
    { $sel:textList:BatchDetectEntities' :: 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:BatchDetectEntities' :: 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.
batchDetectEntities_textList :: Lens.Lens' BatchDetectEntities (Prelude.NonEmpty Prelude.Text)
batchDetectEntities_textList :: Lens' BatchDetectEntities (NonEmpty Text)
batchDetectEntities_textList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchDetectEntities' {Sensitive (NonEmpty (Sensitive Text))
textList :: Sensitive (NonEmpty (Sensitive Text))
$sel:textList:BatchDetectEntities' :: BatchDetectEntities -> Sensitive (NonEmpty (Sensitive Text))
textList} -> Sensitive (NonEmpty (Sensitive Text))
textList) (\s :: BatchDetectEntities
s@BatchDetectEntities' {} Sensitive (NonEmpty (Sensitive Text))
a -> BatchDetectEntities
s {$sel:textList:BatchDetectEntities' :: Sensitive (NonEmpty (Sensitive Text))
textList = Sensitive (NonEmpty (Sensitive Text))
a} :: BatchDetectEntities) 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.
batchDetectEntities_languageCode :: Lens.Lens' BatchDetectEntities LanguageCode
batchDetectEntities_languageCode :: Lens' BatchDetectEntities LanguageCode
batchDetectEntities_languageCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchDetectEntities' {LanguageCode
languageCode :: LanguageCode
$sel:languageCode:BatchDetectEntities' :: BatchDetectEntities -> LanguageCode
languageCode} -> LanguageCode
languageCode) (\s :: BatchDetectEntities
s@BatchDetectEntities' {} LanguageCode
a -> BatchDetectEntities
s {$sel:languageCode:BatchDetectEntities' :: LanguageCode
languageCode = LanguageCode
a} :: BatchDetectEntities)

instance Core.AWSRequest BatchDetectEntities where
  type
    AWSResponse BatchDetectEntities =
      BatchDetectEntitiesResponse
  request :: (Service -> Service)
-> BatchDetectEntities -> Request BatchDetectEntities
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 BatchDetectEntities
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BatchDetectEntities)))
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
-> [BatchDetectEntitiesItemResult]
-> [BatchItemError]
-> BatchDetectEntitiesResponse
BatchDetectEntitiesResponse'
            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 BatchDetectEntities where
  hashWithSalt :: Int -> BatchDetectEntities -> Int
hashWithSalt Int
_salt BatchDetectEntities' {Sensitive (NonEmpty (Sensitive Text))
LanguageCode
languageCode :: LanguageCode
textList :: Sensitive (NonEmpty (Sensitive Text))
$sel:languageCode:BatchDetectEntities' :: BatchDetectEntities -> LanguageCode
$sel:textList:BatchDetectEntities' :: BatchDetectEntities -> 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 BatchDetectEntities where
  rnf :: BatchDetectEntities -> ()
rnf BatchDetectEntities' {Sensitive (NonEmpty (Sensitive Text))
LanguageCode
languageCode :: LanguageCode
textList :: Sensitive (NonEmpty (Sensitive Text))
$sel:languageCode:BatchDetectEntities' :: BatchDetectEntities -> LanguageCode
$sel:textList:BatchDetectEntities' :: BatchDetectEntities -> 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 BatchDetectEntities where
  toHeaders :: BatchDetectEntities -> 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.BatchDetectEntities" ::
                          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 BatchDetectEntities where
  toJSON :: BatchDetectEntities -> Value
toJSON BatchDetectEntities' {Sensitive (NonEmpty (Sensitive Text))
LanguageCode
languageCode :: LanguageCode
textList :: Sensitive (NonEmpty (Sensitive Text))
$sel:languageCode:BatchDetectEntities' :: BatchDetectEntities -> LanguageCode
$sel:textList:BatchDetectEntities' :: BatchDetectEntities -> 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 BatchDetectEntities where
  toPath :: BatchDetectEntities -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newBatchDetectEntitiesResponse' smart constructor.
data BatchDetectEntitiesResponse = BatchDetectEntitiesResponse'
  { -- | The response's http status code.
    BatchDetectEntitiesResponse -> 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.
    BatchDetectEntitiesResponse -> [BatchDetectEntitiesItemResult]
resultList :: [BatchDetectEntitiesItemResult],
    -- | 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.
    BatchDetectEntitiesResponse -> [BatchItemError]
errorList :: [BatchItemError]
  }
  deriving (BatchDetectEntitiesResponse -> BatchDetectEntitiesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchDetectEntitiesResponse -> BatchDetectEntitiesResponse -> Bool
$c/= :: BatchDetectEntitiesResponse -> BatchDetectEntitiesResponse -> Bool
== :: BatchDetectEntitiesResponse -> BatchDetectEntitiesResponse -> Bool
$c== :: BatchDetectEntitiesResponse -> BatchDetectEntitiesResponse -> Bool
Prelude.Eq, Int -> BatchDetectEntitiesResponse -> ShowS
[BatchDetectEntitiesResponse] -> ShowS
BatchDetectEntitiesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchDetectEntitiesResponse] -> ShowS
$cshowList :: [BatchDetectEntitiesResponse] -> ShowS
show :: BatchDetectEntitiesResponse -> String
$cshow :: BatchDetectEntitiesResponse -> String
showsPrec :: Int -> BatchDetectEntitiesResponse -> ShowS
$cshowsPrec :: Int -> BatchDetectEntitiesResponse -> ShowS
Prelude.Show, forall x.
Rep BatchDetectEntitiesResponse x -> BatchDetectEntitiesResponse
forall x.
BatchDetectEntitiesResponse -> Rep BatchDetectEntitiesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchDetectEntitiesResponse x -> BatchDetectEntitiesResponse
$cfrom :: forall x.
BatchDetectEntitiesResponse -> Rep BatchDetectEntitiesResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchDetectEntitiesResponse' 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', 'batchDetectEntitiesResponse_httpStatus' - The response's http status code.
--
-- 'resultList', 'batchDetectEntitiesResponse_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', 'batchDetectEntitiesResponse_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.
newBatchDetectEntitiesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchDetectEntitiesResponse
newBatchDetectEntitiesResponse :: Int -> BatchDetectEntitiesResponse
newBatchDetectEntitiesResponse Int
pHttpStatus_ =
  BatchDetectEntitiesResponse'
    { $sel:httpStatus:BatchDetectEntitiesResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:resultList:BatchDetectEntitiesResponse' :: [BatchDetectEntitiesItemResult]
resultList = forall a. Monoid a => a
Prelude.mempty,
      $sel:errorList:BatchDetectEntitiesResponse' :: [BatchItemError]
errorList = forall a. Monoid a => a
Prelude.mempty
    }

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

-- | 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.
batchDetectEntitiesResponse_resultList :: Lens.Lens' BatchDetectEntitiesResponse [BatchDetectEntitiesItemResult]
batchDetectEntitiesResponse_resultList :: Lens' BatchDetectEntitiesResponse [BatchDetectEntitiesItemResult]
batchDetectEntitiesResponse_resultList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchDetectEntitiesResponse' {[BatchDetectEntitiesItemResult]
resultList :: [BatchDetectEntitiesItemResult]
$sel:resultList:BatchDetectEntitiesResponse' :: BatchDetectEntitiesResponse -> [BatchDetectEntitiesItemResult]
resultList} -> [BatchDetectEntitiesItemResult]
resultList) (\s :: BatchDetectEntitiesResponse
s@BatchDetectEntitiesResponse' {} [BatchDetectEntitiesItemResult]
a -> BatchDetectEntitiesResponse
s {$sel:resultList:BatchDetectEntitiesResponse' :: [BatchDetectEntitiesItemResult]
resultList = [BatchDetectEntitiesItemResult]
a} :: BatchDetectEntitiesResponse) 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.
batchDetectEntitiesResponse_errorList :: Lens.Lens' BatchDetectEntitiesResponse [BatchItemError]
batchDetectEntitiesResponse_errorList :: Lens' BatchDetectEntitiesResponse [BatchItemError]
batchDetectEntitiesResponse_errorList = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchDetectEntitiesResponse' {[BatchItemError]
errorList :: [BatchItemError]
$sel:errorList:BatchDetectEntitiesResponse' :: BatchDetectEntitiesResponse -> [BatchItemError]
errorList} -> [BatchItemError]
errorList) (\s :: BatchDetectEntitiesResponse
s@BatchDetectEntitiesResponse' {} [BatchItemError]
a -> BatchDetectEntitiesResponse
s {$sel:errorList:BatchDetectEntitiesResponse' :: [BatchItemError]
errorList = [BatchItemError]
a} :: BatchDetectEntitiesResponse) 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 BatchDetectEntitiesResponse where
  rnf :: BatchDetectEntitiesResponse -> ()
rnf BatchDetectEntitiesResponse' {Int
[BatchItemError]
[BatchDetectEntitiesItemResult]
errorList :: [BatchItemError]
resultList :: [BatchDetectEntitiesItemResult]
httpStatus :: Int
$sel:errorList:BatchDetectEntitiesResponse' :: BatchDetectEntitiesResponse -> [BatchItemError]
$sel:resultList:BatchDetectEntitiesResponse' :: BatchDetectEntitiesResponse -> [BatchDetectEntitiesItemResult]
$sel:httpStatus:BatchDetectEntitiesResponse' :: BatchDetectEntitiesResponse -> 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 [BatchDetectEntitiesItemResult]
resultList
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [BatchItemError]
errorList