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

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

-- |
-- Module      : Amazonka.Rekognition.Types.TextDetection
-- 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)
module Amazonka.Rekognition.Types.TextDetection where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.Rekognition.Types.Geometry
import Amazonka.Rekognition.Types.TextTypes

-- | Information about a word or line of text detected by DetectText.
--
-- The @DetectedText@ field contains the text that Amazon Rekognition
-- detected in the image.
--
-- Every word and line has an identifier (@Id@). Each word belongs to a
-- line and has a parent identifier (@ParentId@) that identifies the line
-- of text in which the word appears. The word @Id@ is also an index for
-- the word within a line of words.
--
-- For more information, see Detecting Text in the Amazon Rekognition
-- Developer Guide.
--
-- /See:/ 'newTextDetection' smart constructor.
data TextDetection = TextDetection'
  { -- | The word or line of text recognized by Amazon Rekognition.
    TextDetection -> Maybe Text
detectedText :: Prelude.Maybe Prelude.Text,
    -- | The confidence that Amazon Rekognition has in the accuracy of the
    -- detected text and the accuracy of the geometry points around the
    -- detected text.
    TextDetection -> Maybe Double
confidence :: Prelude.Maybe Prelude.Double,
    -- | The location of the detected text on the image. Includes an axis aligned
    -- coarse bounding box surrounding the text and a finer grain polygon for
    -- more accurate spatial information.
    TextDetection -> Maybe Geometry
geometry :: Prelude.Maybe Geometry,
    -- | The identifier for the detected text. The identifier is only unique for
    -- a single call to @DetectText@.
    TextDetection -> Maybe Natural
id :: Prelude.Maybe Prelude.Natural,
    -- | The type of text that was detected.
    TextDetection -> Maybe TextTypes
type' :: Prelude.Maybe TextTypes,
    -- | The Parent identifier for the detected text identified by the value of
    -- @ID@. If the type of detected text is @LINE@, the value of @ParentId@ is
    -- @Null@.
    TextDetection -> Maybe Natural
parentId :: Prelude.Maybe Prelude.Natural
  }
  deriving (TextDetection -> TextDetection -> Bool
(TextDetection -> TextDetection -> Bool)
-> (TextDetection -> TextDetection -> Bool) -> Eq TextDetection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TextDetection -> TextDetection -> Bool
$c/= :: TextDetection -> TextDetection -> Bool
== :: TextDetection -> TextDetection -> Bool
$c== :: TextDetection -> TextDetection -> Bool
Prelude.Eq, ReadPrec [TextDetection]
ReadPrec TextDetection
Int -> ReadS TextDetection
ReadS [TextDetection]
(Int -> ReadS TextDetection)
-> ReadS [TextDetection]
-> ReadPrec TextDetection
-> ReadPrec [TextDetection]
-> Read TextDetection
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TextDetection]
$creadListPrec :: ReadPrec [TextDetection]
readPrec :: ReadPrec TextDetection
$creadPrec :: ReadPrec TextDetection
readList :: ReadS [TextDetection]
$creadList :: ReadS [TextDetection]
readsPrec :: Int -> ReadS TextDetection
$creadsPrec :: Int -> ReadS TextDetection
Prelude.Read, Int -> TextDetection -> ShowS
[TextDetection] -> ShowS
TextDetection -> String
(Int -> TextDetection -> ShowS)
-> (TextDetection -> String)
-> ([TextDetection] -> ShowS)
-> Show TextDetection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TextDetection] -> ShowS
$cshowList :: [TextDetection] -> ShowS
show :: TextDetection -> String
$cshow :: TextDetection -> String
showsPrec :: Int -> TextDetection -> ShowS
$cshowsPrec :: Int -> TextDetection -> ShowS
Prelude.Show, (forall x. TextDetection -> Rep TextDetection x)
-> (forall x. Rep TextDetection x -> TextDetection)
-> Generic TextDetection
forall x. Rep TextDetection x -> TextDetection
forall x. TextDetection -> Rep TextDetection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TextDetection x -> TextDetection
$cfrom :: forall x. TextDetection -> Rep TextDetection x
Prelude.Generic)

-- |
-- Create a value of 'TextDetection' 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:
--
-- 'detectedText', 'textDetection_detectedText' - The word or line of text recognized by Amazon Rekognition.
--
-- 'confidence', 'textDetection_confidence' - The confidence that Amazon Rekognition has in the accuracy of the
-- detected text and the accuracy of the geometry points around the
-- detected text.
--
-- 'geometry', 'textDetection_geometry' - The location of the detected text on the image. Includes an axis aligned
-- coarse bounding box surrounding the text and a finer grain polygon for
-- more accurate spatial information.
--
-- 'id', 'textDetection_id' - The identifier for the detected text. The identifier is only unique for
-- a single call to @DetectText@.
--
-- 'type'', 'textDetection_type' - The type of text that was detected.
--
-- 'parentId', 'textDetection_parentId' - The Parent identifier for the detected text identified by the value of
-- @ID@. If the type of detected text is @LINE@, the value of @ParentId@ is
-- @Null@.
newTextDetection ::
  TextDetection
newTextDetection :: TextDetection
newTextDetection =
  TextDetection' :: Maybe Text
-> Maybe Double
-> Maybe Geometry
-> Maybe Natural
-> Maybe TextTypes
-> Maybe Natural
-> TextDetection
TextDetection'
    { $sel:detectedText:TextDetection' :: Maybe Text
detectedText = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:confidence:TextDetection' :: Maybe Double
confidence = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:geometry:TextDetection' :: Maybe Geometry
geometry = Maybe Geometry
forall a. Maybe a
Prelude.Nothing,
      $sel:id:TextDetection' :: Maybe Natural
id = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:type':TextDetection' :: Maybe TextTypes
type' = Maybe TextTypes
forall a. Maybe a
Prelude.Nothing,
      $sel:parentId:TextDetection' :: Maybe Natural
parentId = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The word or line of text recognized by Amazon Rekognition.
textDetection_detectedText :: Lens.Lens' TextDetection (Prelude.Maybe Prelude.Text)
textDetection_detectedText :: (Maybe Text -> f (Maybe Text)) -> TextDetection -> f TextDetection
textDetection_detectedText = (TextDetection -> Maybe Text)
-> (TextDetection -> Maybe Text -> TextDetection)
-> Lens TextDetection TextDetection (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TextDetection' {Maybe Text
detectedText :: Maybe Text
$sel:detectedText:TextDetection' :: TextDetection -> Maybe Text
detectedText} -> Maybe Text
detectedText) (\s :: TextDetection
s@TextDetection' {} Maybe Text
a -> TextDetection
s {$sel:detectedText:TextDetection' :: Maybe Text
detectedText = Maybe Text
a} :: TextDetection)

-- | The confidence that Amazon Rekognition has in the accuracy of the
-- detected text and the accuracy of the geometry points around the
-- detected text.
textDetection_confidence :: Lens.Lens' TextDetection (Prelude.Maybe Prelude.Double)
textDetection_confidence :: (Maybe Double -> f (Maybe Double))
-> TextDetection -> f TextDetection
textDetection_confidence = (TextDetection -> Maybe Double)
-> (TextDetection -> Maybe Double -> TextDetection)
-> Lens TextDetection TextDetection (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TextDetection' {Maybe Double
confidence :: Maybe Double
$sel:confidence:TextDetection' :: TextDetection -> Maybe Double
confidence} -> Maybe Double
confidence) (\s :: TextDetection
s@TextDetection' {} Maybe Double
a -> TextDetection
s {$sel:confidence:TextDetection' :: Maybe Double
confidence = Maybe Double
a} :: TextDetection)

-- | The location of the detected text on the image. Includes an axis aligned
-- coarse bounding box surrounding the text and a finer grain polygon for
-- more accurate spatial information.
textDetection_geometry :: Lens.Lens' TextDetection (Prelude.Maybe Geometry)
textDetection_geometry :: (Maybe Geometry -> f (Maybe Geometry))
-> TextDetection -> f TextDetection
textDetection_geometry = (TextDetection -> Maybe Geometry)
-> (TextDetection -> Maybe Geometry -> TextDetection)
-> Lens
     TextDetection TextDetection (Maybe Geometry) (Maybe Geometry)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TextDetection' {Maybe Geometry
geometry :: Maybe Geometry
$sel:geometry:TextDetection' :: TextDetection -> Maybe Geometry
geometry} -> Maybe Geometry
geometry) (\s :: TextDetection
s@TextDetection' {} Maybe Geometry
a -> TextDetection
s {$sel:geometry:TextDetection' :: Maybe Geometry
geometry = Maybe Geometry
a} :: TextDetection)

-- | The identifier for the detected text. The identifier is only unique for
-- a single call to @DetectText@.
textDetection_id :: Lens.Lens' TextDetection (Prelude.Maybe Prelude.Natural)
textDetection_id :: (Maybe Natural -> f (Maybe Natural))
-> TextDetection -> f TextDetection
textDetection_id = (TextDetection -> Maybe Natural)
-> (TextDetection -> Maybe Natural -> TextDetection)
-> Lens TextDetection TextDetection (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TextDetection' {Maybe Natural
id :: Maybe Natural
$sel:id:TextDetection' :: TextDetection -> Maybe Natural
id} -> Maybe Natural
id) (\s :: TextDetection
s@TextDetection' {} Maybe Natural
a -> TextDetection
s {$sel:id:TextDetection' :: Maybe Natural
id = Maybe Natural
a} :: TextDetection)

-- | The type of text that was detected.
textDetection_type :: Lens.Lens' TextDetection (Prelude.Maybe TextTypes)
textDetection_type :: (Maybe TextTypes -> f (Maybe TextTypes))
-> TextDetection -> f TextDetection
textDetection_type = (TextDetection -> Maybe TextTypes)
-> (TextDetection -> Maybe TextTypes -> TextDetection)
-> Lens
     TextDetection TextDetection (Maybe TextTypes) (Maybe TextTypes)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TextDetection' {Maybe TextTypes
type' :: Maybe TextTypes
$sel:type':TextDetection' :: TextDetection -> Maybe TextTypes
type'} -> Maybe TextTypes
type') (\s :: TextDetection
s@TextDetection' {} Maybe TextTypes
a -> TextDetection
s {$sel:type':TextDetection' :: Maybe TextTypes
type' = Maybe TextTypes
a} :: TextDetection)

-- | The Parent identifier for the detected text identified by the value of
-- @ID@. If the type of detected text is @LINE@, the value of @ParentId@ is
-- @Null@.
textDetection_parentId :: Lens.Lens' TextDetection (Prelude.Maybe Prelude.Natural)
textDetection_parentId :: (Maybe Natural -> f (Maybe Natural))
-> TextDetection -> f TextDetection
textDetection_parentId = (TextDetection -> Maybe Natural)
-> (TextDetection -> Maybe Natural -> TextDetection)
-> Lens TextDetection TextDetection (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TextDetection' {Maybe Natural
parentId :: Maybe Natural
$sel:parentId:TextDetection' :: TextDetection -> Maybe Natural
parentId} -> Maybe Natural
parentId) (\s :: TextDetection
s@TextDetection' {} Maybe Natural
a -> TextDetection
s {$sel:parentId:TextDetection' :: Maybe Natural
parentId = Maybe Natural
a} :: TextDetection)

instance Core.FromJSON TextDetection where
  parseJSON :: Value -> Parser TextDetection
parseJSON =
    String
-> (Object -> Parser TextDetection)
-> Value
-> Parser TextDetection
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TextDetection"
      ( \Object
x ->
          Maybe Text
-> Maybe Double
-> Maybe Geometry
-> Maybe Natural
-> Maybe TextTypes
-> Maybe Natural
-> TextDetection
TextDetection'
            (Maybe Text
 -> Maybe Double
 -> Maybe Geometry
 -> Maybe Natural
 -> Maybe TextTypes
 -> Maybe Natural
 -> TextDetection)
-> Parser (Maybe Text)
-> Parser
     (Maybe Double
      -> Maybe Geometry
      -> Maybe Natural
      -> Maybe TextTypes
      -> Maybe Natural
      -> TextDetection)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DetectedText")
            Parser
  (Maybe Double
   -> Maybe Geometry
   -> Maybe Natural
   -> Maybe TextTypes
   -> Maybe Natural
   -> TextDetection)
-> Parser (Maybe Double)
-> Parser
     (Maybe Geometry
      -> Maybe Natural
      -> Maybe TextTypes
      -> Maybe Natural
      -> TextDetection)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Confidence")
            Parser
  (Maybe Geometry
   -> Maybe Natural
   -> Maybe TextTypes
   -> Maybe Natural
   -> TextDetection)
-> Parser (Maybe Geometry)
-> Parser
     (Maybe Natural
      -> Maybe TextTypes -> Maybe Natural -> TextDetection)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Geometry)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Geometry")
            Parser
  (Maybe Natural
   -> Maybe TextTypes -> Maybe Natural -> TextDetection)
-> Parser (Maybe Natural)
-> Parser (Maybe TextTypes -> Maybe Natural -> TextDetection)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Id")
            Parser (Maybe TextTypes -> Maybe Natural -> TextDetection)
-> Parser (Maybe TextTypes)
-> Parser (Maybe Natural -> TextDetection)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe TextTypes)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Type")
            Parser (Maybe Natural -> TextDetection)
-> Parser (Maybe Natural) -> Parser TextDetection
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ParentId")
      )

instance Prelude.Hashable TextDetection

instance Prelude.NFData TextDetection