{-# 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.Comprehend.Types.Entity
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Comprehend.Types.Entity where

import Amazonka.Comprehend.Types.BlockReference
import Amazonka.Comprehend.Types.EntityType
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

-- | Provides information about an entity.
--
-- /See:/ 'newEntity' smart constructor.
data Entity = Entity'
  { -- | The zero-based offset from the beginning of the source text to the first
    -- character in the entity.
    --
    -- This field is empty for non-text input.
    Entity -> Maybe Int
beginOffset :: Prelude.Maybe Prelude.Int,
    -- | A reference to each block for this entity. This field is empty for
    -- plain-text input.
    Entity -> Maybe [BlockReference]
blockReferences :: Prelude.Maybe [BlockReference],
    -- | The zero-based offset from the beginning of the source text to the last
    -- character in the entity.
    --
    -- This field is empty for non-text input.
    Entity -> Maybe Int
endOffset :: Prelude.Maybe Prelude.Int,
    -- | The level of confidence that Amazon Comprehend has in the accuracy of
    -- the detection.
    Entity -> Maybe Double
score :: Prelude.Maybe Prelude.Double,
    -- | The text of the entity.
    Entity -> Maybe Text
text :: Prelude.Maybe Prelude.Text,
    -- | The entity type. For entity detection using the built-in model, this
    -- field contains one of the standard entity types listed below.
    --
    -- For custom entity detection, this field contains one of the entity types
    -- that you specified when you trained your custom model.
    Entity -> Maybe EntityType
type' :: Prelude.Maybe EntityType
  }
  deriving (Entity -> Entity -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Entity -> Entity -> Bool
$c/= :: Entity -> Entity -> Bool
== :: Entity -> Entity -> Bool
$c== :: Entity -> Entity -> Bool
Prelude.Eq, ReadPrec [Entity]
ReadPrec Entity
Int -> ReadS Entity
ReadS [Entity]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Entity]
$creadListPrec :: ReadPrec [Entity]
readPrec :: ReadPrec Entity
$creadPrec :: ReadPrec Entity
readList :: ReadS [Entity]
$creadList :: ReadS [Entity]
readsPrec :: Int -> ReadS Entity
$creadsPrec :: Int -> ReadS Entity
Prelude.Read, Int -> Entity -> ShowS
[Entity] -> ShowS
Entity -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Entity] -> ShowS
$cshowList :: [Entity] -> ShowS
show :: Entity -> String
$cshow :: Entity -> String
showsPrec :: Int -> Entity -> ShowS
$cshowsPrec :: Int -> Entity -> ShowS
Prelude.Show, forall x. Rep Entity x -> Entity
forall x. Entity -> Rep Entity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Entity x -> Entity
$cfrom :: forall x. Entity -> Rep Entity x
Prelude.Generic)

-- |
-- Create a value of 'Entity' 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:
--
-- 'beginOffset', 'entity_beginOffset' - The zero-based offset from the beginning of the source text to the first
-- character in the entity.
--
-- This field is empty for non-text input.
--
-- 'blockReferences', 'entity_blockReferences' - A reference to each block for this entity. This field is empty for
-- plain-text input.
--
-- 'endOffset', 'entity_endOffset' - The zero-based offset from the beginning of the source text to the last
-- character in the entity.
--
-- This field is empty for non-text input.
--
-- 'score', 'entity_score' - The level of confidence that Amazon Comprehend has in the accuracy of
-- the detection.
--
-- 'text', 'entity_text' - The text of the entity.
--
-- 'type'', 'entity_type' - The entity type. For entity detection using the built-in model, this
-- field contains one of the standard entity types listed below.
--
-- For custom entity detection, this field contains one of the entity types
-- that you specified when you trained your custom model.
newEntity ::
  Entity
newEntity :: Entity
newEntity =
  Entity'
    { $sel:beginOffset:Entity' :: Maybe Int
beginOffset = forall a. Maybe a
Prelude.Nothing,
      $sel:blockReferences:Entity' :: Maybe [BlockReference]
blockReferences = forall a. Maybe a
Prelude.Nothing,
      $sel:endOffset:Entity' :: Maybe Int
endOffset = forall a. Maybe a
Prelude.Nothing,
      $sel:score:Entity' :: Maybe Double
score = forall a. Maybe a
Prelude.Nothing,
      $sel:text:Entity' :: Maybe Text
text = forall a. Maybe a
Prelude.Nothing,
      $sel:type':Entity' :: Maybe EntityType
type' = forall a. Maybe a
Prelude.Nothing
    }

-- | The zero-based offset from the beginning of the source text to the first
-- character in the entity.
--
-- This field is empty for non-text input.
entity_beginOffset :: Lens.Lens' Entity (Prelude.Maybe Prelude.Int)
entity_beginOffset :: Lens' Entity (Maybe Int)
entity_beginOffset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Maybe Int
beginOffset :: Maybe Int
$sel:beginOffset:Entity' :: Entity -> Maybe Int
beginOffset} -> Maybe Int
beginOffset) (\s :: Entity
s@Entity' {} Maybe Int
a -> Entity
s {$sel:beginOffset:Entity' :: Maybe Int
beginOffset = Maybe Int
a} :: Entity)

-- | A reference to each block for this entity. This field is empty for
-- plain-text input.
entity_blockReferences :: Lens.Lens' Entity (Prelude.Maybe [BlockReference])
entity_blockReferences :: Lens' Entity (Maybe [BlockReference])
entity_blockReferences = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Maybe [BlockReference]
blockReferences :: Maybe [BlockReference]
$sel:blockReferences:Entity' :: Entity -> Maybe [BlockReference]
blockReferences} -> Maybe [BlockReference]
blockReferences) (\s :: Entity
s@Entity' {} Maybe [BlockReference]
a -> Entity
s {$sel:blockReferences:Entity' :: Maybe [BlockReference]
blockReferences = Maybe [BlockReference]
a} :: Entity) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The zero-based offset from the beginning of the source text to the last
-- character in the entity.
--
-- This field is empty for non-text input.
entity_endOffset :: Lens.Lens' Entity (Prelude.Maybe Prelude.Int)
entity_endOffset :: Lens' Entity (Maybe Int)
entity_endOffset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Maybe Int
endOffset :: Maybe Int
$sel:endOffset:Entity' :: Entity -> Maybe Int
endOffset} -> Maybe Int
endOffset) (\s :: Entity
s@Entity' {} Maybe Int
a -> Entity
s {$sel:endOffset:Entity' :: Maybe Int
endOffset = Maybe Int
a} :: Entity)

-- | The level of confidence that Amazon Comprehend has in the accuracy of
-- the detection.
entity_score :: Lens.Lens' Entity (Prelude.Maybe Prelude.Double)
entity_score :: Lens' Entity (Maybe Double)
entity_score = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Maybe Double
score :: Maybe Double
$sel:score:Entity' :: Entity -> Maybe Double
score} -> Maybe Double
score) (\s :: Entity
s@Entity' {} Maybe Double
a -> Entity
s {$sel:score:Entity' :: Maybe Double
score = Maybe Double
a} :: Entity)

-- | The text of the entity.
entity_text :: Lens.Lens' Entity (Prelude.Maybe Prelude.Text)
entity_text :: Lens' Entity (Maybe Text)
entity_text = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Maybe Text
text :: Maybe Text
$sel:text:Entity' :: Entity -> Maybe Text
text} -> Maybe Text
text) (\s :: Entity
s@Entity' {} Maybe Text
a -> Entity
s {$sel:text:Entity' :: Maybe Text
text = Maybe Text
a} :: Entity)

-- | The entity type. For entity detection using the built-in model, this
-- field contains one of the standard entity types listed below.
--
-- For custom entity detection, this field contains one of the entity types
-- that you specified when you trained your custom model.
entity_type :: Lens.Lens' Entity (Prelude.Maybe EntityType)
entity_type :: Lens' Entity (Maybe EntityType)
entity_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Maybe EntityType
type' :: Maybe EntityType
$sel:type':Entity' :: Entity -> Maybe EntityType
type'} -> Maybe EntityType
type') (\s :: Entity
s@Entity' {} Maybe EntityType
a -> Entity
s {$sel:type':Entity' :: Maybe EntityType
type' = Maybe EntityType
a} :: Entity)

instance Data.FromJSON Entity where
  parseJSON :: Value -> Parser Entity
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Entity"
      ( \Object
x ->
          Maybe Int
-> Maybe [BlockReference]
-> Maybe Int
-> Maybe Double
-> Maybe Text
-> Maybe EntityType
-> Entity
Entity'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"BeginOffset")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"BlockReferences"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= 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 -> Parser (Maybe a)
Data..:? Key
"EndOffset")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Score")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Text")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Type")
      )

instance Prelude.Hashable Entity where
  hashWithSalt :: Int -> Entity -> Int
hashWithSalt Int
_salt Entity' {Maybe Double
Maybe Int
Maybe [BlockReference]
Maybe Text
Maybe EntityType
type' :: Maybe EntityType
text :: Maybe Text
score :: Maybe Double
endOffset :: Maybe Int
blockReferences :: Maybe [BlockReference]
beginOffset :: Maybe Int
$sel:type':Entity' :: Entity -> Maybe EntityType
$sel:text:Entity' :: Entity -> Maybe Text
$sel:score:Entity' :: Entity -> Maybe Double
$sel:endOffset:Entity' :: Entity -> Maybe Int
$sel:blockReferences:Entity' :: Entity -> Maybe [BlockReference]
$sel:beginOffset:Entity' :: Entity -> Maybe Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
beginOffset
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [BlockReference]
blockReferences
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
endOffset
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
score
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
text
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe EntityType
type'

instance Prelude.NFData Entity where
  rnf :: Entity -> ()
rnf Entity' {Maybe Double
Maybe Int
Maybe [BlockReference]
Maybe Text
Maybe EntityType
type' :: Maybe EntityType
text :: Maybe Text
score :: Maybe Double
endOffset :: Maybe Int
blockReferences :: Maybe [BlockReference]
beginOffset :: Maybe Int
$sel:type':Entity' :: Entity -> Maybe EntityType
$sel:text:Entity' :: Entity -> Maybe Text
$sel:score:Entity' :: Entity -> Maybe Double
$sel:endOffset:Entity' :: Entity -> Maybe Int
$sel:blockReferences:Entity' :: Entity -> Maybe [BlockReference]
$sel:beginOffset:Entity' :: Entity -> Maybe Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
beginOffset
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [BlockReference]
blockReferences
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
endOffset
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
score
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
text
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe EntityType
type'