From cf015851d65b45a74951e780dc86a791016c4461 Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Fri, 7 Jun 2019 13:15:52 -0700 Subject: [PATCH] [AutoPR cognitiveservices/data-plane/FormRecognizer] FormRecognizer: Updating Train API to take optional parameter. (#4928) * Generated from 0bc60ed42fd5aa7a857431b75a7d9ec7a7e6482d Adding optional support for subfolders in source parameter to Train API. * Generated from 32fa3cb8bf93a50a580b82444835251dde1b09e4 Minor fix to sawgger, removed merged swagger. * Generated from e0c7d245283e52eeca9285dcb4d3f7bdcfb14331 Minor text fix. --- .../formrecognizer/models.go | 56 +++ .../v1.0/formrecognizer/client.go | 258 +++++++++++- .../formrecognizerapi/interfaces.go | 3 + .../v1.0/formrecognizer/models.go | 366 ++++++++++++++++++ 4 files changed, 667 insertions(+), 16 deletions(-) diff --git a/profiles/preview/preview/cognitiveservices/formrecognizer/models.go b/profiles/preview/preview/cognitiveservices/formrecognizer/models.go index 8153d4ec460d..739152aa03ca 100644 --- a/profiles/preview/preview/cognitiveservices/formrecognizer/models.go +++ b/profiles/preview/preview/cognitiveservices/formrecognizer/models.go @@ -45,8 +45,42 @@ const ( Status2Success Status2 = original.Status2Success ) +type TextOperationStatusCodes = original.TextOperationStatusCodes + +const ( + Failed TextOperationStatusCodes = original.Failed + NotStarted TextOperationStatusCodes = original.NotStarted + Running TextOperationStatusCodes = original.Running + Succeeded TextOperationStatusCodes = original.Succeeded +) + +type TextRecognitionResultConfidenceClass = original.TextRecognitionResultConfidenceClass + +const ( + High TextRecognitionResultConfidenceClass = original.High + Low TextRecognitionResultConfidenceClass = original.Low +) + +type TextRecognitionResultDimensionUnit = original.TextRecognitionResultDimensionUnit + +const ( + Inch TextRecognitionResultDimensionUnit = original.Inch + Pixel TextRecognitionResultDimensionUnit = original.Pixel +) + +type ValueType = original.ValueType + +const ( + ValueTypeFieldValue ValueType = original.ValueTypeFieldValue + ValueTypeNumberValue ValueType = original.ValueTypeNumberValue + ValueTypeStringValue ValueType = original.ValueTypeStringValue +) + type AnalyzeResult = original.AnalyzeResult type BaseClient = original.BaseClient +type BasicFieldValue = original.BasicFieldValue +type ComputerVisionError = original.ComputerVisionError +type ElementReference = original.ElementReference type ErrorInformation = original.ErrorInformation type ErrorResponse = original.ErrorResponse type ExtractedKeyValuePair = original.ExtractedKeyValuePair @@ -54,14 +88,24 @@ type ExtractedPage = original.ExtractedPage type ExtractedTable = original.ExtractedTable type ExtractedTableColumn = original.ExtractedTableColumn type ExtractedToken = original.ExtractedToken +type FieldValue = original.FieldValue type FormDocumentReport = original.FormDocumentReport type FormOperationError = original.FormOperationError +type ImageURL = original.ImageURL type InnerError = original.InnerError type KeysResult = original.KeysResult +type Line = original.Line type ModelResult = original.ModelResult type ModelsResult = original.ModelsResult +type NumberValue = original.NumberValue +type ReadReceiptResult = original.ReadReceiptResult +type StringValue = original.StringValue +type TextRecognitionResult = original.TextRecognitionResult type TrainRequest = original.TrainRequest type TrainResult = original.TrainResult +type TrainSourceFilter = original.TrainSourceFilter +type UnderstandingResult = original.UnderstandingResult +type Word = original.Word func New(endpoint string) BaseClient { return original.New(endpoint) @@ -78,6 +122,18 @@ func PossibleStatus2Values() []Status2 { func PossibleStatusValues() []Status { return original.PossibleStatusValues() } +func PossibleTextOperationStatusCodesValues() []TextOperationStatusCodes { + return original.PossibleTextOperationStatusCodesValues() +} +func PossibleTextRecognitionResultConfidenceClassValues() []TextRecognitionResultConfidenceClass { + return original.PossibleTextRecognitionResultConfidenceClassValues() +} +func PossibleTextRecognitionResultDimensionUnitValues() []TextRecognitionResultDimensionUnit { + return original.PossibleTextRecognitionResultDimensionUnitValues() +} +func PossibleValueTypeValues() []ValueType { + return original.PossibleValueTypeValues() +} func UserAgent() string { return original.UserAgent() + " profiles/preview" } diff --git a/services/preview/cognitiveservices/v1.0/formrecognizer/client.go b/services/preview/cognitiveservices/v1.0/formrecognizer/client.go index 5224b2e962d4..cdb2dcccb372 100644 --- a/services/preview/cognitiveservices/v1.0/formrecognizer/client.go +++ b/services/preview/cognitiveservices/v1.0/formrecognizer/client.go @@ -1,7 +1,6 @@ // Package formrecognizer implements the Azure ARM Formrecognizer service API version 1.0-preview. // -// Extracts information from forms and images into structured data based on a model created by a set of representative -// training forms. +// package formrecognizer // Copyright (c) Microsoft and contributors. All rights reserved. @@ -51,9 +50,8 @@ func NewWithoutDefaults(endpoint string) BaseClient { } } -// AnalyzeWithCustomModel the document to analyze must be of a supported content type - 'application/pdf', 'image/jpeg' -// or 'image/png'. The response contains not just the extracted information of the analyzed form but also information -// about content that was not extracted along with a reason. +// AnalyzeWithCustomModel extract key-value pairs from a given document. The input document must be of one of the +// supported content types - 'application/pdf', 'image/jpeg' or 'image/png'. A success response is returned in JSON. // Parameters: // ID - model Identifier to analyze the document with. // formStream - a pdf document or image (jpg,png) file to analyze. @@ -138,6 +136,153 @@ func (client BaseClient) AnalyzeWithCustomModelResponder(resp *http.Response) (r return } +// BatchReadReceipt batch Read Receipt operation. The response contains a field called 'Operation-Location', which +// contains the URL that you must use for your 'Get Read Receipt Result' operation. +// Parameters: +// imageURL - a JSON document with a URL pointing to the image that is to be analyzed. +func (client BaseClient) BatchReadReceipt(ctx context.Context, imageURL ImageURL) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.BatchReadReceipt") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: imageURL, + Constraints: []validation.Constraint{{Target: "imageURL.URL", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { + return result, validation.NewError("formrecognizer.BaseClient", "BatchReadReceipt", err.Error()) + } + + req, err := client.BatchReadReceiptPreparer(ctx, imageURL) + if err != nil { + err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceipt", nil, "Failure preparing request") + return + } + + resp, err := client.BatchReadReceiptSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceipt", resp, "Failure sending request") + return + } + + result, err = client.BatchReadReceiptResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceipt", resp, "Failure responding to request") + } + + return +} + +// BatchReadReceiptPreparer prepares the BatchReadReceipt request. +func (client BaseClient) BatchReadReceiptPreparer(ctx context.Context, imageURL ImageURL) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters), + autorest.WithPath("/prebuilt/receipt/asyncBatchAnalyze"), + autorest.WithJSON(imageURL)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// BatchReadReceiptSender sends the BatchReadReceipt request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) BatchReadReceiptSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// BatchReadReceiptResponder handles the response to the BatchReadReceipt request. The method always +// closes the http.Response Body. +func (client BaseClient) BatchReadReceiptResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + +// BatchReadReceiptInStream read Receipt operation. When you use the 'Batch Read Receipt' interface, the response +// contains a field called 'Operation-Location'. The 'Operation-Location' field contains the URL that you must use for +// your 'Get Read Receipt Result' operation. +// Parameters: +// imageParameter - an image stream. +func (client BaseClient) BatchReadReceiptInStream(ctx context.Context, imageParameter io.ReadCloser) (result autorest.Response, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.BatchReadReceiptInStream") + defer func() { + sc := -1 + if result.Response != nil { + sc = result.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.BatchReadReceiptInStreamPreparer(ctx, imageParameter) + if err != nil { + err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceiptInStream", nil, "Failure preparing request") + return + } + + resp, err := client.BatchReadReceiptInStreamSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceiptInStream", resp, "Failure sending request") + return + } + + result, err = client.BatchReadReceiptInStreamResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "BatchReadReceiptInStream", resp, "Failure responding to request") + } + + return +} + +// BatchReadReceiptInStreamPreparer prepares the BatchReadReceiptInStream request. +func (client BaseClient) BatchReadReceiptInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/octet-stream"), + autorest.AsPost(), + autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters), + autorest.WithPath("/prebuilt/receipt/asyncBatchAnalyze"), + autorest.WithFile(imageParameter)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// BatchReadReceiptInStreamSender sends the BatchReadReceiptInStream request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) BatchReadReceiptInStreamSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// BatchReadReceiptInStreamResponder handles the response to the BatchReadReceiptInStream request. The method always +// closes the http.Response Body. +func (client BaseClient) BatchReadReceiptInStreamResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +} + // DeleteCustomModel delete model artifacts. // Parameters: // ID - the identifier of the model to delete. @@ -281,7 +426,7 @@ func (client BaseClient) GetCustomModelResponder(resp *http.Response) (result Mo return } -// GetCustomModels get information about all trained models +// GetCustomModels get information about all trained custom models func (client BaseClient) GetCustomModels(ctx context.Context) (result ModelsResult, err error) { if tracing.IsEnabled() { ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetCustomModels") @@ -347,8 +492,8 @@ func (client BaseClient) GetCustomModelsResponder(resp *http.Response) (result M return } -// GetExtractedKeys use the API to retrieve the keys that were -// extracted by the specified model. +// GetExtractedKeys retrieve the keys that were +// extracted during the training of the specified model. // Parameters: // ID - model identifier. func (client BaseClient) GetExtractedKeys(ctx context.Context, ID uuid.UUID) (result KeysResult, err error) { @@ -420,14 +565,89 @@ func (client BaseClient) GetExtractedKeysResponder(resp *http.Response) (result return } -// TrainCustomModel the train request must include a source parameter that is either an externally accessible Azure -// Storage blob container Uri (preferably a Shared Access Signature Uri) or valid path to a data folder in a locally -// mounted drive. When local paths are specified, they must follow the Linux/Unix path format and be an absolute path -// rooted to the input mount configuration +// GetReadReceiptResult this interface is used for getting the analysis results of a 'Batch Read Receipt' operation. +// The URL to this interface should be retrieved from the 'Operation-Location' field returned from the 'Batch Read +// Receipt' operation. +// Parameters: +// operationID - id of read operation returned in the response of a 'Batch Read Receipt' operation. +func (client BaseClient) GetReadReceiptResult(ctx context.Context, operationID string) (result ReadReceiptResult, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetReadReceiptResult") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + req, err := client.GetReadReceiptResultPreparer(ctx, operationID) + if err != nil { + err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetReadReceiptResult", nil, "Failure preparing request") + return + } + + resp, err := client.GetReadReceiptResultSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetReadReceiptResult", resp, "Failure sending request") + return + } + + result, err = client.GetReadReceiptResultResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "formrecognizer.BaseClient", "GetReadReceiptResult", resp, "Failure responding to request") + } + + return +} + +// GetReadReceiptResultPreparer prepares the GetReadReceiptResult request. +func (client BaseClient) GetReadReceiptResultPreparer(ctx context.Context, operationID string) (*http.Request, error) { + urlParameters := map[string]interface{}{ + "Endpoint": client.Endpoint, + } + + pathParameters := map[string]interface{}{ + "operationId": autorest.Encode("path", operationID), + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithCustomBaseURL("{Endpoint}/formrecognizer/v1.0-preview", urlParameters), + autorest.WithPathParameters("/prebuilt/receipt/operations/{operationId}", pathParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetReadReceiptResultSender sends the GetReadReceiptResult request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) GetReadReceiptResultSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetReadReceiptResultResponder handles the response to the GetReadReceiptResult request. The method always +// closes the http.Response Body. +func (client BaseClient) GetReadReceiptResultResponder(resp *http.Response) (result ReadReceiptResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// TrainCustomModel create and train a custom model. The train request must include a source parameter that is either +// an externally accessible Azure Storage blob container Uri (preferably a Shared Access Signature Uri) or valid path +// to a data folder in a locally mounted drive. When local paths are specified, they must follow the Linux/Unix path +// format and be an absolute path rooted to the input mount configuration // setting value e.g., if '{Mounts:Input}' configuration setting value is '/input' then a valid source path would be -// '/input/contosodataset'. All data to be trained are expected to be under the source. Models are trained using -// documents that are of the following content type - 'application/pdf', 'image/jpeg' and 'image/png'." -// Other content is ignored when training a model. +// '/input/contosodataset'. All data to be trained is expected to be directly under the source folder. Subfolders are +// not supported. Models are trained using documents that are of the following content type - 'application/pdf', +// 'image/jpeg' and 'image/png'." +// Other type of content is ignored. // Parameters: // trainRequest - request object for training. func (client BaseClient) TrainCustomModel(ctx context.Context, trainRequest TrainRequest) (result TrainResult, err error) { @@ -446,7 +666,13 @@ func (client BaseClient) TrainCustomModel(ctx context.Context, trainRequest Trai Constraints: []validation.Constraint{{Target: "trainRequest.Source", Name: validation.Null, Rule: true, Chain: []validation.Constraint{{Target: "trainRequest.Source", Name: validation.MaxLength, Rule: 2048, Chain: nil}, {Target: "trainRequest.Source", Name: validation.MinLength, Rule: 0, Chain: nil}, - }}}}}); err != nil { + }}, + {Target: "trainRequest.SourceFilter", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "trainRequest.SourceFilter.Prefix", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "trainRequest.SourceFilter.Prefix", Name: validation.MaxLength, Rule: 128, Chain: nil}, + {Target: "trainRequest.SourceFilter.Prefix", Name: validation.MinLength, Rule: 0, Chain: nil}, + }}, + }}}}}); err != nil { return result, validation.NewError("formrecognizer.BaseClient", "TrainCustomModel", err.Error()) } diff --git a/services/preview/cognitiveservices/v1.0/formrecognizer/formrecognizerapi/interfaces.go b/services/preview/cognitiveservices/v1.0/formrecognizer/formrecognizerapi/interfaces.go index f6b9defce199..0612f67133db 100644 --- a/services/preview/cognitiveservices/v1.0/formrecognizer/formrecognizerapi/interfaces.go +++ b/services/preview/cognitiveservices/v1.0/formrecognizer/formrecognizerapi/interfaces.go @@ -28,10 +28,13 @@ import ( // BaseClientAPI contains the set of methods on the BaseClient type. type BaseClientAPI interface { AnalyzeWithCustomModel(ctx context.Context, ID uuid.UUID, formStream io.ReadCloser, keys []string) (result formrecognizer.AnalyzeResult, err error) + BatchReadReceipt(ctx context.Context, imageURL formrecognizer.ImageURL) (result autorest.Response, err error) + BatchReadReceiptInStream(ctx context.Context, imageParameter io.ReadCloser) (result autorest.Response, err error) DeleteCustomModel(ctx context.Context, ID uuid.UUID) (result autorest.Response, err error) GetCustomModel(ctx context.Context, ID uuid.UUID) (result formrecognizer.ModelResult, err error) GetCustomModels(ctx context.Context) (result formrecognizer.ModelsResult, err error) GetExtractedKeys(ctx context.Context, ID uuid.UUID) (result formrecognizer.KeysResult, err error) + GetReadReceiptResult(ctx context.Context, operationID string) (result formrecognizer.ReadReceiptResult, err error) TrainCustomModel(ctx context.Context, trainRequest formrecognizer.TrainRequest) (result formrecognizer.TrainResult, err error) } diff --git a/services/preview/cognitiveservices/v1.0/formrecognizer/models.go b/services/preview/cognitiveservices/v1.0/formrecognizer/models.go index ae1b882064fa..52708597cd73 100644 --- a/services/preview/cognitiveservices/v1.0/formrecognizer/models.go +++ b/services/preview/cognitiveservices/v1.0/formrecognizer/models.go @@ -78,6 +78,72 @@ func PossibleStatus2Values() []Status2 { return []Status2{Status2Failure, Status2PartialSuccess, Status2Success} } +// TextOperationStatusCodes enumerates the values for text operation status codes. +type TextOperationStatusCodes string + +const ( + // Failed ... + Failed TextOperationStatusCodes = "Failed" + // NotStarted ... + NotStarted TextOperationStatusCodes = "Not Started" + // Running ... + Running TextOperationStatusCodes = "Running" + // Succeeded ... + Succeeded TextOperationStatusCodes = "Succeeded" +) + +// PossibleTextOperationStatusCodesValues returns an array of possible values for the TextOperationStatusCodes const type. +func PossibleTextOperationStatusCodesValues() []TextOperationStatusCodes { + return []TextOperationStatusCodes{Failed, NotStarted, Running, Succeeded} +} + +// TextRecognitionResultConfidenceClass enumerates the values for text recognition result confidence class. +type TextRecognitionResultConfidenceClass string + +const ( + // High ... + High TextRecognitionResultConfidenceClass = "High" + // Low ... + Low TextRecognitionResultConfidenceClass = "Low" +) + +// PossibleTextRecognitionResultConfidenceClassValues returns an array of possible values for the TextRecognitionResultConfidenceClass const type. +func PossibleTextRecognitionResultConfidenceClassValues() []TextRecognitionResultConfidenceClass { + return []TextRecognitionResultConfidenceClass{High, Low} +} + +// TextRecognitionResultDimensionUnit enumerates the values for text recognition result dimension unit. +type TextRecognitionResultDimensionUnit string + +const ( + // Inch ... + Inch TextRecognitionResultDimensionUnit = "inch" + // Pixel ... + Pixel TextRecognitionResultDimensionUnit = "pixel" +) + +// PossibleTextRecognitionResultDimensionUnitValues returns an array of possible values for the TextRecognitionResultDimensionUnit const type. +func PossibleTextRecognitionResultDimensionUnitValues() []TextRecognitionResultDimensionUnit { + return []TextRecognitionResultDimensionUnit{Inch, Pixel} +} + +// ValueType enumerates the values for value type. +type ValueType string + +const ( + // ValueTypeFieldValue ... + ValueTypeFieldValue ValueType = "fieldValue" + // ValueTypeNumberValue ... + ValueTypeNumberValue ValueType = "numberValue" + // ValueTypeStringValue ... + ValueTypeStringValue ValueType = "stringValue" +) + +// PossibleValueTypeValues returns an array of possible values for the ValueType const type. +func PossibleValueTypeValues() []ValueType { + return []ValueType{ValueTypeFieldValue, ValueTypeNumberValue, ValueTypeStringValue} +} + // AnalyzeResult analyze API call result. type AnalyzeResult struct { autorest.Response `json:"-"` @@ -91,6 +157,21 @@ type AnalyzeResult struct { Errors *[]FormOperationError `json:"errors,omitempty"` } +// ComputerVisionError details about the API request error. +type ComputerVisionError struct { + // Code - The error code. + Code interface{} `json:"code,omitempty"` + // Message - A message explaining the error reported by the service. + Message *string `json:"message,omitempty"` + // RequestID - A unique request identifier. + RequestID *string `json:"requestId,omitempty"` +} + +// ElementReference reference to an OCR word. +type ElementReference struct { + Ref *string `json:"$ref,omitempty"` +} + // ErrorInformation ... type ErrorInformation struct { Code *string `json:"code,omitempty"` @@ -162,6 +243,100 @@ type ExtractedToken struct { Confidence *float64 `json:"confidence,omitempty"` } +// BasicFieldValue base class representing a recognized field value. +type BasicFieldValue interface { + AsStringValue() (*StringValue, bool) + AsNumberValue() (*NumberValue, bool) + AsFieldValue() (*FieldValue, bool) +} + +// FieldValue base class representing a recognized field value. +type FieldValue struct { + // Text - OCR text content of the recognized field. + Text *string `json:"text,omitempty"` + // Elements - List of references to OCR words comprising the recognized field value. + Elements *[]ElementReference `json:"elements,omitempty"` + // ValueType - Possible values include: 'ValueTypeFieldValue', 'ValueTypeStringValue', 'ValueTypeNumberValue' + ValueType ValueType `json:"valueType,omitempty"` +} + +func unmarshalBasicFieldValue(body []byte) (BasicFieldValue, error) { + var m map[string]interface{} + err := json.Unmarshal(body, &m) + if err != nil { + return nil, err + } + + switch m["valueType"] { + case string(ValueTypeStringValue): + var sv StringValue + err := json.Unmarshal(body, &sv) + return sv, err + case string(ValueTypeNumberValue): + var nv NumberValue + err := json.Unmarshal(body, &nv) + return nv, err + default: + var fv FieldValue + err := json.Unmarshal(body, &fv) + return fv, err + } +} +func unmarshalBasicFieldValueArray(body []byte) ([]BasicFieldValue, error) { + var rawMessages []*json.RawMessage + err := json.Unmarshal(body, &rawMessages) + if err != nil { + return nil, err + } + + fvArray := make([]BasicFieldValue, len(rawMessages)) + + for index, rawMessage := range rawMessages { + fv, err := unmarshalBasicFieldValue(*rawMessage) + if err != nil { + return nil, err + } + fvArray[index] = fv + } + return fvArray, nil +} + +// MarshalJSON is the custom marshaler for FieldValue. +func (fv FieldValue) MarshalJSON() ([]byte, error) { + fv.ValueType = ValueTypeFieldValue + objectMap := make(map[string]interface{}) + if fv.Text != nil { + objectMap["text"] = fv.Text + } + if fv.Elements != nil { + objectMap["elements"] = fv.Elements + } + if fv.ValueType != "" { + objectMap["valueType"] = fv.ValueType + } + return json.Marshal(objectMap) +} + +// AsStringValue is the BasicFieldValue implementation for FieldValue. +func (fv FieldValue) AsStringValue() (*StringValue, bool) { + return nil, false +} + +// AsNumberValue is the BasicFieldValue implementation for FieldValue. +func (fv FieldValue) AsNumberValue() (*NumberValue, bool) { + return nil, false +} + +// AsFieldValue is the BasicFieldValue implementation for FieldValue. +func (fv FieldValue) AsFieldValue() (*FieldValue, bool) { + return &fv, true +} + +// AsBasicFieldValue is the BasicFieldValue implementation for FieldValue. +func (fv FieldValue) AsBasicFieldValue() (BasicFieldValue, bool) { + return &fv, true +} + // FormDocumentReport ... type FormDocumentReport struct { // DocumentName - Reference to the data that the report is for. @@ -180,6 +355,12 @@ type FormOperationError struct { ErrorMessage *string `json:"errorMessage,omitempty"` } +// ImageURL ... +type ImageURL struct { + // URL - Publicly reachable URL of an image. + URL *string `json:"url,omitempty"` +} + // InnerError ... type InnerError struct { RequestID *string `json:"requestId,omitempty"` @@ -202,6 +383,16 @@ func (kr KeysResult) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } +// Line an object representing a recognized text line. +type Line struct { + // BoundingBox - Bounding box of a recognized line. + BoundingBox *[]int32 `json:"boundingBox,omitempty"` + // Text - The text content of the line. + Text *string `json:"text,omitempty"` + // Words - List of words in the text line. + Words *[]Word `json:"words,omitempty"` +} + // ModelResult result of a model status query operation. type ModelResult struct { autorest.Response `json:"-"` @@ -222,10 +413,142 @@ type ModelsResult struct { ModelsProperty *[]ModelResult `json:"models,omitempty"` } +// NumberValue recognized numeric field value. +type NumberValue struct { + // Value - Numeric value of the recognized field. + Value *float64 `json:"value,omitempty"` + // Text - OCR text content of the recognized field. + Text *string `json:"text,omitempty"` + // Elements - List of references to OCR words comprising the recognized field value. + Elements *[]ElementReference `json:"elements,omitempty"` + // ValueType - Possible values include: 'ValueTypeFieldValue', 'ValueTypeStringValue', 'ValueTypeNumberValue' + ValueType ValueType `json:"valueType,omitempty"` +} + +// MarshalJSON is the custom marshaler for NumberValue. +func (nv NumberValue) MarshalJSON() ([]byte, error) { + nv.ValueType = ValueTypeNumberValue + objectMap := make(map[string]interface{}) + if nv.Value != nil { + objectMap["value"] = nv.Value + } + if nv.Text != nil { + objectMap["text"] = nv.Text + } + if nv.Elements != nil { + objectMap["elements"] = nv.Elements + } + if nv.ValueType != "" { + objectMap["valueType"] = nv.ValueType + } + return json.Marshal(objectMap) +} + +// AsStringValue is the BasicFieldValue implementation for NumberValue. +func (nv NumberValue) AsStringValue() (*StringValue, bool) { + return nil, false +} + +// AsNumberValue is the BasicFieldValue implementation for NumberValue. +func (nv NumberValue) AsNumberValue() (*NumberValue, bool) { + return &nv, true +} + +// AsFieldValue is the BasicFieldValue implementation for NumberValue. +func (nv NumberValue) AsFieldValue() (*FieldValue, bool) { + return nil, false +} + +// AsBasicFieldValue is the BasicFieldValue implementation for NumberValue. +func (nv NumberValue) AsBasicFieldValue() (BasicFieldValue, bool) { + return &nv, true +} + +// ReadReceiptResult analysis result of the 'Batch Read Receipt' operation. +type ReadReceiptResult struct { + autorest.Response `json:"-"` + // Status - Status of the read operation. Possible values include: 'NotStarted', 'Running', 'Failed', 'Succeeded' + Status TextOperationStatusCodes `json:"status,omitempty"` + // RecognitionResults - Text recognition result of the 'Batch Read Receipt' operation. + RecognitionResults *[]TextRecognitionResult `json:"recognitionResults,omitempty"` + // UnderstandingResults - Semantic understanding result of the 'Batch Read Receipt' operation. + UnderstandingResults *[]UnderstandingResult `json:"understandingResults,omitempty"` +} + +// StringValue recognized string field value. +type StringValue struct { + // Value - String value of the recognized field. + Value *string `json:"value,omitempty"` + // Text - OCR text content of the recognized field. + Text *string `json:"text,omitempty"` + // Elements - List of references to OCR words comprising the recognized field value. + Elements *[]ElementReference `json:"elements,omitempty"` + // ValueType - Possible values include: 'ValueTypeFieldValue', 'ValueTypeStringValue', 'ValueTypeNumberValue' + ValueType ValueType `json:"valueType,omitempty"` +} + +// MarshalJSON is the custom marshaler for StringValue. +func (sv StringValue) MarshalJSON() ([]byte, error) { + sv.ValueType = ValueTypeStringValue + objectMap := make(map[string]interface{}) + if sv.Value != nil { + objectMap["value"] = sv.Value + } + if sv.Text != nil { + objectMap["text"] = sv.Text + } + if sv.Elements != nil { + objectMap["elements"] = sv.Elements + } + if sv.ValueType != "" { + objectMap["valueType"] = sv.ValueType + } + return json.Marshal(objectMap) +} + +// AsStringValue is the BasicFieldValue implementation for StringValue. +func (sv StringValue) AsStringValue() (*StringValue, bool) { + return &sv, true +} + +// AsNumberValue is the BasicFieldValue implementation for StringValue. +func (sv StringValue) AsNumberValue() (*NumberValue, bool) { + return nil, false +} + +// AsFieldValue is the BasicFieldValue implementation for StringValue. +func (sv StringValue) AsFieldValue() (*FieldValue, bool) { + return nil, false +} + +// AsBasicFieldValue is the BasicFieldValue implementation for StringValue. +func (sv StringValue) AsBasicFieldValue() (BasicFieldValue, bool) { + return &sv, true +} + +// TextRecognitionResult an object representing a recognized text region +type TextRecognitionResult struct { + // Page - The 1-based page number of the recognition result. + Page *int32 `json:"page,omitempty"` + // ClockwiseOrientation - The orientation of the image in degrees in the clockwise direction. Range between [0, 360). + ClockwiseOrientation *float64 `json:"clockwiseOrientation,omitempty"` + // Width - The width of the image in pixels or the PDF in inches. + Width *float64 `json:"width,omitempty"` + // Height - The height of the image in pixels or the PDF in inches. + Height *float64 `json:"height,omitempty"` + // 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' + Unit TextRecognitionResultDimensionUnit `json:"unit,omitempty"` + // Lines - A list of recognized text lines. + Lines *[]Line `json:"lines,omitempty"` +} + // TrainRequest contract to initiate a train request. type TrainRequest struct { // Source - Get or set source path. Source *string `json:"source,omitempty"` + // SourceFilter - Get or set filter to further search the + // source path for content. + SourceFilter *TrainSourceFilter `json:"sourceFilter,omitempty"` } // TrainResult response of the Train API call. @@ -239,3 +562,46 @@ type TrainResult struct { // Errors - Errors returned during the training operation. Errors *[]FormOperationError `json:"errors,omitempty"` } + +// TrainSourceFilter filters to be applied when traversing a data source. +type TrainSourceFilter struct { + // Prefix - A case-sensitive prefix string to filter content + // under the source location. For e.g., when using a Azure Blob + // Uri use the prefix to restrict subfolders for content. + Prefix *string `json:"prefix,omitempty"` + // IncludeSubFolders - A flag to indicate if sub folders within the set of + // prefix folders will also need to be included when searching + // for content to be preprocessed. + IncludeSubFolders *bool `json:"includeSubFolders,omitempty"` +} + +// UnderstandingResult a set of extracted fields corresponding to a semantic object, such as a receipt, in +// the input document. +type UnderstandingResult struct { + // Pages - List of pages where the document is found. + Pages *[]int32 `json:"pages,omitempty"` + // Fields - Dictionary of recognized field values. + Fields map[string]*FieldValue `json:"fields"` +} + +// MarshalJSON is the custom marshaler for UnderstandingResult. +func (ur UnderstandingResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ur.Pages != nil { + objectMap["pages"] = ur.Pages + } + if ur.Fields != nil { + objectMap["fields"] = ur.Fields + } + return json.Marshal(objectMap) +} + +// Word an object representing a recognized word. +type Word struct { + // BoundingBox - Bounding box of a recognized word. + BoundingBox *[]int32 `json:"boundingBox,omitempty"` + // Text - The text content of the word. + Text *string `json:"text,omitempty"` + // Confidence - Qualitative confidence measure. Possible values include: 'High', 'Low' + Confidence TextRecognitionResultConfidenceClass `json:"confidence,omitempty"` +}