1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 
6 #include <aws/comprehendmedical/model/Entity.h>
7 #include <aws/core/utils/json/JsonSerializer.h>
8 
9 #include <utility>
10 
11 using namespace Aws::Utils::Json;
12 using namespace Aws::Utils;
13 
14 namespace Aws
15 {
16 namespace ComprehendMedical
17 {
18 namespace Model
19 {
20 
Entity()21 Entity::Entity() :
22     m_id(0),
23     m_idHasBeenSet(false),
24     m_beginOffset(0),
25     m_beginOffsetHasBeenSet(false),
26     m_endOffset(0),
27     m_endOffsetHasBeenSet(false),
28     m_score(0.0),
29     m_scoreHasBeenSet(false),
30     m_textHasBeenSet(false),
31     m_category(EntityType::NOT_SET),
32     m_categoryHasBeenSet(false),
33     m_type(EntitySubType::NOT_SET),
34     m_typeHasBeenSet(false),
35     m_traitsHasBeenSet(false),
36     m_attributesHasBeenSet(false)
37 {
38 }
39 
Entity(JsonView jsonValue)40 Entity::Entity(JsonView jsonValue) :
41     m_id(0),
42     m_idHasBeenSet(false),
43     m_beginOffset(0),
44     m_beginOffsetHasBeenSet(false),
45     m_endOffset(0),
46     m_endOffsetHasBeenSet(false),
47     m_score(0.0),
48     m_scoreHasBeenSet(false),
49     m_textHasBeenSet(false),
50     m_category(EntityType::NOT_SET),
51     m_categoryHasBeenSet(false),
52     m_type(EntitySubType::NOT_SET),
53     m_typeHasBeenSet(false),
54     m_traitsHasBeenSet(false),
55     m_attributesHasBeenSet(false)
56 {
57   *this = jsonValue;
58 }
59 
operator =(JsonView jsonValue)60 Entity& Entity::operator =(JsonView jsonValue)
61 {
62   if(jsonValue.ValueExists("Id"))
63   {
64     m_id = jsonValue.GetInteger("Id");
65 
66     m_idHasBeenSet = true;
67   }
68 
69   if(jsonValue.ValueExists("BeginOffset"))
70   {
71     m_beginOffset = jsonValue.GetInteger("BeginOffset");
72 
73     m_beginOffsetHasBeenSet = true;
74   }
75 
76   if(jsonValue.ValueExists("EndOffset"))
77   {
78     m_endOffset = jsonValue.GetInteger("EndOffset");
79 
80     m_endOffsetHasBeenSet = true;
81   }
82 
83   if(jsonValue.ValueExists("Score"))
84   {
85     m_score = jsonValue.GetDouble("Score");
86 
87     m_scoreHasBeenSet = true;
88   }
89 
90   if(jsonValue.ValueExists("Text"))
91   {
92     m_text = jsonValue.GetString("Text");
93 
94     m_textHasBeenSet = true;
95   }
96 
97   if(jsonValue.ValueExists("Category"))
98   {
99     m_category = EntityTypeMapper::GetEntityTypeForName(jsonValue.GetString("Category"));
100 
101     m_categoryHasBeenSet = true;
102   }
103 
104   if(jsonValue.ValueExists("Type"))
105   {
106     m_type = EntitySubTypeMapper::GetEntitySubTypeForName(jsonValue.GetString("Type"));
107 
108     m_typeHasBeenSet = true;
109   }
110 
111   if(jsonValue.ValueExists("Traits"))
112   {
113     Array<JsonView> traitsJsonList = jsonValue.GetArray("Traits");
114     for(unsigned traitsIndex = 0; traitsIndex < traitsJsonList.GetLength(); ++traitsIndex)
115     {
116       m_traits.push_back(traitsJsonList[traitsIndex].AsObject());
117     }
118     m_traitsHasBeenSet = true;
119   }
120 
121   if(jsonValue.ValueExists("Attributes"))
122   {
123     Array<JsonView> attributesJsonList = jsonValue.GetArray("Attributes");
124     for(unsigned attributesIndex = 0; attributesIndex < attributesJsonList.GetLength(); ++attributesIndex)
125     {
126       m_attributes.push_back(attributesJsonList[attributesIndex].AsObject());
127     }
128     m_attributesHasBeenSet = true;
129   }
130 
131   return *this;
132 }
133 
Jsonize() const134 JsonValue Entity::Jsonize() const
135 {
136   JsonValue payload;
137 
138   if(m_idHasBeenSet)
139   {
140    payload.WithInteger("Id", m_id);
141 
142   }
143 
144   if(m_beginOffsetHasBeenSet)
145   {
146    payload.WithInteger("BeginOffset", m_beginOffset);
147 
148   }
149 
150   if(m_endOffsetHasBeenSet)
151   {
152    payload.WithInteger("EndOffset", m_endOffset);
153 
154   }
155 
156   if(m_scoreHasBeenSet)
157   {
158    payload.WithDouble("Score", m_score);
159 
160   }
161 
162   if(m_textHasBeenSet)
163   {
164    payload.WithString("Text", m_text);
165 
166   }
167 
168   if(m_categoryHasBeenSet)
169   {
170    payload.WithString("Category", EntityTypeMapper::GetNameForEntityType(m_category));
171   }
172 
173   if(m_typeHasBeenSet)
174   {
175    payload.WithString("Type", EntitySubTypeMapper::GetNameForEntitySubType(m_type));
176   }
177 
178   if(m_traitsHasBeenSet)
179   {
180    Array<JsonValue> traitsJsonList(m_traits.size());
181    for(unsigned traitsIndex = 0; traitsIndex < traitsJsonList.GetLength(); ++traitsIndex)
182    {
183      traitsJsonList[traitsIndex].AsObject(m_traits[traitsIndex].Jsonize());
184    }
185    payload.WithArray("Traits", std::move(traitsJsonList));
186 
187   }
188 
189   if(m_attributesHasBeenSet)
190   {
191    Array<JsonValue> attributesJsonList(m_attributes.size());
192    for(unsigned attributesIndex = 0; attributesIndex < attributesJsonList.GetLength(); ++attributesIndex)
193    {
194      attributesJsonList[attributesIndex].AsObject(m_attributes[attributesIndex].Jsonize());
195    }
196    payload.WithArray("Attributes", std::move(attributesJsonList));
197 
198   }
199 
200   return payload;
201 }
202 
203 } // namespace Model
204 } // namespace ComprehendMedical
205 } // namespace Aws
206