{-# 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.DetectSyntax
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Inspects text for syntax and the part of speech of words in the
-- document. For more information, how-syntax.
module Amazonka.Comprehend.DetectSyntax
  ( -- * Creating a Request
    DetectSyntax (..),
    newDetectSyntax,

    -- * Request Lenses
    detectSyntax_text,
    detectSyntax_languageCode,

    -- * Destructuring the Response
    DetectSyntaxResponse (..),
    newDetectSyntaxResponse,

    -- * Response Lenses
    detectSyntaxResponse_syntaxTokens,
    detectSyntaxResponse_httpStatus,
  )
where

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

-- | /See:/ 'newDetectSyntax' smart constructor.
data DetectSyntax = DetectSyntax'
  { -- | A UTF-8 string. Each string must contain fewer that 5,000 bytes of UTF
    -- encoded characters.
    DetectSyntax -> Sensitive Text
text :: Core.Sensitive Prelude.Text,
    -- | The language code of the input documents. You can specify any of the
    -- following languages supported by Amazon Comprehend: German (\"de\"),
    -- English (\"en\"), Spanish (\"es\"), French (\"fr\"), Italian (\"it\"),
    -- or Portuguese (\"pt\").
    DetectSyntax -> SyntaxLanguageCode
languageCode :: SyntaxLanguageCode
  }
  deriving (DetectSyntax -> DetectSyntax -> Bool
(DetectSyntax -> DetectSyntax -> Bool)
-> (DetectSyntax -> DetectSyntax -> Bool) -> Eq DetectSyntax
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectSyntax -> DetectSyntax -> Bool
$c/= :: DetectSyntax -> DetectSyntax -> Bool
== :: DetectSyntax -> DetectSyntax -> Bool
$c== :: DetectSyntax -> DetectSyntax -> Bool
Prelude.Eq, Int -> DetectSyntax -> ShowS
[DetectSyntax] -> ShowS
DetectSyntax -> String
(Int -> DetectSyntax -> ShowS)
-> (DetectSyntax -> String)
-> ([DetectSyntax] -> ShowS)
-> Show DetectSyntax
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectSyntax] -> ShowS
$cshowList :: [DetectSyntax] -> ShowS
show :: DetectSyntax -> String
$cshow :: DetectSyntax -> String
showsPrec :: Int -> DetectSyntax -> ShowS
$cshowsPrec :: Int -> DetectSyntax -> ShowS
Prelude.Show, (forall x. DetectSyntax -> Rep DetectSyntax x)
-> (forall x. Rep DetectSyntax x -> DetectSyntax)
-> Generic DetectSyntax
forall x. Rep DetectSyntax x -> DetectSyntax
forall x. DetectSyntax -> Rep DetectSyntax x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetectSyntax x -> DetectSyntax
$cfrom :: forall x. DetectSyntax -> Rep DetectSyntax x
Prelude.Generic)

-- |
-- Create a value of 'DetectSyntax' 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:
--
-- 'text', 'detectSyntax_text' - A UTF-8 string. Each string must contain fewer that 5,000 bytes of UTF
-- encoded characters.
--
-- 'languageCode', 'detectSyntax_languageCode' - The language code of the input documents. You can specify any of the
-- following languages supported by Amazon Comprehend: German (\"de\"),
-- English (\"en\"), Spanish (\"es\"), French (\"fr\"), Italian (\"it\"),
-- or Portuguese (\"pt\").
newDetectSyntax ::
  -- | 'text'
  Prelude.Text ->
  -- | 'languageCode'
  SyntaxLanguageCode ->
  DetectSyntax
newDetectSyntax :: Text -> SyntaxLanguageCode -> DetectSyntax
newDetectSyntax Text
pText_ SyntaxLanguageCode
pLanguageCode_ =
  DetectSyntax' :: Sensitive Text -> SyntaxLanguageCode -> DetectSyntax
DetectSyntax'
    { $sel:text:DetectSyntax' :: Sensitive Text
text = Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pText_,
      $sel:languageCode:DetectSyntax' :: SyntaxLanguageCode
languageCode = SyntaxLanguageCode
pLanguageCode_
    }

-- | A UTF-8 string. Each string must contain fewer that 5,000 bytes of UTF
-- encoded characters.
detectSyntax_text :: Lens.Lens' DetectSyntax Prelude.Text
detectSyntax_text :: (Text -> f Text) -> DetectSyntax -> f DetectSyntax
detectSyntax_text = (DetectSyntax -> Sensitive Text)
-> (DetectSyntax -> Sensitive Text -> DetectSyntax)
-> Lens DetectSyntax DetectSyntax (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectSyntax' {Sensitive Text
text :: Sensitive Text
$sel:text:DetectSyntax' :: DetectSyntax -> Sensitive Text
text} -> Sensitive Text
text) (\s :: DetectSyntax
s@DetectSyntax' {} Sensitive Text
a -> DetectSyntax
s {$sel:text:DetectSyntax' :: Sensitive Text
text = Sensitive Text
a} :: DetectSyntax) ((Sensitive Text -> f (Sensitive Text))
 -> DetectSyntax -> f DetectSyntax)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> DetectSyntax
-> f DetectSyntax
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

-- | The language code of the input documents. You can specify any of the
-- following languages supported by Amazon Comprehend: German (\"de\"),
-- English (\"en\"), Spanish (\"es\"), French (\"fr\"), Italian (\"it\"),
-- or Portuguese (\"pt\").
detectSyntax_languageCode :: Lens.Lens' DetectSyntax SyntaxLanguageCode
detectSyntax_languageCode :: (SyntaxLanguageCode -> f SyntaxLanguageCode)
-> DetectSyntax -> f DetectSyntax
detectSyntax_languageCode = (DetectSyntax -> SyntaxLanguageCode)
-> (DetectSyntax -> SyntaxLanguageCode -> DetectSyntax)
-> Lens
     DetectSyntax DetectSyntax SyntaxLanguageCode SyntaxLanguageCode
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectSyntax' {SyntaxLanguageCode
languageCode :: SyntaxLanguageCode
$sel:languageCode:DetectSyntax' :: DetectSyntax -> SyntaxLanguageCode
languageCode} -> SyntaxLanguageCode
languageCode) (\s :: DetectSyntax
s@DetectSyntax' {} SyntaxLanguageCode
a -> DetectSyntax
s {$sel:languageCode:DetectSyntax' :: SyntaxLanguageCode
languageCode = SyntaxLanguageCode
a} :: DetectSyntax)

instance Core.AWSRequest DetectSyntax where
  type AWSResponse DetectSyntax = DetectSyntaxResponse
  request :: DetectSyntax -> Request DetectSyntax
request = Service -> DetectSyntax -> Request DetectSyntax
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DetectSyntax
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetectSyntax)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DetectSyntax))
-> Logger
-> Service
-> Proxy DetectSyntax
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetectSyntax)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [SyntaxToken] -> Int -> DetectSyntaxResponse
DetectSyntaxResponse'
            (Maybe [SyntaxToken] -> Int -> DetectSyntaxResponse)
-> Either String (Maybe [SyntaxToken])
-> Either String (Int -> DetectSyntaxResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [SyntaxToken]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"SyntaxTokens" Either String (Maybe (Maybe [SyntaxToken]))
-> Maybe [SyntaxToken] -> Either String (Maybe [SyntaxToken])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [SyntaxToken]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> DetectSyntaxResponse)
-> Either String Int -> Either String DetectSyntaxResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable DetectSyntax

instance Prelude.NFData DetectSyntax

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

instance Core.ToJSON DetectSyntax where
  toJSON :: DetectSyntax -> Value
toJSON DetectSyntax' {Sensitive Text
SyntaxLanguageCode
languageCode :: SyntaxLanguageCode
text :: Sensitive Text
$sel:languageCode:DetectSyntax' :: DetectSyntax -> SyntaxLanguageCode
$sel:text:DetectSyntax' :: DetectSyntax -> Sensitive Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Text" Text -> Sensitive Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Sensitive Text
text),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"LanguageCode" Text -> SyntaxLanguageCode -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SyntaxLanguageCode
languageCode)
          ]
      )

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

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

-- | /See:/ 'newDetectSyntaxResponse' smart constructor.
data DetectSyntaxResponse = DetectSyntaxResponse'
  { -- | A collection of syntax tokens describing the text. For each token, the
    -- response provides the text, the token type, where the text begins and
    -- ends, and the level of confidence that Amazon Comprehend has that the
    -- token is correct. For a list of token types, see how-syntax.
    DetectSyntaxResponse -> Maybe [SyntaxToken]
syntaxTokens :: Prelude.Maybe [SyntaxToken],
    -- | The response's http status code.
    DetectSyntaxResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DetectSyntaxResponse -> DetectSyntaxResponse -> Bool
(DetectSyntaxResponse -> DetectSyntaxResponse -> Bool)
-> (DetectSyntaxResponse -> DetectSyntaxResponse -> Bool)
-> Eq DetectSyntaxResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectSyntaxResponse -> DetectSyntaxResponse -> Bool
$c/= :: DetectSyntaxResponse -> DetectSyntaxResponse -> Bool
== :: DetectSyntaxResponse -> DetectSyntaxResponse -> Bool
$c== :: DetectSyntaxResponse -> DetectSyntaxResponse -> Bool
Prelude.Eq, Int -> DetectSyntaxResponse -> ShowS
[DetectSyntaxResponse] -> ShowS
DetectSyntaxResponse -> String
(Int -> DetectSyntaxResponse -> ShowS)
-> (DetectSyntaxResponse -> String)
-> ([DetectSyntaxResponse] -> ShowS)
-> Show DetectSyntaxResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectSyntaxResponse] -> ShowS
$cshowList :: [DetectSyntaxResponse] -> ShowS
show :: DetectSyntaxResponse -> String
$cshow :: DetectSyntaxResponse -> String
showsPrec :: Int -> DetectSyntaxResponse -> ShowS
$cshowsPrec :: Int -> DetectSyntaxResponse -> ShowS
Prelude.Show, (forall x. DetectSyntaxResponse -> Rep DetectSyntaxResponse x)
-> (forall x. Rep DetectSyntaxResponse x -> DetectSyntaxResponse)
-> Generic DetectSyntaxResponse
forall x. Rep DetectSyntaxResponse x -> DetectSyntaxResponse
forall x. DetectSyntaxResponse -> Rep DetectSyntaxResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetectSyntaxResponse x -> DetectSyntaxResponse
$cfrom :: forall x. DetectSyntaxResponse -> Rep DetectSyntaxResponse x
Prelude.Generic)

-- |
-- Create a value of 'DetectSyntaxResponse' 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:
--
-- 'syntaxTokens', 'detectSyntaxResponse_syntaxTokens' - A collection of syntax tokens describing the text. For each token, the
-- response provides the text, the token type, where the text begins and
-- ends, and the level of confidence that Amazon Comprehend has that the
-- token is correct. For a list of token types, see how-syntax.
--
-- 'httpStatus', 'detectSyntaxResponse_httpStatus' - The response's http status code.
newDetectSyntaxResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DetectSyntaxResponse
newDetectSyntaxResponse :: Int -> DetectSyntaxResponse
newDetectSyntaxResponse Int
pHttpStatus_ =
  DetectSyntaxResponse' :: Maybe [SyntaxToken] -> Int -> DetectSyntaxResponse
DetectSyntaxResponse'
    { $sel:syntaxTokens:DetectSyntaxResponse' :: Maybe [SyntaxToken]
syntaxTokens =
        Maybe [SyntaxToken]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DetectSyntaxResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A collection of syntax tokens describing the text. For each token, the
-- response provides the text, the token type, where the text begins and
-- ends, and the level of confidence that Amazon Comprehend has that the
-- token is correct. For a list of token types, see how-syntax.
detectSyntaxResponse_syntaxTokens :: Lens.Lens' DetectSyntaxResponse (Prelude.Maybe [SyntaxToken])
detectSyntaxResponse_syntaxTokens :: (Maybe [SyntaxToken] -> f (Maybe [SyntaxToken]))
-> DetectSyntaxResponse -> f DetectSyntaxResponse
detectSyntaxResponse_syntaxTokens = (DetectSyntaxResponse -> Maybe [SyntaxToken])
-> (DetectSyntaxResponse
    -> Maybe [SyntaxToken] -> DetectSyntaxResponse)
-> Lens
     DetectSyntaxResponse
     DetectSyntaxResponse
     (Maybe [SyntaxToken])
     (Maybe [SyntaxToken])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectSyntaxResponse' {Maybe [SyntaxToken]
syntaxTokens :: Maybe [SyntaxToken]
$sel:syntaxTokens:DetectSyntaxResponse' :: DetectSyntaxResponse -> Maybe [SyntaxToken]
syntaxTokens} -> Maybe [SyntaxToken]
syntaxTokens) (\s :: DetectSyntaxResponse
s@DetectSyntaxResponse' {} Maybe [SyntaxToken]
a -> DetectSyntaxResponse
s {$sel:syntaxTokens:DetectSyntaxResponse' :: Maybe [SyntaxToken]
syntaxTokens = Maybe [SyntaxToken]
a} :: DetectSyntaxResponse) ((Maybe [SyntaxToken] -> f (Maybe [SyntaxToken]))
 -> DetectSyntaxResponse -> f DetectSyntaxResponse)
-> ((Maybe [SyntaxToken] -> f (Maybe [SyntaxToken]))
    -> Maybe [SyntaxToken] -> f (Maybe [SyntaxToken]))
-> (Maybe [SyntaxToken] -> f (Maybe [SyntaxToken]))
-> DetectSyntaxResponse
-> f DetectSyntaxResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [SyntaxToken] [SyntaxToken] [SyntaxToken] [SyntaxToken]
-> Iso
     (Maybe [SyntaxToken])
     (Maybe [SyntaxToken])
     (Maybe [SyntaxToken])
     (Maybe [SyntaxToken])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [SyntaxToken] [SyntaxToken] [SyntaxToken] [SyntaxToken]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData DetectSyntaxResponse