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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes a key noun phrase.
--
-- /See:/ 'newKeyPhrase' smart constructor.
data KeyPhrase = KeyPhrase'
  { -- | A character offset in the input text that shows where the key phrase
    -- begins (the first character is at position 0). The offset returns the
    -- position of each UTF-8 code point in the string. A /code point/ is the
    -- abstract character from a particular graphical representation. For
    -- example, a multi-byte UTF-8 character maps to a single code point.
    KeyPhrase -> Maybe Int
beginOffset :: Prelude.Maybe Prelude.Int,
    -- | The text of a key noun phrase.
    KeyPhrase -> Maybe Text
text :: Prelude.Maybe Prelude.Text,
    -- | The level of confidence that Amazon Comprehend has in the accuracy of
    -- the detection.
    KeyPhrase -> Maybe Double
score :: Prelude.Maybe Prelude.Double,
    -- | A character offset in the input text where the key phrase ends. The
    -- offset returns the position of each UTF-8 code point in the string. A
    -- @code point@ is the abstract character from a particular graphical
    -- representation. For example, a multi-byte UTF-8 character maps to a
    -- single code point.
    KeyPhrase -> Maybe Int
endOffset :: Prelude.Maybe Prelude.Int
  }
  deriving (KeyPhrase -> KeyPhrase -> Bool
(KeyPhrase -> KeyPhrase -> Bool)
-> (KeyPhrase -> KeyPhrase -> Bool) -> Eq KeyPhrase
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]
(Int -> ReadS KeyPhrase)
-> ReadS [KeyPhrase]
-> ReadPrec KeyPhrase
-> ReadPrec [KeyPhrase]
-> Read 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
(Int -> KeyPhrase -> ShowS)
-> (KeyPhrase -> String)
-> ([KeyPhrase] -> ShowS)
-> Show KeyPhrase
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. KeyPhrase -> Rep KeyPhrase x)
-> (forall x. Rep KeyPhrase x -> KeyPhrase) -> Generic KeyPhrase
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' - A character offset in the input text that shows where the key phrase
-- begins (the first character is at position 0). The offset returns the
-- position of each UTF-8 code point in the string. A /code point/ is the
-- abstract character from a particular graphical representation. For
-- example, a multi-byte UTF-8 character maps to a single code point.
--
-- 'text', 'keyPhrase_text' - The text of a key noun phrase.
--
-- 'score', 'keyPhrase_score' - The level of confidence that Amazon Comprehend has in the accuracy of
-- the detection.
--
-- 'endOffset', 'keyPhrase_endOffset' - A character offset in the input text where the key phrase ends. The
-- offset returns the position of each UTF-8 code point in the string. A
-- @code point@ is the abstract character from a particular graphical
-- representation. For example, a multi-byte UTF-8 character maps to a
-- single code point.
newKeyPhrase ::
  KeyPhrase
newKeyPhrase :: KeyPhrase
newKeyPhrase =
  KeyPhrase' :: Maybe Int -> Maybe Text -> Maybe Double -> Maybe Int -> KeyPhrase
KeyPhrase'
    { $sel:beginOffset:KeyPhrase' :: Maybe Int
beginOffset = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:text:KeyPhrase' :: Maybe Text
text = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:score:KeyPhrase' :: Maybe Double
score = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:endOffset:KeyPhrase' :: Maybe Int
endOffset = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | A character offset in the input text that shows where the key phrase
-- begins (the first character is at position 0). The offset returns the
-- position of each UTF-8 code point in the string. A /code point/ is the
-- abstract character from a particular graphical representation. For
-- example, a multi-byte UTF-8 character maps to a single code point.
keyPhrase_beginOffset :: Lens.Lens' KeyPhrase (Prelude.Maybe Prelude.Int)
keyPhrase_beginOffset :: (Maybe Int -> f (Maybe Int)) -> KeyPhrase -> f KeyPhrase
keyPhrase_beginOffset = (KeyPhrase -> Maybe Int)
-> (KeyPhrase -> Maybe Int -> KeyPhrase)
-> Lens KeyPhrase KeyPhrase (Maybe Int) (Maybe Int)
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 text of a key noun phrase.
keyPhrase_text :: Lens.Lens' KeyPhrase (Prelude.Maybe Prelude.Text)
keyPhrase_text :: (Maybe Text -> f (Maybe Text)) -> KeyPhrase -> f KeyPhrase
keyPhrase_text = (KeyPhrase -> Maybe Text)
-> (KeyPhrase -> Maybe Text -> KeyPhrase)
-> Lens KeyPhrase KeyPhrase (Maybe Text) (Maybe 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)

-- | 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 :: (Maybe Double -> f (Maybe Double)) -> KeyPhrase -> f KeyPhrase
keyPhrase_score = (KeyPhrase -> Maybe Double)
-> (KeyPhrase -> Maybe Double -> KeyPhrase)
-> Lens KeyPhrase KeyPhrase (Maybe Double) (Maybe Double)
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)

-- | A character offset in the input text where the key phrase ends. The
-- offset returns the position of each UTF-8 code point in the string. A
-- @code point@ is the abstract character from a particular graphical
-- representation. For example, a multi-byte UTF-8 character maps to a
-- single code point.
keyPhrase_endOffset :: Lens.Lens' KeyPhrase (Prelude.Maybe Prelude.Int)
keyPhrase_endOffset :: (Maybe Int -> f (Maybe Int)) -> KeyPhrase -> f KeyPhrase
keyPhrase_endOffset = (KeyPhrase -> Maybe Int)
-> (KeyPhrase -> Maybe Int -> KeyPhrase)
-> Lens KeyPhrase KeyPhrase (Maybe Int) (Maybe Int)
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)

instance Core.FromJSON KeyPhrase where
  parseJSON :: Value -> Parser KeyPhrase
parseJSON =
    String -> (Object -> Parser KeyPhrase) -> Value -> Parser KeyPhrase
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"KeyPhrase"
      ( \Object
x ->
          Maybe Int -> Maybe Text -> Maybe Double -> Maybe Int -> KeyPhrase
KeyPhrase'
            (Maybe Int -> Maybe Text -> Maybe Double -> Maybe Int -> KeyPhrase)
-> Parser (Maybe Int)
-> Parser (Maybe Text -> Maybe Double -> Maybe Int -> KeyPhrase)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"BeginOffset")
            Parser (Maybe Text -> Maybe Double -> Maybe Int -> KeyPhrase)
-> Parser (Maybe Text)
-> Parser (Maybe Double -> Maybe Int -> KeyPhrase)
forall (f :: * -> *) a b. Applicative f => 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
"Text")
            Parser (Maybe Double -> Maybe Int -> KeyPhrase)
-> Parser (Maybe Double) -> Parser (Maybe Int -> KeyPhrase)
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
"Score")
            Parser (Maybe Int -> KeyPhrase)
-> Parser (Maybe Int) -> Parser KeyPhrase
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EndOffset")
      )

instance Prelude.Hashable KeyPhrase

instance Prelude.NFData KeyPhrase