{-# 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.ComprehendMedical.Types.Entity
-- 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.ComprehendMedical.Types.Entity where

import Amazonka.ComprehendMedical.Types.Attribute
import Amazonka.ComprehendMedical.Types.EntitySubType
import Amazonka.ComprehendMedical.Types.EntityType
import Amazonka.ComprehendMedical.Types.Trait
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Provides information about an extracted medical entity.
--
-- /See:/ 'newEntity' smart constructor.
data Entity = Entity'
  { -- | The 0-based character offset in the input text that shows where the
    -- entity begins. The offset returns the UTF-8 code point in the string.
    Entity -> Maybe Int
beginOffset :: Prelude.Maybe Prelude.Int,
    -- | The segment of input text extracted as this entity.
    Entity -> Maybe Text
text :: Prelude.Maybe Prelude.Text,
    -- | The category of the entity.
    Entity -> Maybe EntityType
category :: Prelude.Maybe EntityType,
    -- | The level of confidence that Amazon Comprehend Medical has in the
    -- accuracy of the detection.
    Entity -> Maybe Double
score :: Prelude.Maybe Prelude.Double,
    -- | Contextual information for the entity.
    Entity -> Maybe [Trait]
traits :: Prelude.Maybe [Trait],
    -- | The extracted attributes that relate to this entity.
    Entity -> Maybe [Attribute]
attributes :: Prelude.Maybe [Attribute],
    -- | The 0-based character offset in the input text that shows where the
    -- entity ends. The offset returns the UTF-8 code point in the string.
    Entity -> Maybe Int
endOffset :: Prelude.Maybe Prelude.Int,
    -- | The numeric identifier for the entity. This is a monotonically
    -- increasing id unique within this response rather than a global unique
    -- identifier.
    Entity -> Maybe Int
id :: Prelude.Maybe Prelude.Int,
    -- | Describes the specific type of entity with category of entities.
    Entity -> Maybe EntitySubType
type' :: Prelude.Maybe EntitySubType
  }
  deriving (Entity -> Entity -> Bool
(Entity -> Entity -> Bool)
-> (Entity -> Entity -> Bool) -> Eq Entity
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]
(Int -> ReadS Entity)
-> ReadS [Entity]
-> ReadPrec Entity
-> ReadPrec [Entity]
-> Read 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
(Int -> Entity -> ShowS)
-> (Entity -> String) -> ([Entity] -> ShowS) -> Show Entity
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. Entity -> Rep Entity x)
-> (forall x. Rep Entity x -> Entity) -> Generic Entity
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 0-based character offset in the input text that shows where the
-- entity begins. The offset returns the UTF-8 code point in the string.
--
-- 'text', 'entity_text' - The segment of input text extracted as this entity.
--
-- 'category', 'entity_category' - The category of the entity.
--
-- 'score', 'entity_score' - The level of confidence that Amazon Comprehend Medical has in the
-- accuracy of the detection.
--
-- 'traits', 'entity_traits' - Contextual information for the entity.
--
-- 'attributes', 'entity_attributes' - The extracted attributes that relate to this entity.
--
-- 'endOffset', 'entity_endOffset' - The 0-based character offset in the input text that shows where the
-- entity ends. The offset returns the UTF-8 code point in the string.
--
-- 'id', 'entity_id' - The numeric identifier for the entity. This is a monotonically
-- increasing id unique within this response rather than a global unique
-- identifier.
--
-- 'type'', 'entity_type' - Describes the specific type of entity with category of entities.
newEntity ::
  Entity
newEntity :: Entity
newEntity =
  Entity' :: Maybe Int
-> Maybe Text
-> Maybe EntityType
-> Maybe Double
-> Maybe [Trait]
-> Maybe [Attribute]
-> Maybe Int
-> Maybe Int
-> Maybe EntitySubType
-> Entity
Entity'
    { $sel:beginOffset:Entity' :: Maybe Int
beginOffset = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:text:Entity' :: Maybe Text
text = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:category:Entity' :: Maybe EntityType
category = Maybe EntityType
forall a. Maybe a
Prelude.Nothing,
      $sel:score:Entity' :: Maybe Double
score = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:traits:Entity' :: Maybe [Trait]
traits = Maybe [Trait]
forall a. Maybe a
Prelude.Nothing,
      $sel:attributes:Entity' :: Maybe [Attribute]
attributes = Maybe [Attribute]
forall a. Maybe a
Prelude.Nothing,
      $sel:endOffset:Entity' :: Maybe Int
endOffset = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:id:Entity' :: Maybe Int
id = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:type':Entity' :: Maybe EntitySubType
type' = Maybe EntitySubType
forall a. Maybe a
Prelude.Nothing
    }

-- | The 0-based character offset in the input text that shows where the
-- entity begins. The offset returns the UTF-8 code point in the string.
entity_beginOffset :: Lens.Lens' Entity (Prelude.Maybe Prelude.Int)
entity_beginOffset :: (Maybe Int -> f (Maybe Int)) -> Entity -> f Entity
entity_beginOffset = (Entity -> Maybe Int)
-> (Entity -> Maybe Int -> Entity)
-> Lens Entity Entity (Maybe Int) (Maybe Int)
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)

-- | The segment of input text extracted as this entity.
entity_text :: Lens.Lens' Entity (Prelude.Maybe Prelude.Text)
entity_text :: (Maybe Text -> f (Maybe Text)) -> Entity -> f Entity
entity_text = (Entity -> Maybe Text)
-> (Entity -> Maybe Text -> Entity)
-> Lens Entity Entity (Maybe Text) (Maybe 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 category of the entity.
entity_category :: Lens.Lens' Entity (Prelude.Maybe EntityType)
entity_category :: (Maybe EntityType -> f (Maybe EntityType)) -> Entity -> f Entity
entity_category = (Entity -> Maybe EntityType)
-> (Entity -> Maybe EntityType -> Entity)
-> Lens Entity Entity (Maybe EntityType) (Maybe EntityType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Maybe EntityType
category :: Maybe EntityType
$sel:category:Entity' :: Entity -> Maybe EntityType
category} -> Maybe EntityType
category) (\s :: Entity
s@Entity' {} Maybe EntityType
a -> Entity
s {$sel:category:Entity' :: Maybe EntityType
category = Maybe EntityType
a} :: Entity)

-- | The level of confidence that Amazon Comprehend Medical has in the
-- accuracy of the detection.
entity_score :: Lens.Lens' Entity (Prelude.Maybe Prelude.Double)
entity_score :: (Maybe Double -> f (Maybe Double)) -> Entity -> f Entity
entity_score = (Entity -> Maybe Double)
-> (Entity -> Maybe Double -> Entity)
-> Lens Entity Entity (Maybe Double) (Maybe Double)
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)

-- | Contextual information for the entity.
entity_traits :: Lens.Lens' Entity (Prelude.Maybe [Trait])
entity_traits :: (Maybe [Trait] -> f (Maybe [Trait])) -> Entity -> f Entity
entity_traits = (Entity -> Maybe [Trait])
-> (Entity -> Maybe [Trait] -> Entity)
-> Lens Entity Entity (Maybe [Trait]) (Maybe [Trait])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Maybe [Trait]
traits :: Maybe [Trait]
$sel:traits:Entity' :: Entity -> Maybe [Trait]
traits} -> Maybe [Trait]
traits) (\s :: Entity
s@Entity' {} Maybe [Trait]
a -> Entity
s {$sel:traits:Entity' :: Maybe [Trait]
traits = Maybe [Trait]
a} :: Entity) ((Maybe [Trait] -> f (Maybe [Trait])) -> Entity -> f Entity)
-> ((Maybe [Trait] -> f (Maybe [Trait]))
    -> Maybe [Trait] -> f (Maybe [Trait]))
-> (Maybe [Trait] -> f (Maybe [Trait]))
-> Entity
-> f Entity
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Trait] [Trait] [Trait] [Trait]
-> Iso
     (Maybe [Trait]) (Maybe [Trait]) (Maybe [Trait]) (Maybe [Trait])
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 AnIso [Trait] [Trait] [Trait] [Trait]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The extracted attributes that relate to this entity.
entity_attributes :: Lens.Lens' Entity (Prelude.Maybe [Attribute])
entity_attributes :: (Maybe [Attribute] -> f (Maybe [Attribute])) -> Entity -> f Entity
entity_attributes = (Entity -> Maybe [Attribute])
-> (Entity -> Maybe [Attribute] -> Entity)
-> Lens Entity Entity (Maybe [Attribute]) (Maybe [Attribute])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Maybe [Attribute]
attributes :: Maybe [Attribute]
$sel:attributes:Entity' :: Entity -> Maybe [Attribute]
attributes} -> Maybe [Attribute]
attributes) (\s :: Entity
s@Entity' {} Maybe [Attribute]
a -> Entity
s {$sel:attributes:Entity' :: Maybe [Attribute]
attributes = Maybe [Attribute]
a} :: Entity) ((Maybe [Attribute] -> f (Maybe [Attribute]))
 -> Entity -> f Entity)
-> ((Maybe [Attribute] -> f (Maybe [Attribute]))
    -> Maybe [Attribute] -> f (Maybe [Attribute]))
-> (Maybe [Attribute] -> f (Maybe [Attribute]))
-> Entity
-> f Entity
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Attribute] [Attribute] [Attribute] [Attribute]
-> Iso
     (Maybe [Attribute])
     (Maybe [Attribute])
     (Maybe [Attribute])
     (Maybe [Attribute])
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 AnIso [Attribute] [Attribute] [Attribute] [Attribute]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The 0-based character offset in the input text that shows where the
-- entity ends. The offset returns the UTF-8 code point in the string.
entity_endOffset :: Lens.Lens' Entity (Prelude.Maybe Prelude.Int)
entity_endOffset :: (Maybe Int -> f (Maybe Int)) -> Entity -> f Entity
entity_endOffset = (Entity -> Maybe Int)
-> (Entity -> Maybe Int -> Entity)
-> Lens Entity Entity (Maybe Int) (Maybe Int)
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 numeric identifier for the entity. This is a monotonically
-- increasing id unique within this response rather than a global unique
-- identifier.
entity_id :: Lens.Lens' Entity (Prelude.Maybe Prelude.Int)
entity_id :: (Maybe Int -> f (Maybe Int)) -> Entity -> f Entity
entity_id = (Entity -> Maybe Int)
-> (Entity -> Maybe Int -> Entity)
-> Lens Entity Entity (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Maybe Int
id :: Maybe Int
$sel:id:Entity' :: Entity -> Maybe Int
id} -> Maybe Int
id) (\s :: Entity
s@Entity' {} Maybe Int
a -> Entity
s {$sel:id:Entity' :: Maybe Int
id = Maybe Int
a} :: Entity)

-- | Describes the specific type of entity with category of entities.
entity_type :: Lens.Lens' Entity (Prelude.Maybe EntitySubType)
entity_type :: (Maybe EntitySubType -> f (Maybe EntitySubType))
-> Entity -> f Entity
entity_type = (Entity -> Maybe EntitySubType)
-> (Entity -> Maybe EntitySubType -> Entity)
-> Lens Entity Entity (Maybe EntitySubType) (Maybe EntitySubType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Entity' {Maybe EntitySubType
type' :: Maybe EntitySubType
$sel:type':Entity' :: Entity -> Maybe EntitySubType
type'} -> Maybe EntitySubType
type') (\s :: Entity
s@Entity' {} Maybe EntitySubType
a -> Entity
s {$sel:type':Entity' :: Maybe EntitySubType
type' = Maybe EntitySubType
a} :: Entity)

instance Core.FromJSON Entity where
  parseJSON :: Value -> Parser Entity
parseJSON =
    String -> (Object -> Parser Entity) -> Value -> Parser Entity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Entity"
      ( \Object
x ->
          Maybe Int
-> Maybe Text
-> Maybe EntityType
-> Maybe Double
-> Maybe [Trait]
-> Maybe [Attribute]
-> Maybe Int
-> Maybe Int
-> Maybe EntitySubType
-> Entity
Entity'
            (Maybe Int
 -> Maybe Text
 -> Maybe EntityType
 -> Maybe Double
 -> Maybe [Trait]
 -> Maybe [Attribute]
 -> Maybe Int
 -> Maybe Int
 -> Maybe EntitySubType
 -> Entity)
-> Parser (Maybe Int)
-> Parser
     (Maybe Text
      -> Maybe EntityType
      -> Maybe Double
      -> Maybe [Trait]
      -> Maybe [Attribute]
      -> Maybe Int
      -> Maybe Int
      -> Maybe EntitySubType
      -> Entity)
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 EntityType
   -> Maybe Double
   -> Maybe [Trait]
   -> Maybe [Attribute]
   -> Maybe Int
   -> Maybe Int
   -> Maybe EntitySubType
   -> Entity)
-> Parser (Maybe Text)
-> Parser
     (Maybe EntityType
      -> Maybe Double
      -> Maybe [Trait]
      -> Maybe [Attribute]
      -> Maybe Int
      -> Maybe Int
      -> Maybe EntitySubType
      -> Entity)
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 EntityType
   -> Maybe Double
   -> Maybe [Trait]
   -> Maybe [Attribute]
   -> Maybe Int
   -> Maybe Int
   -> Maybe EntitySubType
   -> Entity)
-> Parser (Maybe EntityType)
-> Parser
     (Maybe Double
      -> Maybe [Trait]
      -> Maybe [Attribute]
      -> Maybe Int
      -> Maybe Int
      -> Maybe EntitySubType
      -> Entity)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe EntityType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Category")
            Parser
  (Maybe Double
   -> Maybe [Trait]
   -> Maybe [Attribute]
   -> Maybe Int
   -> Maybe Int
   -> Maybe EntitySubType
   -> Entity)
-> Parser (Maybe Double)
-> Parser
     (Maybe [Trait]
      -> Maybe [Attribute]
      -> Maybe Int
      -> Maybe Int
      -> Maybe EntitySubType
      -> Entity)
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 [Trait]
   -> Maybe [Attribute]
   -> Maybe Int
   -> Maybe Int
   -> Maybe EntitySubType
   -> Entity)
-> Parser (Maybe [Trait])
-> Parser
     (Maybe [Attribute]
      -> Maybe Int -> Maybe Int -> Maybe EntitySubType -> Entity)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Trait]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Traits" Parser (Maybe (Maybe [Trait]))
-> Maybe [Trait] -> Parser (Maybe [Trait])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Trait]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe [Attribute]
   -> Maybe Int -> Maybe Int -> Maybe EntitySubType -> Entity)
-> Parser (Maybe [Attribute])
-> Parser (Maybe Int -> Maybe Int -> Maybe EntitySubType -> Entity)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Attribute]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Attributes" Parser (Maybe (Maybe [Attribute]))
-> Maybe [Attribute] -> Parser (Maybe [Attribute])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Attribute]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Int -> Maybe Int -> Maybe EntitySubType -> Entity)
-> Parser (Maybe Int)
-> Parser (Maybe Int -> Maybe EntitySubType -> Entity)
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 Int -> Maybe EntitySubType -> Entity)
-> Parser (Maybe Int) -> Parser (Maybe EntitySubType -> Entity)
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
"Id")
            Parser (Maybe EntitySubType -> Entity)
-> Parser (Maybe EntitySubType) -> Parser Entity
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe EntitySubType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Type")
      )

instance Prelude.Hashable Entity

instance Prelude.NFData Entity