diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/LICENSE.txt b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/LICENSE.txt new file mode 100644 index 000000000000..b73b4a1293c3 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2019 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/README.md b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/README.md new file mode 100644 index 000000000000..be95b5737243 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/README.md @@ -0,0 +1,148 @@ +## An isomorphic javascript sdk for - InkRecognizerClient + +This package contains an isomorphic SDK for InkRecognizerClient. + +### Currently supported environments + +- Node.js version 6.x.x or higher +- Browser JavaScript + +### How to Install + +```bash +npm install @azure/cognitiveservices-inkrecognizer +``` + +### How to use + +#### nodejs - Authentication, client creation and recognize inkRecognizer as an example written in TypeScript. + +##### Install @azure/ms-rest-nodeauth + +```bash +npm install @azure/ms-rest-nodeauth +``` + +##### Sample code + +```typescript +import * as msRest from "@azure/ms-rest-js"; +import * as msRestNodeAuth from "@azure/ms-rest-nodeauth"; +import { InkRecognizerClient, InkRecognizerModels, InkRecognizerMappers } from "@azure/cognitiveservices-inkrecognizer"; +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; + +msRestNodeAuth.interactiveLogin().then((creds) => { + const client = new InkRecognizerClient(creds, subscriptionId); + const body: InkRecognizerModels.AnalysisRequest = { + applicationType: "drawing", + unit: "mm", + unitMultiple: 1.01, + language: "testlanguage", + strokes: [{ + id: 1, + language: "testlanguage", + points: "testpoints", + drawingAttributes: { + width: 1.01, + color: { + r: 1.01, + g: 1.01, + b: 1.01, + a: 1.01 + }, + height: 1.01, + fitToCurve: true, + rasterOp: "noOperation", + ignorePressure: true, + tip: "ellipse" + }, + kind: "inkDrawing" + }] + }; + const xMsClientRequestId = "testxMsClientRequestId"; + client.inkRecognizer.recognize(body, xMsClientRequestId).then((result) => { + console.log("The result is:"); + console.log(result); + }); +}).catch((err) => { + console.error(err); +}); +``` + +#### browser - Authentication, client creation and recognize inkRecognizer as an example written in JavaScript. + +##### Install @azure/ms-rest-browserauth + +```bash +npm install @azure/ms-rest-browserauth +``` + +##### Sample code + +See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. + +- index.html +```html + + + + @azure/cognitiveservices-inkrecognizer sample + + + + + + + +``` + +## Related projects + +- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js) diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/inkRecognizerClient.ts b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/inkRecognizerClient.ts new file mode 100644 index 000000000000..58f454e40057 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/inkRecognizerClient.ts @@ -0,0 +1,42 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +import * as msRest from "@azure/ms-rest-js"; +import * as Models from "./models"; +import * as Mappers from "./models/mappers"; +import * as operations from "./operations"; +import { InkRecognizerClientContext } from "./inkRecognizerClientContext"; + +class InkRecognizerClient extends InkRecognizerClientContext { + // Operation groups + inkRecognizer: operations.InkRecognizer; + + /** + * Initializes a new instance of the InkRecognizerClient class. + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus2.api.cognitive.microsoft.com). + * @param credentials Subscription credentials which uniquely identify client subscription. + * @param [options] The parameter options + */ + constructor(endpoint: string, credentials: msRest.ServiceClientCredentials, options?: msRest.ServiceClientOptions) { + super(endpoint, credentials, options); + this.inkRecognizer = new operations.InkRecognizer(this); + } +} + +// Operation Specifications + +export { + InkRecognizerClient, + InkRecognizerClientContext, + Models as InkRecognizerModels, + Mappers as InkRecognizerMappers +}; +export * from "./operations"; diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/inkRecognizerClientContext.ts b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/inkRecognizerClientContext.ts new file mode 100644 index 000000000000..7822f72457cc --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/inkRecognizerClientContext.ts @@ -0,0 +1,51 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +import * as msRest from "@azure/ms-rest-js"; + +const packageName = "@azure/cognitiveservices-inkrecognizer"; +const packageVersion = "1.0.0"; + +export class InkRecognizerClientContext extends msRest.ServiceClient { + endpoint: string; + credentials: msRest.ServiceClientCredentials; + + /** + * Initializes a new instance of the InkRecognizerClientContext class. + * @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example: + * https://westus2.api.cognitive.microsoft.com). + * @param credentials Subscription credentials which uniquely identify client subscription. + * @param [options] The parameter options + */ + constructor(endpoint: string, credentials: msRest.ServiceClientCredentials, options?: msRest.ServiceClientOptions) { + if (endpoint === null || endpoint === undefined) { + throw new Error('\'endpoint\' cannot be null.'); + } + if (credentials === null || credentials === undefined) { + throw new Error('\'credentials\' cannot be null.'); + } + + if (!options) { + options = {}; + } + if(!options.userAgent) { + const defaultUserAgent = msRest.getDefaultUserAgentValue(); + options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent}`; + } + + super(credentials, options); + + this.baseUri = "https://{Endpoint}"; + this.requestContentType = "application/json; charset=utf-8"; + this.endpoint = endpoint; + this.credentials = credentials; + + } +} diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/models/index.ts b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/models/index.ts new file mode 100644 index 000000000000..9772c2fa5e18 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/models/index.ts @@ -0,0 +1,553 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +import * as msRest from "@azure/ms-rest-js"; + + +/** + * @interface + * An interface representing DrawingAttributesPatternColor. + * This shows the components of the color in rgba format + * + */ +export interface DrawingAttributesPatternColor { + /** + * @member {number} [r] The red component of the color + */ + r?: number; + /** + * @member {number} [g] The green component of the color + */ + g?: number; + /** + * @member {number} [b] The blue component of the color + */ + b?: number; + /** + * @member {number} [a] The alpha component of the color + */ + a?: number; +} + +/** + * @interface + * An interface representing DrawingAttributesPattern. + * The properties to use when rendering ink + * + */ +export interface DrawingAttributesPattern { + /** + * @member {number} [width] The width of the stylus used to draw the stroke + */ + width?: number; + /** + * @member {DrawingAttributesPatternColor} [color] This shows the components + * of the color in rgba format + */ + color?: DrawingAttributesPatternColor; + /** + * @member {number} [height] The height of the stylus used to draw the stroke + */ + height?: number; + /** + * @member {boolean} [fitToCurve] This indicates whether Bezier smoothing is + * used to render the stroke + */ + fitToCurve?: boolean; + /** + * @member {RasterOp} [rasterOp] Possible values include: 'noOperation', + * 'copyPen', 'maskPen' + */ + rasterOp?: RasterOp; + /** + * @member {boolean} [ignorePressure] This indicates whether the thickness of + * a rendered Stroke changes according the amount of pressure applied. + */ + ignorePressure?: boolean; + /** + * @member {Tip} [tip] This specifies the tip to be used to draw a stroke. + * Possible values include: 'ellipse', 'rectangle' + */ + tip?: Tip; +} + +/** + * @interface + * An interface representing PointDetailsPattern. + * This holds all the properties of one point + * + */ +export interface PointDetailsPattern { + /** + * @member {number} x This represents the x coordinate of the point + */ + x: number; + /** + * @member {number} y This represents the y coordinate of the point + */ + y: number; +} + +/** + * @interface + * An interface representing AlternatePatternItem. + */ +export interface AlternatePatternItem { + /** + * @member {Leaf} category Possible values include: 'inkDrawing', + * 'inkBullet', 'inkWord', 'unknown' + */ + category: Leaf; + /** + * @member {PointDetailsPattern[]} [points] Array of point objects that + * represent points that are relevant to the type of recognition unit. For + * example, for leaf node of inkDrawing category that represents a triangle, + * points would include the x,y coordinates of the vertices of the recognized + * triangle. The points represent the coordinates of points used to create + * the perfectly drawn shape that is closest to the original input. They may + * not exactly match. + */ + points?: PointDetailsPattern[]; + /** + * @member {number} [rotationAngle] The angular orientation of an object + * relative to the horizontal axis + */ + rotationAngle?: number; + /** + * @member {number} [confidence] A number between 0 and 1 which indicates the + * confidence level in the result + */ + confidence?: number; + /** + * @member {string} recognizedString The recognized string from an inkWord or + * the name of a recognized shape in an inkDrawing object + */ + recognizedString: string; +} + +/** + * @interface + * An interface representing RecognitionUnitItemBoundingRectangle. + * The bounding rectangle of the recognized unit represented by the coordinates + * of the top left corner (x,y) along with width (w) and height (h) of the + * rectangle. Note that this rectangle is not rotated. So for rotated objects + * such as slanted handwriting, it will cover the entire object. The unit will + * be matched to the one specified in the original request (mm by default.) + * + */ +export interface RecognitionUnitItemBoundingRectangle { + /** + * @member {number} [topX] This represents the top left x coordinate + */ + topX?: number; + /** + * @member {number} [topY] This represents the top left y coordinate + */ + topY?: number; + /** + * @member {number} [width] This represents width of the bounding rectangle + */ + width?: number; + /** + * @member {number} [height] The represents the height of the bounding + * rectangle + */ + height?: number; +} + +/** + * @interface + * An interface representing RecognitionUnitItem. + * This represents the recognized entity + * + */ +export interface RecognitionUnitItem { + /** + * @member {number} id The identifier of the recognition unit. This id is + * used to indicate parent/child relationship between different recognition + * units. + */ + id: number; + /** + * @member {Category} category Possible values include: 'writingRegion', + * 'paragraph', 'listItem', 'line', 'inkBullet', 'inkDrawing', 'inkWord', + * 'unknown' + */ + category: Category; + /** + * @member {AlternatePatternItem[]} [alternates] + */ + alternates?: AlternatePatternItem[]; + /** + * @member {PointDetailsPattern} [center] The coordinates (x,y) of the center + * of the recognition unit. + */ + center?: PointDetailsPattern; + /** + * @member {PointDetailsPattern[]} [points] Array of point objects that + * represent points that are relevant to the type of recognition unit. For + * example, for a leaf node of inkDrawing category that represents a + * triangle, points would include the x, y coordinates of the vertices of the + * recognized triangle. The points represent the coordinates used to create + * the perfectly drawn shape that is closest to the original input. They may + * not exactly match. + */ + points?: PointDetailsPattern[]; + /** + * @member {number[]} [childIds] An array of integers representing the + * identifier of each child of the current recognition unit. + */ + childIds?: number[]; + /** + * @member {ClassProperty} classProperty Possible values include: + * 'container', 'leaf' + */ + classProperty: ClassProperty; + /** + * @member {number} parentId The id of the parent node in the tree structure + * of the recognition results. parent = 0 indicates that there is no + * dedicated parent node for this unit. + */ + parentId: number; + /** + * @member {RecognitionUnitItemBoundingRectangle} [boundingRectangle] The + * bounding rectangle of the recognized unit represented by the coordinates + * of the top left corner (x,y) along with width (w) and height (h) of the + * rectangle. Note that this rectangle is not rotated. So for rotated + * objects such as slanted handwriting, it will cover the entire object. The + * unit will be matched to the one specified in the original request (mm by + * default.) + */ + boundingRectangle?: RecognitionUnitItemBoundingRectangle; + /** + * @member {PointDetailsPattern[]} [rotatedBoundingRectangle] This property + * provides the rotated bounding rectangle that covers the entire recognized + * object along the angle of rotation of the object. Note that this is NOT + * the same as rotating the boundingRectangle by the rotation angle. + */ + rotatedBoundingRectangle?: PointDetailsPattern[]; + /** + * @member {number[]} strokeIds This is an array of integers representing the + * list of stroke Identifier integers from the input request body that belong + * to this recognition unit. + */ + strokeIds: number[]; + /** + * @member {string} [recognizedText] The string represents the text that was + * recognized. It can be an empty string if the recognizer cannot determine + * the text. + */ + recognizedText?: string; + /** + * @member {number} [confidence] The class represents the type of the + * recognition unit. A recognition unit can be a leaf node or a container + * node. Container nodes typically have leaf nodes as children. + */ + confidence?: number; + /** + * @member {number} [rotationAngle] This represents the angle at which the + * unit is rotated in degrees with respect to the positive X axis. + */ + rotationAngle?: number; + /** + * @member {Shape} [recognizedObject] Possible values include: 'drawing', + * 'square', 'rectangle', 'circle', 'ellipse', 'triangle', + * 'isoscelesTriangle', 'equilateralTriangle', 'rightTriangle', + * 'quadrilateral', 'diamond', 'trapezoid', 'parallelogram', 'pentagon', + * 'hexagon', 'blockArrow', 'heart', 'starSimple', 'starCrossed', 'cloud', + * 'line', 'curve', 'polyLine' + */ + recognizedObject?: Shape; +} + +/** + * @interface + * An interface representing Stroke. + */ +export interface Stroke { + /** + * @member {number} id This is treated as a unique identifier for each stroke + * within a request. If the id is repeated within the same request, the + * service will return an error. + */ + id: number; + /** + * @member {string} [language] The IETF BCP 47 language code (for ex. en-US, + * en-GB, hi-IN etc.) of the expected language for the handwritten content in + * this stroke. The response will include results from this language. + */ + language?: string; + /** + * @member {string} points A string of comma separated floating point values + * that represent the x and y coordinates of points that are part of the + * stroke. (X1,Y1, X2,Y2…). It is recommended to have a precision of 8 + * digits after the decimal to obtain most accurate recognition results. The + * origin (0,0) of the canvas is assumed to be at the top left corner of the + * canvas + */ + points: string; + /** + * @member {DrawingAttributesPattern} [drawingAttributes] + */ + drawingAttributes?: DrawingAttributesPattern; + /** + * @member {Kind} [kind] This is an optional property which influences the + * decision about what the stroke kind is between inkWriting and inkDrawing. + * This property should be set ONLY if the type of user content is known + * ahead of time. Not setting this value implies the kind is not known ahead + * of time. Kind represents the type of content the stroke is a part of. + * Possible values include: 'inkDrawing', 'inkWriting' + */ + kind?: Kind; +} + +/** + * @interface + * An interface representing AnalysisResponse. + * This shows the expected contents of a response from the service + * + */ +export interface AnalysisResponse { + /** + * @member {Unit} [unit] This represents the physical units of the ink + * strokes. It is up to the application developer to decide how to convert + * the device specific units to physical units before calling the service. + * The conversion factor can be different based on the type of the device + * used. Possible values include: 'mm', 'cm', 'in' + */ + unit?: Unit; + /** + * @member {number} [unitMultiple] This is a scaling factor to be applied to + * the point coordinates when interpreting them in the physical units + * specified. + */ + unitMultiple?: number; + /** + * @member {string} [language] This is the language used for recognizing + * handwriting from the ink strokes in the request. Set this to the user’s + * preferred language. + */ + language?: string; + /** + * @member {RecognitionUnitItem[]} recognitionUnits + */ + recognitionUnits: RecognitionUnitItem[]; +} + +/** + * @interface + * An interface representing ErrorModelDetailsItem. + */ +export interface ErrorModelDetailsItem { + /** + * @member {string} [code] This represents the error code + */ + code?: string; + /** + * @member {string} [message] This represents the error message + */ + message?: string; + /** + * @member {string} [target] This represents the target of the error message + */ + target?: string; +} + +/** + * @interface + * An interface representing ErrorModel. + */ +export interface ErrorModel { + /** + * @member {string} code This represents the error code + */ + code: string; + /** + * @member {string} message This represents the error message + */ + message: string; + /** + * @member {string} [target] This represents the target of the error message + */ + target?: string; + /** + * @member {ErrorModelDetailsItem[]} [details] This gives details of the + * reason(s) for the error + */ + details?: ErrorModelDetailsItem[]; +} + +/** + * @interface + * An interface representing AnalysisRequest. + * This shows the expected contents of a request + * + */ +export interface AnalysisRequest { + /** + * @member {Application} [applicationType] This describes the domain of the + * client application. Possible values include: 'drawing', 'writing', 'mixed' + */ + applicationType?: Application; + /** + * @member {Unit1} [unit] This represents the physical units of the ink + * strokes. It is up to the application developer to decide how to convert + * the device specific units to physical units before calling the service. + * The conversion factor can be different based on the type of the device + * used. Possible values include: 'mm', 'cm', 'in' + */ + unit?: Unit1; + /** + * @member {number} [unitMultiple] This is a scaling factor to be applied to + * the point coordinates when interpreting them in the physical units + * specified. + */ + unitMultiple?: number; + /** + * @member {string} language The IETF BCP 47 language code (for ex. en-US, + * en-GB, hi-IN etc.) of the expected language for the handwritten content in + * the ink strokes. The response will include results from this language. + */ + language: string; + /** + * @member {Stroke[]} strokes This is the array of strokes sent for + * recognition. Best results are produced when the order of strokes added in + * the array matches the order in which the user created them. Changing the + * stroke order may produce unexpected results. + */ + strokes: Stroke[]; +} + +/** + * @interface + * An interface representing InkRecognizerRecognizeOptionalParams. + * Optional Parameters. + * + * @extends RequestOptionsBase + */ +export interface InkRecognizerRecognizeOptionalParams extends msRest.RequestOptionsBase { + /** + * @member {string} [xMsClientRequestId] The request id used to uniquely + * identify each request during troubleshooting. This is an optional + * parameter useful for correlating logs and other artifacts. + */ + xMsClientRequestId?: string; +} + +/** + * Defines values for RasterOp. + * Possible values include: 'noOperation', 'copyPen', 'maskPen' + * @readonly + * @enum {string} + */ +export type RasterOp = 'noOperation' | 'copyPen' | 'maskPen'; + +/** + * Defines values for Tip. + * Possible values include: 'ellipse', 'rectangle' + * @readonly + * @enum {string} + */ +export type Tip = 'ellipse' | 'rectangle'; + +/** + * Defines values for Shape. + * Possible values include: 'drawing', 'square', 'rectangle', 'circle', 'ellipse', 'triangle', + * 'isoscelesTriangle', 'equilateralTriangle', 'rightTriangle', 'quadrilateral', 'diamond', + * 'trapezoid', 'parallelogram', 'pentagon', 'hexagon', 'blockArrow', 'heart', 'starSimple', + * 'starCrossed', 'cloud', 'line', 'curve', 'polyLine' + * @readonly + * @enum {string} + */ +export type Shape = 'drawing' | 'square' | 'rectangle' | 'circle' | 'ellipse' | 'triangle' | 'isoscelesTriangle' | 'equilateralTriangle' | 'rightTriangle' | 'quadrilateral' | 'diamond' | 'trapezoid' | 'parallelogram' | 'pentagon' | 'hexagon' | 'blockArrow' | 'heart' | 'starSimple' | 'starCrossed' | 'cloud' | 'line' | 'curve' | 'polyLine'; + +/** + * Defines values for Category. + * Possible values include: 'writingRegion', 'paragraph', 'listItem', 'line', 'inkBullet', + * 'inkDrawing', 'inkWord', 'unknown' + * @readonly + * @enum {string} + */ +export type Category = 'writingRegion' | 'paragraph' | 'listItem' | 'line' | 'inkBullet' | 'inkDrawing' | 'inkWord' | 'unknown'; + +/** + * Defines values for Container. + * Possible values include: 'writingRegion', 'paragraph', 'listItem', 'line' + * @readonly + * @enum {string} + */ +export type Container = 'writingRegion' | 'paragraph' | 'listItem' | 'line'; + +/** + * Defines values for Leaf. + * Possible values include: 'inkDrawing', 'inkBullet', 'inkWord', 'unknown' + * @readonly + * @enum {string} + */ +export type Leaf = 'inkDrawing' | 'inkBullet' | 'inkWord' | 'unknown'; + +/** + * Defines values for Kind. + * Possible values include: 'inkDrawing', 'inkWriting' + * @readonly + * @enum {string} + */ +export type Kind = 'inkDrawing' | 'inkWriting'; + +/** + * Defines values for Unit. + * Possible values include: 'mm', 'cm', 'in' + * @readonly + * @enum {string} + */ +export type Unit = 'mm' | 'cm' | 'in'; + +/** + * Defines values for Application. + * Possible values include: 'drawing', 'writing', 'mixed' + * @readonly + * @enum {string} + */ +export type Application = 'drawing' | 'writing' | 'mixed'; + +/** + * Defines values for ClassProperty. + * Possible values include: 'container', 'leaf' + * @readonly + * @enum {string} + */ +export type ClassProperty = 'container' | 'leaf'; + +/** + * Defines values for Unit1. + * Possible values include: 'mm', 'cm', 'in' + * @readonly + * @enum {string} + */ +export type Unit1 = 'mm' | 'cm' | 'in'; + +/** + * Contains response data for the recognize operation. + */ +export type InkRecognizerRecognizeResponse = AnalysisResponse & { + /** + * The underlying HTTP response. + */ + _response: msRest.HttpResponse & { + /** + * The response body as text (string format) + */ + bodyAsText: string; + /** + * The response body as parsed JSON or XML + */ + parsedBody: AnalysisResponse; + }; +}; diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/models/inkRecognizerMappers.ts b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/models/inkRecognizerMappers.ts new file mode 100644 index 000000000000..75974e7e099e --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/models/inkRecognizerMappers.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +export { + AnalysisRequest, + Stroke, + DrawingAttributesPattern, + DrawingAttributesPatternColor, + AnalysisResponse, + RecognitionUnitItem, + AlternatePatternItem, + PointDetailsPattern, + RecognitionUnitItemBoundingRectangle, + ErrorModel, + ErrorModelDetailsItem +} from "../models/mappers"; + diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/models/mappers.ts b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/models/mappers.ts new file mode 100644 index 000000000000..b7430e867310 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/models/mappers.ts @@ -0,0 +1,542 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +import * as msRest from "@azure/ms-rest-js"; + + +export const DrawingAttributesPatternColor: msRest.CompositeMapper = { + serializedName: "drawingAttributesPattern_color", + type: { + name: "Composite", + className: "DrawingAttributesPatternColor", + modelProperties: { + r: { + serializedName: "r", + type: { + name: "Number" + } + }, + g: { + serializedName: "g", + type: { + name: "Number" + } + }, + b: { + serializedName: "b", + type: { + name: "Number" + } + }, + a: { + serializedName: "a", + type: { + name: "Number" + } + } + } + } +}; + +export const DrawingAttributesPattern: msRest.CompositeMapper = { + serializedName: "drawingAttributesPattern", + type: { + name: "Composite", + className: "DrawingAttributesPattern", + modelProperties: { + width: { + serializedName: "width", + type: { + name: "Number" + } + }, + color: { + serializedName: "color", + type: { + name: "Composite", + className: "DrawingAttributesPatternColor" + } + }, + height: { + serializedName: "height", + type: { + name: "Number" + } + }, + fitToCurve: { + serializedName: "fitToCurve", + type: { + name: "Boolean" + } + }, + rasterOp: { + serializedName: "rasterOp", + type: { + name: "String" + } + }, + ignorePressure: { + serializedName: "ignorePressure", + type: { + name: "Boolean" + } + }, + tip: { + serializedName: "tip", + type: { + name: "String" + } + } + } + } +}; + +export const PointDetailsPattern: msRest.CompositeMapper = { + serializedName: "pointDetailsPattern", + type: { + name: "Composite", + className: "PointDetailsPattern", + modelProperties: { + x: { + required: true, + serializedName: "x", + type: { + name: "Number" + } + }, + y: { + required: true, + serializedName: "y", + type: { + name: "Number" + } + } + } + } +}; + +export const AlternatePatternItem: msRest.CompositeMapper = { + serializedName: "alternatePatternItem", + type: { + name: "Composite", + className: "AlternatePatternItem", + modelProperties: { + category: { + required: true, + serializedName: "category", + type: { + name: "String" + } + }, + points: { + serializedName: "points", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "PointDetailsPattern" + } + } + } + }, + rotationAngle: { + serializedName: "rotationAngle", + type: { + name: "Number" + } + }, + confidence: { + serializedName: "confidence", + type: { + name: "Number" + } + }, + recognizedString: { + required: true, + serializedName: "recognizedString", + type: { + name: "String" + } + } + } + } +}; + +export const RecognitionUnitItemBoundingRectangle: msRest.CompositeMapper = { + serializedName: "recognitionUnitItem_boundingRectangle", + type: { + name: "Composite", + className: "RecognitionUnitItemBoundingRectangle", + modelProperties: { + topX: { + serializedName: "topX", + type: { + name: "Number" + } + }, + topY: { + serializedName: "topY", + type: { + name: "Number" + } + }, + width: { + serializedName: "width", + type: { + name: "Number" + } + }, + height: { + serializedName: "height", + type: { + name: "Number" + } + } + } + } +}; + +export const RecognitionUnitItem: msRest.CompositeMapper = { + serializedName: "recognitionUnitItem", + type: { + name: "Composite", + className: "RecognitionUnitItem", + modelProperties: { + id: { + required: true, + serializedName: "id", + type: { + name: "Number" + } + }, + category: { + required: true, + serializedName: "category", + type: { + name: "String" + } + }, + alternates: { + serializedName: "alternates", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "AlternatePatternItem" + } + } + } + }, + center: { + serializedName: "center", + type: { + name: "Composite", + className: "PointDetailsPattern" + } + }, + points: { + serializedName: "points", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "PointDetailsPattern" + } + } + } + }, + childIds: { + serializedName: "childIds", + type: { + name: "Sequence", + element: { + type: { + name: "Number" + } + } + } + }, + classProperty: { + required: true, + serializedName: "class", + type: { + name: "String" + } + }, + parentId: { + required: true, + serializedName: "parentId", + type: { + name: "Number" + } + }, + boundingRectangle: { + serializedName: "boundingRectangle", + type: { + name: "Composite", + className: "RecognitionUnitItemBoundingRectangle" + } + }, + rotatedBoundingRectangle: { + serializedName: "rotatedBoundingRectangle", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "PointDetailsPattern" + } + } + } + }, + strokeIds: { + required: true, + serializedName: "strokeIds", + type: { + name: "Sequence", + element: { + type: { + name: "Number" + } + } + } + }, + recognizedText: { + serializedName: "recognizedText", + type: { + name: "String" + } + }, + confidence: { + serializedName: "confidence", + type: { + name: "Number" + } + }, + rotationAngle: { + serializedName: "rotationAngle", + type: { + name: "Number" + } + }, + recognizedObject: { + serializedName: "recognizedObject", + type: { + name: "String" + } + } + } + } +}; + +export const Stroke: msRest.CompositeMapper = { + serializedName: "stroke", + type: { + name: "Composite", + className: "Stroke", + modelProperties: { + id: { + required: true, + serializedName: "id", + type: { + name: "Number" + } + }, + language: { + serializedName: "language", + type: { + name: "String" + } + }, + points: { + required: true, + serializedName: "points", + type: { + name: "String" + } + }, + drawingAttributes: { + serializedName: "drawingAttributes", + type: { + name: "Composite", + className: "DrawingAttributesPattern" + } + }, + kind: { + serializedName: "kind", + type: { + name: "String" + } + } + } + } +}; + +export const AnalysisResponse: msRest.CompositeMapper = { + serializedName: "analysisResponse", + type: { + name: "Composite", + className: "AnalysisResponse", + modelProperties: { + unit: { + serializedName: "unit", + type: { + name: "String" + } + }, + unitMultiple: { + serializedName: "unitMultiple", + type: { + name: "Number" + } + }, + language: { + serializedName: "language", + type: { + name: "String" + } + }, + recognitionUnits: { + required: true, + serializedName: "recognitionUnits", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "RecognitionUnitItem" + } + } + } + } + } + } +}; + +export const ErrorModelDetailsItem: msRest.CompositeMapper = { + serializedName: "errorModel_detailsItem", + type: { + name: "Composite", + className: "ErrorModelDetailsItem", + modelProperties: { + code: { + serializedName: "code", + type: { + name: "String" + } + }, + message: { + serializedName: "message", + type: { + name: "String" + } + }, + target: { + serializedName: "target", + type: { + name: "String" + } + } + } + } +}; + +export const ErrorModel: msRest.CompositeMapper = { + serializedName: "errorModel", + type: { + name: "Composite", + className: "ErrorModel", + modelProperties: { + code: { + required: true, + serializedName: "code", + type: { + name: "String" + } + }, + message: { + required: true, + serializedName: "message", + type: { + name: "String" + } + }, + target: { + serializedName: "target", + type: { + name: "String" + } + }, + details: { + serializedName: "details", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "ErrorModelDetailsItem" + } + } + } + } + } + } +}; + +export const AnalysisRequest: msRest.CompositeMapper = { + serializedName: "analysisRequest", + type: { + name: "Composite", + className: "AnalysisRequest", + modelProperties: { + applicationType: { + serializedName: "applicationType", + type: { + name: "String" + } + }, + unit: { + serializedName: "unit", + type: { + name: "String" + } + }, + unitMultiple: { + serializedName: "unitMultiple", + type: { + name: "Number" + } + }, + language: { + required: true, + serializedName: "language", + type: { + name: "String" + } + }, + strokes: { + required: true, + serializedName: "strokes", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "Stroke" + } + } + } + } + } + } +}; diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/models/parameters.ts b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/models/parameters.ts new file mode 100644 index 000000000000..89e7a440c20b --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/models/parameters.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +import * as msRest from "@azure/ms-rest-js"; + +export const endpoint: msRest.OperationURLParameter = { + parameterPath: "endpoint", + mapper: { + required: true, + serializedName: "Endpoint", + defaultValue: '', + type: { + name: "String" + } + }, + skipEncoding: true +}; +export const xMsClientRequestId: msRest.OperationParameter = { + parameterPath: [ + "options", + "xMsClientRequestId" + ], + mapper: { + serializedName: "x-ms-client-request-id", + type: { + name: "String" + } + } +}; diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/operations/index.ts b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/operations/index.ts new file mode 100644 index 000000000000..44f5e3f74077 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/operations/index.ts @@ -0,0 +1,11 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +export * from "./inkRecognizer"; diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/operations/inkRecognizer.ts b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/operations/inkRecognizer.ts new file mode 100644 index 000000000000..fa306c5bb619 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/lib/operations/inkRecognizer.ts @@ -0,0 +1,87 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +import * as msRest from "@azure/ms-rest-js"; +import * as Models from "../models"; +import * as Mappers from "../models/inkRecognizerMappers"; +import * as Parameters from "../models/parameters"; +import { InkRecognizerClientContext } from "../inkRecognizerClientContext"; + +/** Class representing a InkRecognizer. */ +export class InkRecognizer { + private readonly client: InkRecognizerClientContext; + + /** + * Create a InkRecognizer. + * @param {InkRecognizerClientContext} client Reference to the service client. + */ + constructor(client: InkRecognizerClientContext) { + this.client = client; + } + + /** + * Ink Recognition operation is used to perform ink layout and recognition of written words and + * shapes. It allows passing the ink strokes to the service to get the recognition results in the + * response. + * @param body The collection of stroke objects to send for analysis + * @param [options] The optional parameters + * @returns Promise + */ + recognize(body: Models.AnalysisRequest, options?: Models.InkRecognizerRecognizeOptionalParams): Promise; + /** + * @param body The collection of stroke objects to send for analysis + * @param callback The callback + */ + recognize(body: Models.AnalysisRequest, callback: msRest.ServiceCallback): void; + /** + * @param body The collection of stroke objects to send for analysis + * @param options The optional parameters + * @param callback The callback + */ + recognize(body: Models.AnalysisRequest, options: Models.InkRecognizerRecognizeOptionalParams, callback: msRest.ServiceCallback): void; + recognize(body: Models.AnalysisRequest, options?: Models.InkRecognizerRecognizeOptionalParams | msRest.ServiceCallback, callback?: msRest.ServiceCallback): Promise { + return this.client.sendOperationRequest( + { + body, + options + }, + recognizeOperationSpec, + callback) as Promise; + } +} + +// Operation Specifications +const serializer = new msRest.Serializer(Mappers); +const recognizeOperationSpec: msRest.OperationSpec = { + httpMethod: "PUT", + path: "recognize", + urlParameters: [ + Parameters.endpoint + ], + headerParameters: [ + Parameters.xMsClientRequestId + ], + requestBody: { + parameterPath: "body", + mapper: { + ...Mappers.AnalysisRequest, + required: true + } + }, + responses: { + 200: { + bodyMapper: Mappers.AnalysisResponse + }, + default: { + bodyMapper: Mappers.ErrorModel + } + }, + serializer +}; diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/package.json b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/package.json new file mode 100644 index 000000000000..887d14699b25 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/package.json @@ -0,0 +1,55 @@ +{ + "name": "@azure/cognitiveservices-inkrecognizer", + "author": "Microsoft Corporation", + "description": "InkRecognizerClient Library with typescript type definitions for node.js and browser.", + "version": "1.0.0", + "dependencies": { + "@azure/ms-rest-js": "^1.2.0", + "tslib": "^1.9.3" + }, + "keywords": [ + "node", + "azure", + "typescript", + "browser", + "isomorphic" + ], + "license": "MIT", + "main": "./dist/cognitiveservices-inkrecognizer.js", + "module": "./esm/inkRecognizerClient.js", + "types": "./esm/inkRecognizerClient.d.ts", + "devDependencies": { + "typescript": "^3.1.1", + "rollup": "^0.66.2", + "rollup-plugin-node-resolve": "^3.4.0", + "rollup-plugin-sourcemaps": "^0.4.2", + "uglify-js": "^3.4.9" + }, + "homepage": "https://github.com/azure/azure-sdk-for-js", + "repository": { + "type": "git", + "url": "https://github.com/azure/azure-sdk-for-js.git" + }, + "bugs": { + "url": "https://github.com/azure/azure-sdk-for-js/issues" + }, + "files": [ + "dist/**/*.js", + "dist/**/*.js.map", + "dist/**/*.d.ts", + "dist/**/*.d.ts.map", + "esm/**/*.js", + "esm/**/*.js.map", + "esm/**/*.d.ts", + "esm/**/*.d.ts.map", + "lib/**/*.ts", + "rollup.config.js", + "tsconfig.json" + ], + "scripts": { + "build": "tsc && rollup -c rollup.config.js && npm run minify", + "minify": "uglifyjs -c -m --comments --source-map \"content='./dist/cognitiveservices-inkrecognizer.js.map'\" -o ./dist/cognitiveservices-inkrecognizer.min.js ./dist/cognitiveservices-inkrecognizer.js", + "prepack": "npm install && npm run build" + }, + "sideEffects": false +} diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/rollup.config.js b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/rollup.config.js new file mode 100644 index 000000000000..e7e5d42dd33d --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/rollup.config.js @@ -0,0 +1,37 @@ +import rollup from "rollup"; +import nodeResolve from "rollup-plugin-node-resolve"; +import sourcemaps from "rollup-plugin-sourcemaps"; + +/** + * @type {rollup.RollupFileOptions} + */ +const config = { + input: "./esm/inkRecognizerClient.js", + external: [ + "@azure/ms-rest-js", + "@azure/ms-rest-azure-js" + ], + output: { + file: "./dist/cognitiveservices-inkrecognizer.js", + format: "umd", + name: "Azure.CognitiveservicesInkrecognizer", + sourcemap: true, + globals: { + "@azure/ms-rest-js": "msRest", + "@azure/ms-rest-azure-js": "msRestAzure" + }, + banner: `/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */` + }, + plugins: [ + nodeResolve({ module: true }), + sourcemaps() + ] +}; + +export default config; diff --git a/sdk/cognitiveservices/cognitiveservices-inkrecognizer/tsconfig.json b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/tsconfig.json new file mode 100644 index 000000000000..51ea90961ce5 --- /dev/null +++ b/sdk/cognitiveservices/cognitiveservices-inkrecognizer/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "es6", + "moduleResolution": "node", + "strict": true, + "target": "es5", + "sourceMap": true, + "declarationMap": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "lib": ["es6"], + "declaration": true, + "outDir": "./esm", + "importHelpers": true + }, + "include": ["./lib/**/*.ts"], + "exclude": ["node_modules"] +}