From 6097d1d7c9e8b65b4bae18872c782718c2f28576 Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Tue, 29 May 2018 15:24:50 +0000 Subject: [PATCH] Generated from bd6c66b615b94480a1458dde3a8bc42f3a689548 ComputerVision - collection of fixes * fix ocr language parameter to fix [bug](https://github.com/Azure/azure-sdk-for-net/issues/4083) * language parameter missing for /tag path * language parameter missing for /models/*/analyze path * make /models/*/analyze return a more generic type * add specific types for /models/*/analyze to return for current models --- .../computervision/models.go | 14 +-- .../computervision/models.go | 14 +-- .../v1.0/computervision/client.go | 57 +++++++-- .../v1.0/computervision/models.go | 110 +++++------------- 4 files changed, 80 insertions(+), 115 deletions(-) diff --git a/profiles/latest/cognitiveservices/computervision/models.go b/profiles/latest/cognitiveservices/computervision/models.go index 954a0e004ccb..be9b19dad644 100644 --- a/profiles/latest/cognitiveservices/computervision/models.go +++ b/profiles/latest/cognitiveservices/computervision/models.go @@ -46,13 +46,6 @@ const ( Landmarks Details = original.Landmarks ) -type DomainModels = original.DomainModels - -const ( - DomainModelsCelebrities DomainModels = original.DomainModelsCelebrities - DomainModelsLandmarks DomainModels = original.DomainModelsLandmarks -) - type ErrorCodes = original.ErrorCodes const ( @@ -135,8 +128,8 @@ type AdultInfo = original.AdultInfo type Category = original.Category type CategoryDetail = original.CategoryDetail type CelebritiesModel = original.CelebritiesModel +type CelebrityResults = original.CelebrityResults type ColorInfo = original.ColorInfo -type DomainModelResult = original.DomainModelResult type DomainModelResults = original.DomainModelResults type Error = original.Error type FaceDescription = original.FaceDescription @@ -149,6 +142,8 @@ type ImageMetadata = original.ImageMetadata type ImageTag = original.ImageTag type ImageType = original.ImageType type ImageURL = original.ImageURL +type LandmarkResults = original.LandmarkResults +type LandmarkResultsLandmarksItem = original.LandmarkResultsLandmarksItem type Line = original.Line type ListModelsResult = original.ListModelsResult type ModelDescription = original.ModelDescription @@ -174,9 +169,6 @@ func PossibleAzureRegionsValues() []AzureRegions { func PossibleDetailsValues() []Details { return original.PossibleDetailsValues() } -func PossibleDomainModelsValues() []DomainModels { - return original.PossibleDomainModelsValues() -} func PossibleErrorCodesValues() []ErrorCodes { return original.PossibleErrorCodesValues() } diff --git a/profiles/preview/cognitiveservices/computervision/models.go b/profiles/preview/cognitiveservices/computervision/models.go index bbb11cb1d0a7..1bb2df90a345 100644 --- a/profiles/preview/cognitiveservices/computervision/models.go +++ b/profiles/preview/cognitiveservices/computervision/models.go @@ -46,13 +46,6 @@ const ( Landmarks Details = original.Landmarks ) -type DomainModels = original.DomainModels - -const ( - DomainModelsCelebrities DomainModels = original.DomainModelsCelebrities - DomainModelsLandmarks DomainModels = original.DomainModelsLandmarks -) - type ErrorCodes = original.ErrorCodes const ( @@ -135,8 +128,8 @@ type AdultInfo = original.AdultInfo type Category = original.Category type CategoryDetail = original.CategoryDetail type CelebritiesModel = original.CelebritiesModel +type CelebrityResults = original.CelebrityResults type ColorInfo = original.ColorInfo -type DomainModelResult = original.DomainModelResult type DomainModelResults = original.DomainModelResults type Error = original.Error type FaceDescription = original.FaceDescription @@ -149,6 +142,8 @@ type ImageMetadata = original.ImageMetadata type ImageTag = original.ImageTag type ImageType = original.ImageType type ImageURL = original.ImageURL +type LandmarkResults = original.LandmarkResults +type LandmarkResultsLandmarksItem = original.LandmarkResultsLandmarksItem type Line = original.Line type ListModelsResult = original.ListModelsResult type ModelDescription = original.ModelDescription @@ -174,9 +169,6 @@ func PossibleAzureRegionsValues() []AzureRegions { func PossibleDetailsValues() []Details { return original.PossibleDetailsValues() } -func PossibleDomainModelsValues() []DomainModels { - return original.PossibleDomainModelsValues() -} func PossibleErrorCodesValues() []ErrorCodes { return original.PossibleErrorCodesValues() } diff --git a/services/cognitiveservices/v1.0/computervision/client.go b/services/cognitiveservices/v1.0/computervision/client.go index 5c695f7e7836..42cfc89eb292 100644 --- a/services/cognitiveservices/v1.0/computervision/client.go +++ b/services/cognitiveservices/v1.0/computervision/client.go @@ -157,14 +157,17 @@ func (client BaseClient) AnalyzeImageResponder(resp *http.Response) (result Imag // Parameters: // model - the domain-specific content to recognize. // imageURL - a JSON document with a URL pointing to the image that is to be analyzed. -func (client BaseClient) AnalyzeImageByDomain(ctx context.Context, model DomainModels, imageURL ImageURL) (result DomainModelResults, err error) { +// language - the desired language for output generation. If this parameter is not specified, the default value +// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified +// Chinese. +func (client BaseClient) AnalyzeImageByDomain(ctx context.Context, model string, imageURL ImageURL, language string) (result DomainModelResults, err error) { 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("computervision.BaseClient", "AnalyzeImageByDomain", err.Error()) } - req, err := client.AnalyzeImageByDomainPreparer(ctx, model, imageURL) + req, err := client.AnalyzeImageByDomainPreparer(ctx, model, imageURL, language) if err != nil { err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomain", nil, "Failure preparing request") return @@ -186,7 +189,7 @@ func (client BaseClient) AnalyzeImageByDomain(ctx context.Context, model DomainM } // AnalyzeImageByDomainPreparer prepares the AnalyzeImageByDomain request. -func (client BaseClient) AnalyzeImageByDomainPreparer(ctx context.Context, model DomainModels, imageURL ImageURL) (*http.Request, error) { +func (client BaseClient) AnalyzeImageByDomainPreparer(ctx context.Context, model string, imageURL ImageURL, language string) (*http.Request, error) { urlParameters := map[string]interface{}{ "AzureRegion": client.AzureRegion, } @@ -195,12 +198,20 @@ func (client BaseClient) AnalyzeImageByDomainPreparer(ctx context.Context, model "model": autorest.Encode("path", model), } + queryParameters := map[string]interface{}{} + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "en") + } + preparer := autorest.CreatePreparer( autorest.AsContentType("application/json; charset=utf-8"), autorest.AsPost(), autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v1.0", urlParameters), autorest.WithPathParameters("/models/{model}/analyze", pathParameters), - autorest.WithJSON(imageURL)) + autorest.WithJSON(imageURL), + autorest.WithQueryParameters(queryParameters)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) } @@ -232,8 +243,11 @@ func (client BaseClient) AnalyzeImageByDomainResponder(resp *http.Response) (res // Parameters: // model - the domain-specific content to recognize. // imageParameter - an image stream. -func (client BaseClient) AnalyzeImageByDomainInStream(ctx context.Context, model string, imageParameter io.ReadCloser) (result DomainModelResults, err error) { - req, err := client.AnalyzeImageByDomainInStreamPreparer(ctx, model, imageParameter) +// language - the desired language for output generation. If this parameter is not specified, the default value +// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified +// Chinese. +func (client BaseClient) AnalyzeImageByDomainInStream(ctx context.Context, model string, imageParameter io.ReadCloser, language string) (result DomainModelResults, err error) { + req, err := client.AnalyzeImageByDomainInStreamPreparer(ctx, model, imageParameter, language) if err != nil { err = autorest.NewErrorWithError(err, "computervision.BaseClient", "AnalyzeImageByDomainInStream", nil, "Failure preparing request") return @@ -255,7 +269,7 @@ func (client BaseClient) AnalyzeImageByDomainInStream(ctx context.Context, model } // AnalyzeImageByDomainInStreamPreparer prepares the AnalyzeImageByDomainInStream request. -func (client BaseClient) AnalyzeImageByDomainInStreamPreparer(ctx context.Context, model string, imageParameter io.ReadCloser) (*http.Request, error) { +func (client BaseClient) AnalyzeImageByDomainInStreamPreparer(ctx context.Context, model string, imageParameter io.ReadCloser, language string) (*http.Request, error) { urlParameters := map[string]interface{}{ "AzureRegion": client.AzureRegion, } @@ -264,12 +278,20 @@ func (client BaseClient) AnalyzeImageByDomainInStreamPreparer(ctx context.Contex "model": autorest.Encode("path", model), } + queryParameters := map[string]interface{}{} + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "en") + } + preparer := autorest.CreatePreparer( autorest.AsContentType("application/octet-stream"), autorest.AsPost(), autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v1.0", urlParameters), autorest.WithPathParameters("/models/{model}/analyze", pathParameters), - autorest.WithFile(imageParameter)) + autorest.WithFile(imageParameter), + autorest.WithQueryParameters(queryParameters)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) } @@ -1247,8 +1269,11 @@ func (client BaseClient) TagImageResponder(resp *http.Response) (result TagResul // accompanied by the hint 'musical instrument'. All tags are in English. // Parameters: // imageParameter - an image stream. -func (client BaseClient) TagImageInStream(ctx context.Context, imageParameter io.ReadCloser) (result TagResult, err error) { - req, err := client.TagImageInStreamPreparer(ctx, imageParameter) +// language - the desired language for output generation. If this parameter is not specified, the default value +// is "en".Supported languages:en - English, Default.ja - Japanese pt - Portuguese zh - Simplified +// Chinese. +func (client BaseClient) TagImageInStream(ctx context.Context, imageParameter io.ReadCloser, language string) (result TagResult, err error) { + req, err := client.TagImageInStreamPreparer(ctx, imageParameter, language) if err != nil { err = autorest.NewErrorWithError(err, "computervision.BaseClient", "TagImageInStream", nil, "Failure preparing request") return @@ -1270,17 +1295,25 @@ func (client BaseClient) TagImageInStream(ctx context.Context, imageParameter io } // TagImageInStreamPreparer prepares the TagImageInStream request. -func (client BaseClient) TagImageInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser) (*http.Request, error) { +func (client BaseClient) TagImageInStreamPreparer(ctx context.Context, imageParameter io.ReadCloser, language string) (*http.Request, error) { urlParameters := map[string]interface{}{ "AzureRegion": client.AzureRegion, } + queryParameters := map[string]interface{}{} + if len(string(language)) > 0 { + queryParameters["language"] = autorest.Encode("query", language) + } else { + queryParameters["language"] = autorest.Encode("query", "en") + } + preparer := autorest.CreatePreparer( autorest.AsContentType("application/octet-stream"), autorest.AsPost(), autorest.WithCustomBaseURL("https://{AzureRegion}.api.cognitive.microsoft.com/vision/v1.0", urlParameters), autorest.WithPath("/tag"), - autorest.WithFile(imageParameter)) + autorest.WithFile(imageParameter), + autorest.WithQueryParameters(queryParameters)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) } diff --git a/services/cognitiveservices/v1.0/computervision/models.go b/services/cognitiveservices/v1.0/computervision/models.go index d342a5268f17..d740047c3945 100644 --- a/services/cognitiveservices/v1.0/computervision/models.go +++ b/services/cognitiveservices/v1.0/computervision/models.go @@ -73,21 +73,6 @@ func PossibleDetailsValues() []Details { return []Details{Celebrities, Landmarks} } -// DomainModels enumerates the values for domain models. -type DomainModels string - -const ( - // DomainModelsCelebrities ... - DomainModelsCelebrities DomainModels = "Celebrities" - // DomainModelsLandmarks ... - DomainModelsLandmarks DomainModels = "Landmarks" -) - -// PossibleDomainModelsValues returns an array of possible values for the DomainModels const type. -func PossibleDomainModelsValues() []DomainModels { - return []DomainModels{DomainModelsCelebrities, DomainModelsLandmarks} -} - // ErrorCodes enumerates the values for error codes. type ErrorCodes string @@ -285,6 +270,14 @@ type CelebritiesModel struct { FaceRectangle *FaceRectangle `json:"faceRectangle,omitempty"` } +// CelebrityResults list of celebrities recognized in the image. +type CelebrityResults struct { + Celebrities *[]CelebritiesModel `json:"celebrities,omitempty"` + // RequestID - Id of the REST API request. + RequestID *string `json:"requestId,omitempty"` + Metadata *ImageMetadata `json:"metadata,omitempty"` +} + // ColorInfo an object providing additional metadata describing color attributes. type ColorInfo struct { // DominantColorForeground - Possible dominant foreground color. @@ -299,78 +292,16 @@ type ColorInfo struct { IsBWImg *bool `json:"isBWImg,omitempty"` } -// DomainModelResult ... -type DomainModelResult struct { - // Celebrities - An array of possible celebritied identified in the image. - Celebrities *[]CelebritiesModel `json:"celebrities,omitempty"` -} - // DomainModelResults result of image analysis using a specific domain model including additional metadata. type DomainModelResults struct { - autorest.Response `json:"-"` - *DomainModelResult `json:"result,omitempty"` + autorest.Response `json:"-"` + // Result - Model-specific response + Result interface{} `json:"result,omitempty"` // RequestID - Id of the REST API request. RequestID *string `json:"requestId,omitempty"` Metadata *ImageMetadata `json:"metadata,omitempty"` } -// MarshalJSON is the custom marshaler for DomainModelResults. -func (dmr DomainModelResults) MarshalJSON() ([]byte, error) { - objectMap := make(map[string]interface{}) - if dmr.DomainModelResult != nil { - objectMap["result"] = dmr.DomainModelResult - } - if dmr.RequestID != nil { - objectMap["requestId"] = dmr.RequestID - } - if dmr.Metadata != nil { - objectMap["metadata"] = dmr.Metadata - } - return json.Marshal(objectMap) -} - -// UnmarshalJSON is the custom unmarshaler for DomainModelResults struct. -func (dmr *DomainModelResults) UnmarshalJSON(body []byte) error { - var m map[string]*json.RawMessage - err := json.Unmarshal(body, &m) - if err != nil { - return err - } - for k, v := range m { - switch k { - case "result": - if v != nil { - var domainModelResult DomainModelResult - err = json.Unmarshal(*v, &domainModelResult) - if err != nil { - return err - } - dmr.DomainModelResult = &domainModelResult - } - case "requestId": - if v != nil { - var requestID string - err = json.Unmarshal(*v, &requestID) - if err != nil { - return err - } - dmr.RequestID = &requestID - } - case "metadata": - if v != nil { - var metadata ImageMetadata - err = json.Unmarshal(*v, &metadata) - if err != nil { - return err - } - dmr.Metadata = &metadata - } - } - } - - return nil -} - // Error ... type Error struct { // Code - The error code. Possible values include: 'InvalidImageURL', 'InvalidImageFormat', 'InvalidImageSize', 'NotSupportedVisualFeature', 'NotSupportedImage', 'InvalidDetails', 'NotSupportedLanguage', 'BadArgument', 'FailedToProcess', 'Timeout', 'InternalServerError', 'Unspecified', 'StorageException' @@ -512,6 +443,22 @@ type ImageURL struct { URL *string `json:"url,omitempty"` } +// LandmarkResults list of landmarks recognized in the image. +type LandmarkResults struct { + Landmarks *[]LandmarkResultsLandmarksItem `json:"landmarks,omitempty"` + // RequestID - Id of the REST API request. + RequestID *string `json:"requestId,omitempty"` + Metadata *ImageMetadata `json:"metadata,omitempty"` +} + +// LandmarkResultsLandmarksItem a landmark recognized in the image +type LandmarkResultsLandmarksItem struct { + // Name - Name of the landmark. + Name *string `json:"name,omitempty"` + // Confidence - Confidence level for the landmark recognition. + Confidence *float64 `json:"confidence,omitempty"` +} + // Line ... type Line struct { BoundingBox *[]int32 `json:"boundingBox,omitempty"` @@ -550,7 +497,8 @@ type OcrRegion struct { // OcrResult ... type OcrResult struct { autorest.Response `json:"-"` - Language *OcrResult `json:"language,omitempty"` + // Language - The BCP-47 language code of the text in the image. + Language *string `json:"language,omitempty"` // TextAngle - The angle, in degrees, of the detected text with respect to the closest horizontal or vertical direction. After rotating the input image clockwise by this angle, the recognized text lines become horizontal or vertical. In combination with the orientation property it can be used to overlay recognition results correctly on the original image, by rotating either the original image or recognition results by a suitable angle around the center of the original image. If the angle cannot be confidently detected, this property is not present. If the image contains text at different angles, only part of the text will be recognized correctly. TextAngle *float64 `json:"textAngle,omitempty"` // Orientation - Orientation of the text recognized in the image. The value (up,down,left, or right) refers to the direction that the top of the recognized text is facing, after the image has been rotated around its center according to the detected text angle (see textAngle property).