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

import Amazonka.Comprehend.Types.PartOfSpeechTag
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a work in the input text that was recognized and assigned a
-- part of speech. There is one syntax token record for each word in the
-- source text.
--
-- /See:/ 'newSyntaxToken' smart constructor.
data SyntaxToken = SyntaxToken'
  { -- | The zero-based offset from the beginning of the source text to the first
    -- character in the word.
    SyntaxToken -> Maybe Int
beginOffset :: Prelude.Maybe Prelude.Int,
    -- | The word that was recognized in the source text.
    SyntaxToken -> Maybe Text
text :: Prelude.Maybe Prelude.Text,
    -- | A unique identifier for a token.
    SyntaxToken -> Maybe Int
tokenId :: Prelude.Maybe Prelude.Int,
    -- | The zero-based offset from the beginning of the source text to the last
    -- character in the word.
    SyntaxToken -> Maybe Int
endOffset :: Prelude.Maybe Prelude.Int,
    -- | Provides the part of speech label and the confidence level that Amazon
    -- Comprehend has that the part of speech was correctly identified. For
    -- more information, see how-syntax.
    SyntaxToken -> Maybe PartOfSpeechTag
partOfSpeech :: Prelude.Maybe PartOfSpeechTag
  }
  deriving (SyntaxToken -> SyntaxToken -> Bool
(SyntaxToken -> SyntaxToken -> Bool)
-> (SyntaxToken -> SyntaxToken -> Bool) -> Eq SyntaxToken
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SyntaxToken -> SyntaxToken -> Bool
$c/= :: SyntaxToken -> SyntaxToken -> Bool
== :: SyntaxToken -> SyntaxToken -> Bool
$c== :: SyntaxToken -> SyntaxToken -> Bool
Prelude.Eq, ReadPrec [SyntaxToken]
ReadPrec SyntaxToken
Int -> ReadS SyntaxToken
ReadS [SyntaxToken]
(Int -> ReadS SyntaxToken)
-> ReadS [SyntaxToken]
-> ReadPrec SyntaxToken
-> ReadPrec [SyntaxToken]
-> Read SyntaxToken
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SyntaxToken]
$creadListPrec :: ReadPrec [SyntaxToken]
readPrec :: ReadPrec SyntaxToken
$creadPrec :: ReadPrec SyntaxToken
readList :: ReadS [SyntaxToken]
$creadList :: ReadS [SyntaxToken]
readsPrec :: Int -> ReadS SyntaxToken
$creadsPrec :: Int -> ReadS SyntaxToken
Prelude.Read, Int -> SyntaxToken -> ShowS
[SyntaxToken] -> ShowS
SyntaxToken -> String
(Int -> SyntaxToken -> ShowS)
-> (SyntaxToken -> String)
-> ([SyntaxToken] -> ShowS)
-> Show SyntaxToken
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SyntaxToken] -> ShowS
$cshowList :: [SyntaxToken] -> ShowS
show :: SyntaxToken -> String
$cshow :: SyntaxToken -> String
showsPrec :: Int -> SyntaxToken -> ShowS
$cshowsPrec :: Int -> SyntaxToken -> ShowS
Prelude.Show, (forall x. SyntaxToken -> Rep SyntaxToken x)
-> (forall x. Rep SyntaxToken x -> SyntaxToken)
-> Generic SyntaxToken
forall x. Rep SyntaxToken x -> SyntaxToken
forall x. SyntaxToken -> Rep SyntaxToken x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SyntaxToken x -> SyntaxToken
$cfrom :: forall x. SyntaxToken -> Rep SyntaxToken x
Prelude.Generic)

-- |
-- Create a value of 'SyntaxToken' 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', 'syntaxToken_beginOffset' - The zero-based offset from the beginning of the source text to the first
-- character in the word.
--
-- 'text', 'syntaxToken_text' - The word that was recognized in the source text.
--
-- 'tokenId', 'syntaxToken_tokenId' - A unique identifier for a token.
--
-- 'endOffset', 'syntaxToken_endOffset' - The zero-based offset from the beginning of the source text to the last
-- character in the word.
--
-- 'partOfSpeech', 'syntaxToken_partOfSpeech' - Provides the part of speech label and the confidence level that Amazon
-- Comprehend has that the part of speech was correctly identified. For
-- more information, see how-syntax.
newSyntaxToken ::
  SyntaxToken
newSyntaxToken :: SyntaxToken
newSyntaxToken =
  SyntaxToken' :: Maybe Int
-> Maybe Text
-> Maybe Int
-> Maybe Int
-> Maybe PartOfSpeechTag
-> SyntaxToken
SyntaxToken'
    { $sel:beginOffset:SyntaxToken' :: Maybe Int
beginOffset = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:text:SyntaxToken' :: Maybe Text
text = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:tokenId:SyntaxToken' :: Maybe Int
tokenId = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:endOffset:SyntaxToken' :: Maybe Int
endOffset = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:partOfSpeech:SyntaxToken' :: Maybe PartOfSpeechTag
partOfSpeech = Maybe PartOfSpeechTag
forall a. Maybe a
Prelude.Nothing
    }

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

-- | The word that was recognized in the source text.
syntaxToken_text :: Lens.Lens' SyntaxToken (Prelude.Maybe Prelude.Text)
syntaxToken_text :: (Maybe Text -> f (Maybe Text)) -> SyntaxToken -> f SyntaxToken
syntaxToken_text = (SyntaxToken -> Maybe Text)
-> (SyntaxToken -> Maybe Text -> SyntaxToken)
-> Lens SyntaxToken SyntaxToken (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SyntaxToken' {Maybe Text
text :: Maybe Text
$sel:text:SyntaxToken' :: SyntaxToken -> Maybe Text
text} -> Maybe Text
text) (\s :: SyntaxToken
s@SyntaxToken' {} Maybe Text
a -> SyntaxToken
s {$sel:text:SyntaxToken' :: Maybe Text
text = Maybe Text
a} :: SyntaxToken)

-- | A unique identifier for a token.
syntaxToken_tokenId :: Lens.Lens' SyntaxToken (Prelude.Maybe Prelude.Int)
syntaxToken_tokenId :: (Maybe Int -> f (Maybe Int)) -> SyntaxToken -> f SyntaxToken
syntaxToken_tokenId = (SyntaxToken -> Maybe Int)
-> (SyntaxToken -> Maybe Int -> SyntaxToken)
-> Lens SyntaxToken SyntaxToken (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SyntaxToken' {Maybe Int
tokenId :: Maybe Int
$sel:tokenId:SyntaxToken' :: SyntaxToken -> Maybe Int
tokenId} -> Maybe Int
tokenId) (\s :: SyntaxToken
s@SyntaxToken' {} Maybe Int
a -> SyntaxToken
s {$sel:tokenId:SyntaxToken' :: Maybe Int
tokenId = Maybe Int
a} :: SyntaxToken)

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

-- | Provides the part of speech label and the confidence level that Amazon
-- Comprehend has that the part of speech was correctly identified. For
-- more information, see how-syntax.
syntaxToken_partOfSpeech :: Lens.Lens' SyntaxToken (Prelude.Maybe PartOfSpeechTag)
syntaxToken_partOfSpeech :: (Maybe PartOfSpeechTag -> f (Maybe PartOfSpeechTag))
-> SyntaxToken -> f SyntaxToken
syntaxToken_partOfSpeech = (SyntaxToken -> Maybe PartOfSpeechTag)
-> (SyntaxToken -> Maybe PartOfSpeechTag -> SyntaxToken)
-> Lens
     SyntaxToken
     SyntaxToken
     (Maybe PartOfSpeechTag)
     (Maybe PartOfSpeechTag)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SyntaxToken' {Maybe PartOfSpeechTag
partOfSpeech :: Maybe PartOfSpeechTag
$sel:partOfSpeech:SyntaxToken' :: SyntaxToken -> Maybe PartOfSpeechTag
partOfSpeech} -> Maybe PartOfSpeechTag
partOfSpeech) (\s :: SyntaxToken
s@SyntaxToken' {} Maybe PartOfSpeechTag
a -> SyntaxToken
s {$sel:partOfSpeech:SyntaxToken' :: Maybe PartOfSpeechTag
partOfSpeech = Maybe PartOfSpeechTag
a} :: SyntaxToken)

instance Core.FromJSON SyntaxToken where
  parseJSON :: Value -> Parser SyntaxToken
parseJSON =
    String
-> (Object -> Parser SyntaxToken) -> Value -> Parser SyntaxToken
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SyntaxToken"
      ( \Object
x ->
          Maybe Int
-> Maybe Text
-> Maybe Int
-> Maybe Int
-> Maybe PartOfSpeechTag
-> SyntaxToken
SyntaxToken'
            (Maybe Int
 -> Maybe Text
 -> Maybe Int
 -> Maybe Int
 -> Maybe PartOfSpeechTag
 -> SyntaxToken)
-> Parser (Maybe Int)
-> Parser
     (Maybe Text
      -> Maybe Int -> Maybe Int -> Maybe PartOfSpeechTag -> SyntaxToken)
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 Int -> Maybe Int -> Maybe PartOfSpeechTag -> SyntaxToken)
-> Parser (Maybe Text)
-> Parser
     (Maybe Int -> Maybe Int -> Maybe PartOfSpeechTag -> SyntaxToken)
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 Int -> Maybe Int -> Maybe PartOfSpeechTag -> SyntaxToken)
-> Parser (Maybe Int)
-> Parser (Maybe Int -> Maybe PartOfSpeechTag -> SyntaxToken)
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
"TokenId")
            Parser (Maybe Int -> Maybe PartOfSpeechTag -> SyntaxToken)
-> Parser (Maybe Int)
-> Parser (Maybe PartOfSpeechTag -> SyntaxToken)
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")
            Parser (Maybe PartOfSpeechTag -> SyntaxToken)
-> Parser (Maybe PartOfSpeechTag) -> Parser SyntaxToken
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe PartOfSpeechTag)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PartOfSpeech")
      )

instance Prelude.Hashable SyntaxToken

instance Prelude.NFData SyntaxToken