1 package formrecognizer
2
3
4
5
6
7
8
9 import (
10 "encoding/json"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/date"
13 "github.com/gofrs/uuid"
14 )
15
16
17 const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/cognitiveservices/v1.0/formrecognizer"
18
19
20 type AnalyzeResult struct {
21 autorest.Response `json:"-"`
22
23 Status Status2 `json:"status,omitempty"`
24
25
26 Pages *[]ExtractedPage `json:"pages,omitempty"`
27
28
29 Errors *[]FormOperationError `json:"errors,omitempty"`
30 }
31
32
33 type ComputerVisionError struct {
34
35 Code interface{} `json:"code,omitempty"`
36
37 Message *string `json:"message,omitempty"`
38
39 RequestID *string `json:"requestId,omitempty"`
40 }
41
42
43 type ElementReference struct {
44 Ref *string `json:"$ref,omitempty"`
45 }
46
47
48 type ErrorInformation struct {
49 Code *string `json:"code,omitempty"`
50 InnerError *InnerError `json:"innerError,omitempty"`
51 Message *string `json:"message,omitempty"`
52 }
53
54
55 type ErrorResponse struct {
56 Error *ErrorInformation `json:"error,omitempty"`
57 }
58
59
60
61 type ExtractedKeyValuePair struct {
62
63 Key *[]ExtractedToken `json:"key,omitempty"`
64
65 Value *[]ExtractedToken `json:"value,omitempty"`
66 }
67
68
69
70 type ExtractedPage struct {
71
72 Number *int32 `json:"number,omitempty"`
73
74 Height *int32 `json:"height,omitempty"`
75
76 Width *int32 `json:"width,omitempty"`
77
78 ClusterID *int32 `json:"clusterId,omitempty"`
79
80 KeyValuePairs *[]ExtractedKeyValuePair `json:"keyValuePairs,omitempty"`
81
82 Tables *[]ExtractedTable `json:"tables,omitempty"`
83 }
84
85
86
87 type ExtractedTable struct {
88
89 ID *string `json:"id,omitempty"`
90
91 Columns *[]ExtractedTableColumn `json:"columns,omitempty"`
92 }
93
94
95
96 type ExtractedTableColumn struct {
97
98 Header *[]ExtractedToken `json:"header,omitempty"`
99
100
101 Entries *[][]ExtractedToken `json:"entries,omitempty"`
102 }
103
104
105 type ExtractedToken struct {
106
107 Text *string `json:"text,omitempty"`
108
109
110
111
112
113 BoundingBox *[]float64 `json:"boundingBox,omitempty"`
114
115 Confidence *float64 `json:"confidence,omitempty"`
116 }
117
118
119 type BasicFieldValue interface {
120 AsStringValue() (*StringValue, bool)
121 AsNumberValue() (*NumberValue, bool)
122 AsFieldValue() (*FieldValue, bool)
123 }
124
125
126 type FieldValue struct {
127
128 Text *string `json:"text,omitempty"`
129
130 Elements *[]ElementReference `json:"elements,omitempty"`
131
132 ValueType ValueType `json:"valueType,omitempty"`
133 }
134
135 func unmarshalBasicFieldValue(body []byte) (BasicFieldValue, error) {
136 var m map[string]interface{}
137 err := json.Unmarshal(body, &m)
138 if err != nil {
139 return nil, err
140 }
141
142 switch m["valueType"] {
143 case string(ValueTypeStringValue):
144 var sv StringValue
145 err := json.Unmarshal(body, &sv)
146 return sv, err
147 case string(ValueTypeNumberValue):
148 var nv NumberValue
149 err := json.Unmarshal(body, &nv)
150 return nv, err
151 default:
152 var fv FieldValue
153 err := json.Unmarshal(body, &fv)
154 return fv, err
155 }
156 }
157 func unmarshalBasicFieldValueArray(body []byte) ([]BasicFieldValue, error) {
158 var rawMessages []*json.RawMessage
159 err := json.Unmarshal(body, &rawMessages)
160 if err != nil {
161 return nil, err
162 }
163
164 fvArray := make([]BasicFieldValue, len(rawMessages))
165
166 for index, rawMessage := range rawMessages {
167 fv, err := unmarshalBasicFieldValue(*rawMessage)
168 if err != nil {
169 return nil, err
170 }
171 fvArray[index] = fv
172 }
173 return fvArray, nil
174 }
175
176
177 func (fv FieldValue) MarshalJSON() ([]byte, error) {
178 fv.ValueType = ValueTypeFieldValue
179 objectMap := make(map[string]interface{})
180 if fv.Text != nil {
181 objectMap["text"] = fv.Text
182 }
183 if fv.Elements != nil {
184 objectMap["elements"] = fv.Elements
185 }
186 if fv.ValueType != "" {
187 objectMap["valueType"] = fv.ValueType
188 }
189 return json.Marshal(objectMap)
190 }
191
192
193 func (fv FieldValue) AsStringValue() (*StringValue, bool) {
194 return nil, false
195 }
196
197
198 func (fv FieldValue) AsNumberValue() (*NumberValue, bool) {
199 return nil, false
200 }
201
202
203 func (fv FieldValue) AsFieldValue() (*FieldValue, bool) {
204 return &fv, true
205 }
206
207
208 func (fv FieldValue) AsBasicFieldValue() (BasicFieldValue, bool) {
209 return &fv, true
210 }
211
212
213 type FormDocumentReport struct {
214
215 DocumentName *string `json:"documentName,omitempty"`
216
217 Pages *int32 `json:"pages,omitempty"`
218
219 Errors *[]string `json:"errors,omitempty"`
220
221 Status Status `json:"status,omitempty"`
222 }
223
224
225 type FormOperationError struct {
226
227 ErrorMessage *string `json:"errorMessage,omitempty"`
228 }
229
230
231 type ImageURL struct {
232
233 URL *string `json:"url,omitempty"`
234 }
235
236
237 type InnerError struct {
238 RequestID *string `json:"requestId,omitempty"`
239 }
240
241
242
243 type KeysResult struct {
244 autorest.Response `json:"-"`
245
246 Clusters map[string][]string `json:"clusters"`
247 }
248
249
250 func (kr KeysResult) MarshalJSON() ([]byte, error) {
251 objectMap := make(map[string]interface{})
252 if kr.Clusters != nil {
253 objectMap["clusters"] = kr.Clusters
254 }
255 return json.Marshal(objectMap)
256 }
257
258
259 type Line struct {
260
261 BoundingBox *[]int32 `json:"boundingBox,omitempty"`
262
263 Text *string `json:"text,omitempty"`
264
265 Words *[]Word `json:"words,omitempty"`
266 }
267
268
269 type ModelResult struct {
270 autorest.Response `json:"-"`
271
272 ModelID *uuid.UUID `json:"modelId,omitempty"`
273
274 Status Status1 `json:"status,omitempty"`
275
276 CreatedDateTime *date.Time `json:"createdDateTime,omitempty"`
277
278 LastUpdatedDateTime *date.Time `json:"lastUpdatedDateTime,omitempty"`
279 }
280
281
282 type ModelsResult struct {
283 autorest.Response `json:"-"`
284
285 ModelsProperty *[]ModelResult `json:"models,omitempty"`
286 }
287
288
289 type NumberValue struct {
290
291 Value *float64 `json:"value,omitempty"`
292
293 Text *string `json:"text,omitempty"`
294
295 Elements *[]ElementReference `json:"elements,omitempty"`
296
297 ValueType ValueType `json:"valueType,omitempty"`
298 }
299
300
301 func (nv NumberValue) MarshalJSON() ([]byte, error) {
302 nv.ValueType = ValueTypeNumberValue
303 objectMap := make(map[string]interface{})
304 if nv.Value != nil {
305 objectMap["value"] = nv.Value
306 }
307 if nv.Text != nil {
308 objectMap["text"] = nv.Text
309 }
310 if nv.Elements != nil {
311 objectMap["elements"] = nv.Elements
312 }
313 if nv.ValueType != "" {
314 objectMap["valueType"] = nv.ValueType
315 }
316 return json.Marshal(objectMap)
317 }
318
319
320 func (nv NumberValue) AsStringValue() (*StringValue, bool) {
321 return nil, false
322 }
323
324
325 func (nv NumberValue) AsNumberValue() (*NumberValue, bool) {
326 return &nv, true
327 }
328
329
330 func (nv NumberValue) AsFieldValue() (*FieldValue, bool) {
331 return nil, false
332 }
333
334
335 func (nv NumberValue) AsBasicFieldValue() (BasicFieldValue, bool) {
336 return &nv, true
337 }
338
339
340 type ReadReceiptResult struct {
341 autorest.Response `json:"-"`
342
343 Status TextOperationStatusCodes `json:"status,omitempty"`
344
345 RecognitionResults *[]TextRecognitionResult `json:"recognitionResults,omitempty"`
346
347 UnderstandingResults *[]UnderstandingResult `json:"understandingResults,omitempty"`
348 }
349
350
351 type StringValue struct {
352
353 Value *string `json:"value,omitempty"`
354
355 Text *string `json:"text,omitempty"`
356
357 Elements *[]ElementReference `json:"elements,omitempty"`
358
359 ValueType ValueType `json:"valueType,omitempty"`
360 }
361
362
363 func (sv StringValue) MarshalJSON() ([]byte, error) {
364 sv.ValueType = ValueTypeStringValue
365 objectMap := make(map[string]interface{})
366 if sv.Value != nil {
367 objectMap["value"] = sv.Value
368 }
369 if sv.Text != nil {
370 objectMap["text"] = sv.Text
371 }
372 if sv.Elements != nil {
373 objectMap["elements"] = sv.Elements
374 }
375 if sv.ValueType != "" {
376 objectMap["valueType"] = sv.ValueType
377 }
378 return json.Marshal(objectMap)
379 }
380
381
382 func (sv StringValue) AsStringValue() (*StringValue, bool) {
383 return &sv, true
384 }
385
386
387 func (sv StringValue) AsNumberValue() (*NumberValue, bool) {
388 return nil, false
389 }
390
391
392 func (sv StringValue) AsFieldValue() (*FieldValue, bool) {
393 return nil, false
394 }
395
396
397 func (sv StringValue) AsBasicFieldValue() (BasicFieldValue, bool) {
398 return &sv, true
399 }
400
401
402 type TextRecognitionResult struct {
403
404 Page *int32 `json:"page,omitempty"`
405
406 ClockwiseOrientation *float64 `json:"clockwiseOrientation,omitempty"`
407
408 Width *float64 `json:"width,omitempty"`
409
410 Height *float64 `json:"height,omitempty"`
411
412 Unit TextRecognitionResultDimensionUnit `json:"unit,omitempty"`
413
414 Lines *[]Line `json:"lines,omitempty"`
415 }
416
417
418 type TrainRequest struct {
419
420 Source *string `json:"source,omitempty"`
421
422
423 SourceFilter *TrainSourceFilter `json:"sourceFilter,omitempty"`
424 }
425
426
427 type TrainResult struct {
428 autorest.Response `json:"-"`
429
430 ModelID *uuid.UUID `json:"modelId,omitempty"`
431
432
433 TrainingDocuments *[]FormDocumentReport `json:"trainingDocuments,omitempty"`
434
435 Errors *[]FormOperationError `json:"errors,omitempty"`
436 }
437
438
439 type TrainSourceFilter struct {
440
441
442
443 Prefix *string `json:"prefix,omitempty"`
444
445
446
447 IncludeSubFolders *bool `json:"includeSubFolders,omitempty"`
448 }
449
450
451
452 type UnderstandingResult struct {
453
454 Pages *[]int32 `json:"pages,omitempty"`
455
456 Fields map[string]BasicFieldValue `json:"fields"`
457 }
458
459
460 func (ur UnderstandingResult) MarshalJSON() ([]byte, error) {
461 objectMap := make(map[string]interface{})
462 if ur.Pages != nil {
463 objectMap["pages"] = ur.Pages
464 }
465 if ur.Fields != nil {
466 objectMap["fields"] = ur.Fields
467 }
468 return json.Marshal(objectMap)
469 }
470
471
472 type Word struct {
473
474 BoundingBox *[]int32 `json:"boundingBox,omitempty"`
475
476 Text *string `json:"text,omitempty"`
477
478 Confidence TextRecognitionResultConfidenceClass `json:"confidence,omitempty"`
479 }
480
View as plain text