1package formrecognizer 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 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// The package's fully qualified name. 17const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/cognitiveservices/v1.0/formrecognizer" 18 19// AnalyzeResult analyze API call result. 20type AnalyzeResult struct { 21 autorest.Response `json:"-"` 22 // Status - Status of the analyze operation. Possible values include: 'Status2Success', 'Status2PartialSuccess', 'Status2Failure' 23 Status Status2 `json:"status,omitempty"` 24 // Pages - Page level information extracted in the analyzed 25 // document. 26 Pages *[]ExtractedPage `json:"pages,omitempty"` 27 // Errors - List of errors reported during the analyze 28 // operation. 29 Errors *[]FormOperationError `json:"errors,omitempty"` 30} 31 32// ComputerVisionError details about the API request error. 33type ComputerVisionError struct { 34 // Code - The error code. 35 Code interface{} `json:"code,omitempty"` 36 // Message - A message explaining the error reported by the service. 37 Message *string `json:"message,omitempty"` 38 // RequestID - A unique request identifier. 39 RequestID *string `json:"requestId,omitempty"` 40} 41 42// ElementReference reference to an OCR word. 43type ElementReference struct { 44 Ref *string `json:"$ref,omitempty"` 45} 46 47// ErrorInformation ... 48type ErrorInformation struct { 49 Code *string `json:"code,omitempty"` 50 InnerError *InnerError `json:"innerError,omitempty"` 51 Message *string `json:"message,omitempty"` 52} 53 54// ErrorResponse ... 55type ErrorResponse struct { 56 Error *ErrorInformation `json:"error,omitempty"` 57} 58 59// ExtractedKeyValuePair representation of a key-value pair as a list 60// of key and value tokens. 61type ExtractedKeyValuePair struct { 62 // Key - List of tokens for the extracted key in a key-value pair. 63 Key *[]ExtractedToken `json:"key,omitempty"` 64 // Value - List of tokens for the extracted value in a key-value pair. 65 Value *[]ExtractedToken `json:"value,omitempty"` 66} 67 68// ExtractedPage extraction information of a single page in a 69// with a document. 70type ExtractedPage struct { 71 // Number - Page number. 72 Number *int32 `json:"number,omitempty"` 73 // Height - Height of the page (in pixels). 74 Height *int32 `json:"height,omitempty"` 75 // Width - Width of the page (in pixels). 76 Width *int32 `json:"width,omitempty"` 77 // ClusterID - Cluster identifier. 78 ClusterID *int32 `json:"clusterId,omitempty"` 79 // KeyValuePairs - List of Key-Value pairs extracted from the page. 80 KeyValuePairs *[]ExtractedKeyValuePair `json:"keyValuePairs,omitempty"` 81 // Tables - List of Tables and their information extracted from the page. 82 Tables *[]ExtractedTable `json:"tables,omitempty"` 83} 84 85// ExtractedTable extraction information about a table 86// contained in a page. 87type ExtractedTable struct { 88 // ID - Table identifier. 89 ID *string `json:"id,omitempty"` 90 // Columns - List of columns contained in the table. 91 Columns *[]ExtractedTableColumn `json:"columns,omitempty"` 92} 93 94// ExtractedTableColumn extraction information of a column in 95// a table. 96type ExtractedTableColumn struct { 97 // Header - List of extracted tokens for the column header. 98 Header *[]ExtractedToken `json:"header,omitempty"` 99 // Entries - Extracted text for each cell of a column. Each cell 100 // in the column can have a list of one or more tokens. 101 Entries *[][]ExtractedToken `json:"entries,omitempty"` 102} 103 104// ExtractedToken canonical representation of single extracted text. 105type ExtractedToken struct { 106 // Text - String value of the extracted text. 107 Text *string `json:"text,omitempty"` 108 // BoundingBox - Bounding box of the extracted text. Represents the 109 // location of the extracted text as a pair of 110 // cartesian co-ordinates. The co-ordinate pairs are arranged by 111 // top-left, top-right, bottom-right and bottom-left endpoints box 112 // with origin reference from the bottom-left of the page. 113 BoundingBox *[]float64 `json:"boundingBox,omitempty"` 114 // Confidence - A measure of accuracy of the extracted text. 115 Confidence *float64 `json:"confidence,omitempty"` 116} 117 118// BasicFieldValue base class representing a recognized field value. 119type BasicFieldValue interface { 120 AsStringValue() (*StringValue, bool) 121 AsNumberValue() (*NumberValue, bool) 122 AsFieldValue() (*FieldValue, bool) 123} 124 125// FieldValue base class representing a recognized field value. 126type FieldValue struct { 127 // Text - OCR text content of the recognized field. 128 Text *string `json:"text,omitempty"` 129 // Elements - List of references to OCR words comprising the recognized field value. 130 Elements *[]ElementReference `json:"elements,omitempty"` 131 // ValueType - Possible values include: 'ValueTypeFieldValue', 'ValueTypeStringValue', 'ValueTypeNumberValue' 132 ValueType ValueType `json:"valueType,omitempty"` 133} 134 135func 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} 157func 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// MarshalJSON is the custom marshaler for FieldValue. 177func (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// AsStringValue is the BasicFieldValue implementation for FieldValue. 193func (fv FieldValue) AsStringValue() (*StringValue, bool) { 194 return nil, false 195} 196 197// AsNumberValue is the BasicFieldValue implementation for FieldValue. 198func (fv FieldValue) AsNumberValue() (*NumberValue, bool) { 199 return nil, false 200} 201 202// AsFieldValue is the BasicFieldValue implementation for FieldValue. 203func (fv FieldValue) AsFieldValue() (*FieldValue, bool) { 204 return &fv, true 205} 206 207// AsBasicFieldValue is the BasicFieldValue implementation for FieldValue. 208func (fv FieldValue) AsBasicFieldValue() (BasicFieldValue, bool) { 209 return &fv, true 210} 211 212// FormDocumentReport ... 213type FormDocumentReport struct { 214 // DocumentName - Reference to the data that the report is for. 215 DocumentName *string `json:"documentName,omitempty"` 216 // Pages - Total number of pages trained on. 217 Pages *int32 `json:"pages,omitempty"` 218 // Errors - List of errors per page. 219 Errors *[]string `json:"errors,omitempty"` 220 // Status - Status of the training operation. Possible values include: 'Success', 'PartialSuccess', 'Failure' 221 Status Status `json:"status,omitempty"` 222} 223 224// FormOperationError error reported during an operation. 225type FormOperationError struct { 226 // ErrorMessage - Message reported during the train operation. 227 ErrorMessage *string `json:"errorMessage,omitempty"` 228} 229 230// ImageURL ... 231type ImageURL struct { 232 // URL - Publicly reachable URL of an image. 233 URL *string `json:"url,omitempty"` 234} 235 236// InnerError ... 237type InnerError struct { 238 RequestID *string `json:"requestId,omitempty"` 239} 240 241// KeysResult result of an operation to get 242// the keys extracted by a model. 243type KeysResult struct { 244 autorest.Response `json:"-"` 245 // Clusters - Object mapping ClusterIds to Key lists. 246 Clusters map[string][]string `json:"clusters"` 247} 248 249// MarshalJSON is the custom marshaler for KeysResult. 250func (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// Line an object representing a recognized text line. 259type Line struct { 260 // BoundingBox - Bounding box of a recognized line. 261 BoundingBox *[]int32 `json:"boundingBox,omitempty"` 262 // Text - The text content of the line. 263 Text *string `json:"text,omitempty"` 264 // Words - List of words in the text line. 265 Words *[]Word `json:"words,omitempty"` 266} 267 268// ModelResult result of a model status query operation. 269type ModelResult struct { 270 autorest.Response `json:"-"` 271 // ModelID - Get or set model identifier. 272 ModelID *uuid.UUID `json:"modelId,omitempty"` 273 // Status - Get or set the status of model. Possible values include: 'Created', 'Ready', 'Invalid' 274 Status Status1 `json:"status,omitempty"` 275 // CreatedDateTime - Get or set the created date time of the model. 276 CreatedDateTime *date.Time `json:"createdDateTime,omitempty"` 277 // LastUpdatedDateTime - Get or set the model last updated datetime. 278 LastUpdatedDateTime *date.Time `json:"lastUpdatedDateTime,omitempty"` 279} 280 281// ModelsResult result of query operation to fetch multiple models. 282type ModelsResult struct { 283 autorest.Response `json:"-"` 284 // ModelsProperty - Collection of models. 285 ModelsProperty *[]ModelResult `json:"models,omitempty"` 286} 287 288// NumberValue recognized numeric field value. 289type NumberValue struct { 290 // Value - Numeric value of the recognized field. 291 Value *float64 `json:"value,omitempty"` 292 // Text - OCR text content of the recognized field. 293 Text *string `json:"text,omitempty"` 294 // Elements - List of references to OCR words comprising the recognized field value. 295 Elements *[]ElementReference `json:"elements,omitempty"` 296 // ValueType - Possible values include: 'ValueTypeFieldValue', 'ValueTypeStringValue', 'ValueTypeNumberValue' 297 ValueType ValueType `json:"valueType,omitempty"` 298} 299 300// MarshalJSON is the custom marshaler for NumberValue. 301func (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// AsStringValue is the BasicFieldValue implementation for NumberValue. 320func (nv NumberValue) AsStringValue() (*StringValue, bool) { 321 return nil, false 322} 323 324// AsNumberValue is the BasicFieldValue implementation for NumberValue. 325func (nv NumberValue) AsNumberValue() (*NumberValue, bool) { 326 return &nv, true 327} 328 329// AsFieldValue is the BasicFieldValue implementation for NumberValue. 330func (nv NumberValue) AsFieldValue() (*FieldValue, bool) { 331 return nil, false 332} 333 334// AsBasicFieldValue is the BasicFieldValue implementation for NumberValue. 335func (nv NumberValue) AsBasicFieldValue() (BasicFieldValue, bool) { 336 return &nv, true 337} 338 339// ReadReceiptResult analysis result of the 'Batch Read Receipt' operation. 340type ReadReceiptResult struct { 341 autorest.Response `json:"-"` 342 // Status - Status of the read operation. Possible values include: 'NotStarted', 'Running', 'Failed', 'Succeeded' 343 Status TextOperationStatusCodes `json:"status,omitempty"` 344 // RecognitionResults - Text recognition result of the 'Batch Read Receipt' operation. 345 RecognitionResults *[]TextRecognitionResult `json:"recognitionResults,omitempty"` 346 // UnderstandingResults - Semantic understanding result of the 'Batch Read Receipt' operation. 347 UnderstandingResults *[]UnderstandingResult `json:"understandingResults,omitempty"` 348} 349 350// StringValue recognized string field value. 351type StringValue struct { 352 // Value - String value of the recognized field. 353 Value *string `json:"value,omitempty"` 354 // Text - OCR text content of the recognized field. 355 Text *string `json:"text,omitempty"` 356 // Elements - List of references to OCR words comprising the recognized field value. 357 Elements *[]ElementReference `json:"elements,omitempty"` 358 // ValueType - Possible values include: 'ValueTypeFieldValue', 'ValueTypeStringValue', 'ValueTypeNumberValue' 359 ValueType ValueType `json:"valueType,omitempty"` 360} 361 362// MarshalJSON is the custom marshaler for StringValue. 363func (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// AsStringValue is the BasicFieldValue implementation for StringValue. 382func (sv StringValue) AsStringValue() (*StringValue, bool) { 383 return &sv, true 384} 385 386// AsNumberValue is the BasicFieldValue implementation for StringValue. 387func (sv StringValue) AsNumberValue() (*NumberValue, bool) { 388 return nil, false 389} 390 391// AsFieldValue is the BasicFieldValue implementation for StringValue. 392func (sv StringValue) AsFieldValue() (*FieldValue, bool) { 393 return nil, false 394} 395 396// AsBasicFieldValue is the BasicFieldValue implementation for StringValue. 397func (sv StringValue) AsBasicFieldValue() (BasicFieldValue, bool) { 398 return &sv, true 399} 400 401// TextRecognitionResult an object representing a recognized text region 402type TextRecognitionResult struct { 403 // Page - The 1-based page number of the recognition result. 404 Page *int32 `json:"page,omitempty"` 405 // ClockwiseOrientation - The orientation of the image in degrees in the clockwise direction. Range between [0, 360). 406 ClockwiseOrientation *float64 `json:"clockwiseOrientation,omitempty"` 407 // Width - The width of the image in pixels or the PDF in inches. 408 Width *float64 `json:"width,omitempty"` 409 // Height - The height of the image in pixels or the PDF in inches. 410 Height *float64 `json:"height,omitempty"` 411 // Unit - The unit used in the Width, Height and BoundingBox. For images, the unit is 'pixel'. For PDF, the unit is 'inch'. Possible values include: 'Pixel', 'Inch' 412 Unit TextRecognitionResultDimensionUnit `json:"unit,omitempty"` 413 // Lines - A list of recognized text lines. 414 Lines *[]Line `json:"lines,omitempty"` 415} 416 417// TrainRequest contract to initiate a train request. 418type TrainRequest struct { 419 // Source - Get or set source path. 420 Source *string `json:"source,omitempty"` 421 // SourceFilter - Get or set filter to further search the 422 // source path for content. 423 SourceFilter *TrainSourceFilter `json:"sourceFilter,omitempty"` 424} 425 426// TrainResult response of the Train API call. 427type TrainResult struct { 428 autorest.Response `json:"-"` 429 // ModelID - Identifier of the model. 430 ModelID *uuid.UUID `json:"modelId,omitempty"` 431 // TrainingDocuments - List of documents used to train the model and the 432 // train operation error reported by each. 433 TrainingDocuments *[]FormDocumentReport `json:"trainingDocuments,omitempty"` 434 // Errors - Errors returned during the training operation. 435 Errors *[]FormOperationError `json:"errors,omitempty"` 436} 437 438// TrainSourceFilter filters to be applied when traversing a data source. 439type TrainSourceFilter struct { 440 // Prefix - A case-sensitive prefix string to filter content 441 // under the source location. For e.g., when using a Azure Blob 442 // Uri use the prefix to restrict subfolders for content. 443 Prefix *string `json:"prefix,omitempty"` 444 // IncludeSubFolders - A flag to indicate if sub folders within the set of 445 // prefix folders will also need to be included when searching 446 // for content to be preprocessed. 447 IncludeSubFolders *bool `json:"includeSubFolders,omitempty"` 448} 449 450// UnderstandingResult a set of extracted fields corresponding to a semantic object, such as a receipt, in 451// the input document. 452type UnderstandingResult struct { 453 // Pages - List of pages where the document is found. 454 Pages *[]int32 `json:"pages,omitempty"` 455 // Fields - Dictionary of recognized field values. 456 Fields map[string]BasicFieldValue `json:"fields"` 457} 458 459// MarshalJSON is the custom marshaler for UnderstandingResult. 460func (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// Word an object representing a recognized word. 472type Word struct { 473 // BoundingBox - Bounding box of a recognized word. 474 BoundingBox *[]int32 `json:"boundingBox,omitempty"` 475 // Text - The text content of the word. 476 Text *string `json:"text,omitempty"` 477 // Confidence - Qualitative confidence measure. Possible values include: 'High', 'Low' 478 Confidence TextRecognitionResultConfidenceClass `json:"confidence,omitempty"` 479} 480