{-# 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.Transcribe.Types.TranscriptFilter
-- 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.Transcribe.Types.TranscriptFilter 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
import Amazonka.Transcribe.Types.AbsoluteTimeRange
import Amazonka.Transcribe.Types.ParticipantRole
import Amazonka.Transcribe.Types.RelativeTimeRange
import Amazonka.Transcribe.Types.TranscriptFilterType

-- | Flag the presence or absence of specific words or phrases detected in
-- your Call Analytics transcription output.
--
-- Rules using @TranscriptFilter@ are designed to match:
--
-- -   Custom words or phrases spoken by the agent, the customer, or both
--
-- -   Custom words or phrases __not__ spoken by the agent, the customer,
--     or either
--
-- -   Custom words or phrases that occur at a specific time frame
--
-- See
-- <https://docs.aws.amazon.com/transcribe/latest/dg/tca-categories-batch.html#tca-rules-batch Rule criteria for batch categories>
-- and
-- <https://docs.aws.amazon.com/transcribe/latest/dg/tca-categories-stream.html#tca-rules-stream Rule criteria for streaming categories>
-- for usage examples.
--
-- /See:/ 'newTranscriptFilter' smart constructor.
data TranscriptFilter = TranscriptFilter'
  { -- | Makes it possible to specify a time range (in milliseconds) in your
    -- audio, during which you want to search for the specified key words or
    -- phrases. See for more detail.
    TranscriptFilter -> Maybe AbsoluteTimeRange
absoluteTimeRange :: Prelude.Maybe AbsoluteTimeRange,
    -- | Set to @TRUE@ to flag the absence of the phrase that you specified in
    -- your request. Set to @FALSE@ to flag the presence of the phrase that you
    -- specified in your request.
    TranscriptFilter -> Maybe Bool
negate :: Prelude.Maybe Prelude.Bool,
    -- | Specify the participant that you want to flag. Omitting this parameter
    -- is equivalent to specifying both participants.
    TranscriptFilter -> Maybe ParticipantRole
participantRole :: Prelude.Maybe ParticipantRole,
    -- | Makes it possible to specify a time range (in percentage) in your media
    -- file, during which you want to search for the specified key words or
    -- phrases. See for more detail.
    TranscriptFilter -> Maybe RelativeTimeRange
relativeTimeRange :: Prelude.Maybe RelativeTimeRange,
    -- | Flag the presence or absence of an exact match to the phrases that you
    -- specify. For example, if you specify the phrase \"speak to a manager\"
    -- as your @Targets@ value, only that exact phrase is flagged.
    --
    -- Note that semantic matching is not supported. For example, if your
    -- customer says \"speak to /the/ manager\", instead of \"speak to /a/
    -- manager\", your content is not flagged.
    TranscriptFilter -> TranscriptFilterType
transcriptFilterType :: TranscriptFilterType,
    -- | Specify the phrases that you want to flag.
    TranscriptFilter -> NonEmpty Text
targets :: Prelude.NonEmpty Prelude.Text
  }
  deriving (TranscriptFilter -> TranscriptFilter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TranscriptFilter -> TranscriptFilter -> Bool
$c/= :: TranscriptFilter -> TranscriptFilter -> Bool
== :: TranscriptFilter -> TranscriptFilter -> Bool
$c== :: TranscriptFilter -> TranscriptFilter -> Bool
Prelude.Eq, ReadPrec [TranscriptFilter]
ReadPrec TranscriptFilter
Int -> ReadS TranscriptFilter
ReadS [TranscriptFilter]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TranscriptFilter]
$creadListPrec :: ReadPrec [TranscriptFilter]
readPrec :: ReadPrec TranscriptFilter
$creadPrec :: ReadPrec TranscriptFilter
readList :: ReadS [TranscriptFilter]
$creadList :: ReadS [TranscriptFilter]
readsPrec :: Int -> ReadS TranscriptFilter
$creadsPrec :: Int -> ReadS TranscriptFilter
Prelude.Read, Int -> TranscriptFilter -> ShowS
[TranscriptFilter] -> ShowS
TranscriptFilter -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TranscriptFilter] -> ShowS
$cshowList :: [TranscriptFilter] -> ShowS
show :: TranscriptFilter -> String
$cshow :: TranscriptFilter -> String
showsPrec :: Int -> TranscriptFilter -> ShowS
$cshowsPrec :: Int -> TranscriptFilter -> ShowS
Prelude.Show, forall x. Rep TranscriptFilter x -> TranscriptFilter
forall x. TranscriptFilter -> Rep TranscriptFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TranscriptFilter x -> TranscriptFilter
$cfrom :: forall x. TranscriptFilter -> Rep TranscriptFilter x
Prelude.Generic)

-- |
-- Create a value of 'TranscriptFilter' 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:
--
-- 'absoluteTimeRange', 'transcriptFilter_absoluteTimeRange' - Makes it possible to specify a time range (in milliseconds) in your
-- audio, during which you want to search for the specified key words or
-- phrases. See for more detail.
--
-- 'negate', 'transcriptFilter_negate' - Set to @TRUE@ to flag the absence of the phrase that you specified in
-- your request. Set to @FALSE@ to flag the presence of the phrase that you
-- specified in your request.
--
-- 'participantRole', 'transcriptFilter_participantRole' - Specify the participant that you want to flag. Omitting this parameter
-- is equivalent to specifying both participants.
--
-- 'relativeTimeRange', 'transcriptFilter_relativeTimeRange' - Makes it possible to specify a time range (in percentage) in your media
-- file, during which you want to search for the specified key words or
-- phrases. See for more detail.
--
-- 'transcriptFilterType', 'transcriptFilter_transcriptFilterType' - Flag the presence or absence of an exact match to the phrases that you
-- specify. For example, if you specify the phrase \"speak to a manager\"
-- as your @Targets@ value, only that exact phrase is flagged.
--
-- Note that semantic matching is not supported. For example, if your
-- customer says \"speak to /the/ manager\", instead of \"speak to /a/
-- manager\", your content is not flagged.
--
-- 'targets', 'transcriptFilter_targets' - Specify the phrases that you want to flag.
newTranscriptFilter ::
  -- | 'transcriptFilterType'
  TranscriptFilterType ->
  -- | 'targets'
  Prelude.NonEmpty Prelude.Text ->
  TranscriptFilter
newTranscriptFilter :: TranscriptFilterType -> NonEmpty Text -> TranscriptFilter
newTranscriptFilter TranscriptFilterType
pTranscriptFilterType_ NonEmpty Text
pTargets_ =
  TranscriptFilter'
    { $sel:absoluteTimeRange:TranscriptFilter' :: Maybe AbsoluteTimeRange
absoluteTimeRange =
        forall a. Maybe a
Prelude.Nothing,
      $sel:negate:TranscriptFilter' :: Maybe Bool
negate = forall a. Maybe a
Prelude.Nothing,
      $sel:participantRole:TranscriptFilter' :: Maybe ParticipantRole
participantRole = forall a. Maybe a
Prelude.Nothing,
      $sel:relativeTimeRange:TranscriptFilter' :: Maybe RelativeTimeRange
relativeTimeRange = forall a. Maybe a
Prelude.Nothing,
      $sel:transcriptFilterType:TranscriptFilter' :: TranscriptFilterType
transcriptFilterType = TranscriptFilterType
pTranscriptFilterType_,
      $sel:targets:TranscriptFilter' :: NonEmpty Text
targets = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pTargets_
    }

-- | Makes it possible to specify a time range (in milliseconds) in your
-- audio, during which you want to search for the specified key words or
-- phrases. See for more detail.
transcriptFilter_absoluteTimeRange :: Lens.Lens' TranscriptFilter (Prelude.Maybe AbsoluteTimeRange)
transcriptFilter_absoluteTimeRange :: Lens' TranscriptFilter (Maybe AbsoluteTimeRange)
transcriptFilter_absoluteTimeRange = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TranscriptFilter' {Maybe AbsoluteTimeRange
absoluteTimeRange :: Maybe AbsoluteTimeRange
$sel:absoluteTimeRange:TranscriptFilter' :: TranscriptFilter -> Maybe AbsoluteTimeRange
absoluteTimeRange} -> Maybe AbsoluteTimeRange
absoluteTimeRange) (\s :: TranscriptFilter
s@TranscriptFilter' {} Maybe AbsoluteTimeRange
a -> TranscriptFilter
s {$sel:absoluteTimeRange:TranscriptFilter' :: Maybe AbsoluteTimeRange
absoluteTimeRange = Maybe AbsoluteTimeRange
a} :: TranscriptFilter)

-- | Set to @TRUE@ to flag the absence of the phrase that you specified in
-- your request. Set to @FALSE@ to flag the presence of the phrase that you
-- specified in your request.
transcriptFilter_negate :: Lens.Lens' TranscriptFilter (Prelude.Maybe Prelude.Bool)
transcriptFilter_negate :: Lens' TranscriptFilter (Maybe Bool)
transcriptFilter_negate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TranscriptFilter' {Maybe Bool
negate :: Maybe Bool
$sel:negate:TranscriptFilter' :: TranscriptFilter -> Maybe Bool
negate} -> Maybe Bool
negate) (\s :: TranscriptFilter
s@TranscriptFilter' {} Maybe Bool
a -> TranscriptFilter
s {$sel:negate:TranscriptFilter' :: Maybe Bool
negate = Maybe Bool
a} :: TranscriptFilter)

-- | Specify the participant that you want to flag. Omitting this parameter
-- is equivalent to specifying both participants.
transcriptFilter_participantRole :: Lens.Lens' TranscriptFilter (Prelude.Maybe ParticipantRole)
transcriptFilter_participantRole :: Lens' TranscriptFilter (Maybe ParticipantRole)
transcriptFilter_participantRole = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TranscriptFilter' {Maybe ParticipantRole
participantRole :: Maybe ParticipantRole
$sel:participantRole:TranscriptFilter' :: TranscriptFilter -> Maybe ParticipantRole
participantRole} -> Maybe ParticipantRole
participantRole) (\s :: TranscriptFilter
s@TranscriptFilter' {} Maybe ParticipantRole
a -> TranscriptFilter
s {$sel:participantRole:TranscriptFilter' :: Maybe ParticipantRole
participantRole = Maybe ParticipantRole
a} :: TranscriptFilter)

-- | Makes it possible to specify a time range (in percentage) in your media
-- file, during which you want to search for the specified key words or
-- phrases. See for more detail.
transcriptFilter_relativeTimeRange :: Lens.Lens' TranscriptFilter (Prelude.Maybe RelativeTimeRange)
transcriptFilter_relativeTimeRange :: Lens' TranscriptFilter (Maybe RelativeTimeRange)
transcriptFilter_relativeTimeRange = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TranscriptFilter' {Maybe RelativeTimeRange
relativeTimeRange :: Maybe RelativeTimeRange
$sel:relativeTimeRange:TranscriptFilter' :: TranscriptFilter -> Maybe RelativeTimeRange
relativeTimeRange} -> Maybe RelativeTimeRange
relativeTimeRange) (\s :: TranscriptFilter
s@TranscriptFilter' {} Maybe RelativeTimeRange
a -> TranscriptFilter
s {$sel:relativeTimeRange:TranscriptFilter' :: Maybe RelativeTimeRange
relativeTimeRange = Maybe RelativeTimeRange
a} :: TranscriptFilter)

-- | Flag the presence or absence of an exact match to the phrases that you
-- specify. For example, if you specify the phrase \"speak to a manager\"
-- as your @Targets@ value, only that exact phrase is flagged.
--
-- Note that semantic matching is not supported. For example, if your
-- customer says \"speak to /the/ manager\", instead of \"speak to /a/
-- manager\", your content is not flagged.
transcriptFilter_transcriptFilterType :: Lens.Lens' TranscriptFilter TranscriptFilterType
transcriptFilter_transcriptFilterType :: Lens' TranscriptFilter TranscriptFilterType
transcriptFilter_transcriptFilterType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TranscriptFilter' {TranscriptFilterType
transcriptFilterType :: TranscriptFilterType
$sel:transcriptFilterType:TranscriptFilter' :: TranscriptFilter -> TranscriptFilterType
transcriptFilterType} -> TranscriptFilterType
transcriptFilterType) (\s :: TranscriptFilter
s@TranscriptFilter' {} TranscriptFilterType
a -> TranscriptFilter
s {$sel:transcriptFilterType:TranscriptFilter' :: TranscriptFilterType
transcriptFilterType = TranscriptFilterType
a} :: TranscriptFilter)

-- | Specify the phrases that you want to flag.
transcriptFilter_targets :: Lens.Lens' TranscriptFilter (Prelude.NonEmpty Prelude.Text)
transcriptFilter_targets :: Lens' TranscriptFilter (NonEmpty Text)
transcriptFilter_targets = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TranscriptFilter' {NonEmpty Text
targets :: NonEmpty Text
$sel:targets:TranscriptFilter' :: TranscriptFilter -> NonEmpty Text
targets} -> NonEmpty Text
targets) (\s :: TranscriptFilter
s@TranscriptFilter' {} NonEmpty Text
a -> TranscriptFilter
s {$sel:targets:TranscriptFilter' :: NonEmpty Text
targets = NonEmpty Text
a} :: TranscriptFilter) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON TranscriptFilter where
  parseJSON :: Value -> Parser TranscriptFilter
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TranscriptFilter"
      ( \Object
x ->
          Maybe AbsoluteTimeRange
-> Maybe Bool
-> Maybe ParticipantRole
-> Maybe RelativeTimeRange
-> TranscriptFilterType
-> NonEmpty Text
-> TranscriptFilter
TranscriptFilter'
            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
"AbsoluteTimeRange")
            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
"Negate")
            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
"ParticipantRole")
            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
"RelativeTimeRange")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"TranscriptFilterType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Targets")
      )

instance Prelude.Hashable TranscriptFilter where
  hashWithSalt :: Int -> TranscriptFilter -> Int
hashWithSalt Int
_salt TranscriptFilter' {Maybe Bool
Maybe AbsoluteTimeRange
Maybe ParticipantRole
Maybe RelativeTimeRange
NonEmpty Text
TranscriptFilterType
targets :: NonEmpty Text
transcriptFilterType :: TranscriptFilterType
relativeTimeRange :: Maybe RelativeTimeRange
participantRole :: Maybe ParticipantRole
negate :: Maybe Bool
absoluteTimeRange :: Maybe AbsoluteTimeRange
$sel:targets:TranscriptFilter' :: TranscriptFilter -> NonEmpty Text
$sel:transcriptFilterType:TranscriptFilter' :: TranscriptFilter -> TranscriptFilterType
$sel:relativeTimeRange:TranscriptFilter' :: TranscriptFilter -> Maybe RelativeTimeRange
$sel:participantRole:TranscriptFilter' :: TranscriptFilter -> Maybe ParticipantRole
$sel:negate:TranscriptFilter' :: TranscriptFilter -> Maybe Bool
$sel:absoluteTimeRange:TranscriptFilter' :: TranscriptFilter -> Maybe AbsoluteTimeRange
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AbsoluteTimeRange
absoluteTimeRange
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
negate
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ParticipantRole
participantRole
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RelativeTimeRange
relativeTimeRange
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` TranscriptFilterType
transcriptFilterType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
targets

instance Prelude.NFData TranscriptFilter where
  rnf :: TranscriptFilter -> ()
rnf TranscriptFilter' {Maybe Bool
Maybe AbsoluteTimeRange
Maybe ParticipantRole
Maybe RelativeTimeRange
NonEmpty Text
TranscriptFilterType
targets :: NonEmpty Text
transcriptFilterType :: TranscriptFilterType
relativeTimeRange :: Maybe RelativeTimeRange
participantRole :: Maybe ParticipantRole
negate :: Maybe Bool
absoluteTimeRange :: Maybe AbsoluteTimeRange
$sel:targets:TranscriptFilter' :: TranscriptFilter -> NonEmpty Text
$sel:transcriptFilterType:TranscriptFilter' :: TranscriptFilter -> TranscriptFilterType
$sel:relativeTimeRange:TranscriptFilter' :: TranscriptFilter -> Maybe RelativeTimeRange
$sel:participantRole:TranscriptFilter' :: TranscriptFilter -> Maybe ParticipantRole
$sel:negate:TranscriptFilter' :: TranscriptFilter -> Maybe Bool
$sel:absoluteTimeRange:TranscriptFilter' :: TranscriptFilter -> Maybe AbsoluteTimeRange
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe AbsoluteTimeRange
absoluteTimeRange
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
negate
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ParticipantRole
participantRole
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe RelativeTimeRange
relativeTimeRange
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf TranscriptFilterType
transcriptFilterType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
targets

instance Data.ToJSON TranscriptFilter where
  toJSON :: TranscriptFilter -> Value
toJSON TranscriptFilter' {Maybe Bool
Maybe AbsoluteTimeRange
Maybe ParticipantRole
Maybe RelativeTimeRange
NonEmpty Text
TranscriptFilterType
targets :: NonEmpty Text
transcriptFilterType :: TranscriptFilterType
relativeTimeRange :: Maybe RelativeTimeRange
participantRole :: Maybe ParticipantRole
negate :: Maybe Bool
absoluteTimeRange :: Maybe AbsoluteTimeRange
$sel:targets:TranscriptFilter' :: TranscriptFilter -> NonEmpty Text
$sel:transcriptFilterType:TranscriptFilter' :: TranscriptFilter -> TranscriptFilterType
$sel:relativeTimeRange:TranscriptFilter' :: TranscriptFilter -> Maybe RelativeTimeRange
$sel:participantRole:TranscriptFilter' :: TranscriptFilter -> Maybe ParticipantRole
$sel:negate:TranscriptFilter' :: TranscriptFilter -> Maybe Bool
$sel:absoluteTimeRange:TranscriptFilter' :: TranscriptFilter -> Maybe AbsoluteTimeRange
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AbsoluteTimeRange" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AbsoluteTimeRange
absoluteTimeRange,
            (Key
"Negate" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
negate,
            (Key
"ParticipantRole" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ParticipantRole
participantRole,
            (Key
"RelativeTimeRange" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RelativeTimeRange
relativeTimeRange,
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"TranscriptFilterType"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= TranscriptFilterType
transcriptFilterType
              ),
            forall a. a -> Maybe a
Prelude.Just (Key
"Targets" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
targets)
          ]
      )