{-# 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.KeyPhrase
-- 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.KeyPhrase where

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

-- | Describes a key noun phrase.
--
-- /See:/ 'newKeyPhrase' smart constructor.
data KeyPhrase = KeyPhrase'
  { -- | The zero-based offset from the beginning of the source text to the first
    -- character in the key phrase.
    KeyPhrase -> Maybe Int
beginOffset :: Prelude.Maybe Prelude.Int,
    -- | The zero-based offset from the beginning of the source text to the last
    -- character in the key phrase.
    KeyPhrase -> Maybe Int
endOffset :: Prelude.Maybe Prelude.Int,
    -- | The level of confidence that Amazon Comprehend has in the accuracy of
    -- the detection.
    KeyPhrase -> Maybe Double
score :: Prelude.Maybe Prelude.Double,
    -- | The text of a key noun phrase.
    KeyPhrase -> Maybe Text
text :: Prelude.Maybe Prelude.Text
  }
  deriving (KeyPhrase -> KeyPhrase -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: KeyPhrase -> KeyPhrase -> Bool
$c/= :: KeyPhrase -> KeyPhrase -> Bool
== :: KeyPhrase -> KeyPhrase -> Bool
$c== :: KeyPhrase -> KeyPhrase -> Bool
Prelude.Eq, ReadPrec [KeyPhrase]
ReadPrec KeyPhrase
Int -> ReadS KeyPhrase
ReadS [KeyPhrase]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [KeyPhrase]
$creadListPrec :: ReadPrec [KeyPhrase]
readPrec :: ReadPrec KeyPhrase
$creadPrec :: ReadPrec KeyPhrase
readList :: ReadS [KeyPhrase]
$creadList :: ReadS [KeyPhrase]
readsPrec :: Int -> ReadS KeyPhrase
$creadsPrec :: Int -> ReadS KeyPhrase
Prelude.Read, Int -> KeyPhrase -> ShowS
[KeyPhrase] -> ShowS
KeyPhrase -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KeyPhrase] -> ShowS
$cshowList :: [KeyPhrase] -> ShowS
show :: KeyPhrase -> String
$cshow :: KeyPhrase -> String
showsPrec :: Int -> KeyPhrase -> ShowS
$cshowsPrec :: Int -> KeyPhrase -> ShowS
Prelude.Show, forall x. Rep KeyPhrase x -> KeyPhrase
forall x. KeyPhrase -> Rep KeyPhrase x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep KeyPhrase x -> KeyPhrase
$cfrom :: forall x. KeyPhrase -> Rep KeyPhrase x
Prelude.Generic)

-- |
-- Create a value of 'KeyPhrase' 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', 'keyPhrase_beginOffset' - The zero-based offset from the beginning of the source text to the first
-- character in the key phrase.
--
-- 'endOffset', 'keyPhrase_endOffset' - The zero-based offset from the beginning of the source text to the last
-- character in the key phrase.
--
-- 'score', 'keyPhrase_score' - The level of confidence that Amazon Comprehend has in the accuracy of
-- the detection.
--
-- 'text', 'keyPhrase_text' - The text of a key noun phrase.
newKeyPhrase ::
  KeyPhrase
newKeyPhrase :: KeyPhrase
newKeyPhrase =
  KeyPhrase'
    { $sel:beginOffset:KeyPhrase' :: Maybe Int
beginOffset = forall a. Maybe a
Prelude.Nothing,
      $sel:endOffset:KeyPhrase' :: Maybe Int
endOffset = forall a. Maybe a
Prelude.Nothing,
      $sel:score:KeyPhrase' :: Maybe Double
score = forall a. Maybe a
Prelude.Nothing,
      $sel:text:KeyPhrase' :: Maybe Text
text = forall a. Maybe a
Prelude.Nothing
    }

-- | The zero-based offset from the beginning of the source text to the first
-- character in the key phrase.
keyPhrase_beginOffset :: Lens.Lens' KeyPhrase (Prelude.Maybe Prelude.Int)
keyPhrase_beginOffset :: Lens' KeyPhrase (Maybe Int)
keyPhrase_beginOffset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyPhrase' {Maybe Int
beginOffset :: Maybe Int
$sel:beginOffset:KeyPhrase' :: KeyPhrase -> Maybe Int
beginOffset} -> Maybe Int
beginOffset) (\s :: KeyPhrase
s@KeyPhrase' {} Maybe Int
a -> KeyPhrase
s {$sel:beginOffset:KeyPhrase' :: Maybe Int
beginOffset = Maybe Int
a} :: KeyPhrase)

-- | The zero-based offset from the beginning of the source text to the last
-- character in the key phrase.
keyPhrase_endOffset :: Lens.Lens' KeyPhrase (Prelude.Maybe Prelude.Int)
keyPhrase_endOffset :: Lens' KeyPhrase (Maybe Int)
keyPhrase_endOffset = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyPhrase' {Maybe Int
endOffset :: Maybe Int
$sel:endOffset:KeyPhrase' :: KeyPhrase -> Maybe Int
endOffset} -> Maybe Int
endOffset) (\s :: KeyPhrase
s@KeyPhrase' {} Maybe Int
a -> KeyPhrase
s {$sel:endOffset:KeyPhrase' :: Maybe Int
endOffset = Maybe Int
a} :: KeyPhrase)

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

-- | The text of a key noun phrase.
keyPhrase_text :: Lens.Lens' KeyPhrase (Prelude.Maybe Prelude.Text)
keyPhrase_text :: Lens' KeyPhrase (Maybe Text)
keyPhrase_text = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\KeyPhrase' {Maybe Text
text :: Maybe Text
$sel:text:KeyPhrase' :: KeyPhrase -> Maybe Text
text} -> Maybe Text
text) (\s :: KeyPhrase
s@KeyPhrase' {} Maybe Text
a -> KeyPhrase
s {$sel:text:KeyPhrase' :: Maybe Text
text = Maybe Text
a} :: KeyPhrase)

instance Data.FromJSON KeyPhrase where
  parseJSON :: Value -> Parser KeyPhrase
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"KeyPhrase"
      ( \Object
x ->
          Maybe Int -> Maybe Int -> Maybe Double -> Maybe Text -> KeyPhrase
KeyPhrase'
            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
"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")
      )

instance Prelude.Hashable KeyPhrase where
  hashWithSalt :: Int -> KeyPhrase -> Int
hashWithSalt Int
_salt KeyPhrase' {Maybe Double
Maybe Int
Maybe Text
text :: Maybe Text
score :: Maybe Double
endOffset :: Maybe Int
beginOffset :: Maybe Int
$sel:text:KeyPhrase' :: KeyPhrase -> Maybe Text
$sel:score:KeyPhrase' :: KeyPhrase -> Maybe Double
$sel:endOffset:KeyPhrase' :: KeyPhrase -> Maybe Int
$sel:beginOffset:KeyPhrase' :: KeyPhrase -> 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 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

instance Prelude.NFData KeyPhrase where
  rnf :: KeyPhrase -> ()
rnf KeyPhrase' {Maybe Double
Maybe Int
Maybe Text
text :: Maybe Text
score :: Maybe Double
endOffset :: Maybe Int
beginOffset :: Maybe Int
$sel:text:KeyPhrase' :: KeyPhrase -> Maybe Text
$sel:score:KeyPhrase' :: KeyPhrase -> Maybe Double
$sel:endOffset:KeyPhrase' :: KeyPhrase -> Maybe Int
$sel:beginOffset:KeyPhrase' :: KeyPhrase -> 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 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