From e5cf7321767fe6e16c7463d91a88d514550ca166 Mon Sep 17 00:00:00 2001 From: Jeremy Meng Date: Fri, 15 May 2020 08:53:01 -0700 Subject: [PATCH] [FormRecognizer] Rename for cross-language API consistency (#8808) * [FormRecognizer] Rename for cross-language API consistency - `beginRecognizeForms` => `beginRecognizeCustomForms` * FormElement => FormContent * blobContainerUrl => trainingFilesUrl * parameter name `documentUrl` => `formFileUrl` or `receiptFileUrl` * useLabels => useTrainingLabels, getModel => getCustomModel * listModels => listCustomModels * ModelInfo => CustomFormModelInfo * limit => customModelLimit, count => customModelCount * fieldLabel => labelText * ErrorInformation => FormRecognizerError export `Model` from model.ts instead of from generated code. * CustomFormSubModelField => CustomFormField * ModelStatus => CustomFormModelStatus TrainStatus => TrainingStatus --- .../ai-form-recognizer/README.md | 8 +- .../review/ai-form-recognizer.api.md | 100 ++++++------ .../javascript/customModelManagement.js | 8 +- .../differentiateLabeledUnlabeled.js | 4 +- .../samples/javascript/getBoundingBoxes.js | 2 +- .../samples/javascript/iteratorModels.js | 6 +- .../samples/javascript/recognizeCustomForm.js | 2 +- .../typescript/src/customModelManagement.ts | 8 +- .../src/differentiateLabeledUnlabeled.ts | 4 +- .../typescript/src/getBoundingBoxes.ts | 2 +- .../samples/typescript/src/iteratorModels.ts | 6 +- .../typescript/src/recognizeCustomForm.ts | 2 +- .../src/formRecognizerClient.ts | 30 ++-- .../src/formTrainingClient.ts | 43 +++-- .../src/lro/train/poller.ts | 4 +- .../ai-form-recognizer/src/models.ts | 152 ++++++++++++++---- .../ai-form-recognizer/src/transforms.ts | 18 +-- .../test/browser/formtrainingclient.spec.ts | 18 +-- .../test/node/formtrainingclient.spec.ts | 28 ++-- .../test/transforms.spec.ts | 18 +-- 20 files changed, 280 insertions(+), 183 deletions(-) diff --git a/sdk/formrecognizer/ai-form-recognizer/README.md b/sdk/formrecognizer/ai-form-recognizer/README.md index fab68ebcf807..d551568e2822 100644 --- a/sdk/formrecognizer/ai-form-recognizer/README.md +++ b/sdk/formrecognizer/ai-form-recognizer/README.md @@ -266,7 +266,7 @@ async function main() { const readStream = fs.createReadStream(path); const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey)); - const poller = await client.beginRecognizeForms(modelId, readStream, "application/pdf", { + const poller = await client.beginRecognizeCustomForms(modelId, readStream, "application/pdf", { onProgress: (state) => { console.log(`status: ${state.status}`); } }); await poller.pollUntilDone(); @@ -315,7 +315,7 @@ async function main() { const trainingClient = client.getFormTrainingClient(); // returns an async iteratable iterator that supports paging - const result = await trainingClient.listModels(); + const result = await trainingClient.listCustomModels(); let i = 0; for await (const modelInfo of result) { console.log(`model ${i++}:`); @@ -324,7 +324,7 @@ async function main() { // using `iter.next()` i = 1; - let iter = trainingClient.listModels(); + let iter = trainingClient.listCustomModels(); let modelItem = await iter.next(); while (!modelItem.done) { console.log(`model ${i++}: ${modelItem.value.modelId}`); @@ -333,7 +333,7 @@ async function main() { // using `byPage()` i = 1; - for await (const response of trainingClient.listModels().byPage()) { + for await (const response of trainingClient.listCustomModels().byPage()) { for (const modelInfo of response.modelList) { console.log(`model ${i++}: ${modelInfo.modelId}`); } diff --git a/sdk/formrecognizer/ai-form-recognizer/review/ai-form-recognizer.api.md b/sdk/formrecognizer/ai-form-recognizer/review/ai-form-recognizer.api.md index b6541de1f58d..221d9832796a 100644 --- a/sdk/formrecognizer/ai-form-recognizer/review/ai-form-recognizer.api.md +++ b/sdk/formrecognizer/ai-form-recognizer/review/ai-form-recognizer.api.md @@ -17,8 +17,8 @@ import { RestResponse } from '@azure/core-http'; // @public export interface AccountProperties { - count: number; - limit: number; + customModelCount: number; + customModelLimit: number; } // @public @@ -74,32 +74,43 @@ export type ContentPollerLike = PollerLike; - beginRecognizeContentFromUrl(documentUrl: string, options?: BeginRecognizeContentOptions): Promise; - beginRecognizeForms(modelId: string, data: FormRecognizerRequestBody, contentType?: ContentType, options?: BeginRecognizeFormsOptions): Promise; - beginRecognizeFormsFromUrl(modelId: string, documentUrl: string, options?: BeginRecognizeFormsOptions): Promise, RecognizeFormResultResponse>>; + beginRecognizeContentFromUrl(formFileUrl: string, options?: BeginRecognizeContentOptions): Promise; + beginRecognizeCustomForms(modelId: string, data: FormRecognizerRequestBody, contentType?: ContentType, options?: BeginRecognizeFormsOptions): Promise; + beginRecognizeCustomFormsFromUrl(modelId: string, formFileUrl: string, options?: BeginRecognizeFormsOptions): Promise, RecognizeFormResultResponse>>; beginRecognizeReceipts(data: FormRecognizerRequestBody, contentType?: ContentType, options?: BeginRecognizeReceiptsOptions): Promise; - beginRecognizeReceiptsFromUrl(documentUrl: string, options?: BeginRecognizeReceiptsOptions): Promise; + beginRecognizeReceiptsFromUrl(receiptFileUrl: string, options?: BeginRecognizeReceiptsOptions): Promise; readonly endpointUrl: string; getFormTrainingClient(): FormTrainingClient; } @@ -211,6 +214,12 @@ export class FormRecognizerClient { export interface FormRecognizerClientOptions extends PipelineOptions { } +// @public +export interface FormRecognizerError { + code: string; + message: string; +} + // @public export interface FormRecognizerOperationOptions extends OperationOptions { } @@ -220,7 +229,7 @@ export type FormRecognizerRequestBody = Blob | ArrayBuffer | ArrayBufferView | N // @public export interface FormResult { - errors?: ErrorInformation[]; + errors?: FormRecognizerError[]; forms?: RecognizedForm[]; version: string; } @@ -243,7 +252,7 @@ export interface FormTableCell { rowIndex: number; rowSpan?: number; text: string; - textContent?: FormElement[]; + textContent?: FormContent[]; } // @public @@ -255,28 +264,28 @@ export interface FormTableRow { export interface FormText { boundingBox?: Point2D[]; text?: string; - textContent?: FormElement[]; + textContent?: FormContent[]; } // @public export class FormTrainingClient { constructor(endpointUrl: string, credential: KeyCredential, options?: FormRecognizerClientOptions); - beginTraining(blobContainerUrl: string, useLabels?: boolean, options?: BeginTrainingOptions): Promise, FormModelResponse>>; + beginTraining(trainingFilesUrl: string, useTrainingLabels?: boolean, options?: BeginTrainingOptions): Promise, FormModelResponse>>; deleteModel(modelId: string, options?: DeleteModelOptions): Promise; readonly endpointUrl: string; getAccountProperties(options?: GetAccountPropertiesOptions): Promise; - getModel(modelId: string, options?: GetModelOptions): Promise; - listModels(options?: ListModelsOptions): PagedAsyncIterableIterator; + getCustomModel(modelId: string, options?: GetModelOptions): Promise; + listCustomModels(options?: ListModelsOptions): PagedAsyncIterableIterator; } // @public export interface FormTrainResult { - errors?: ErrorInformation[]; + errors?: FormRecognizerError[]; trainingDocuments: TrainingDocumentInfo[]; } // @public -export interface FormWord extends FormElementCommon { +export interface FormWord extends FormContentCommon { confidence?: number; containingLine?: FormLine; kind: "word"; @@ -348,7 +357,7 @@ export interface ModelInfo { createdOn: Date; lastModified: Date; modelId: string; - status: ModelStatus; + status: CustomFormModelStatus; } // @public @@ -365,9 +374,6 @@ export interface ModelsSummary { limit: number; } -// @public -export type ModelStatus = "creating" | "ready" | "invalid"; - // @public export type NumberFieldValue = { type: "number"; @@ -534,11 +540,14 @@ export type TimeFieldValue = { // @public export interface TrainingDocumentInfo { documentName: string; - errors: ErrorInformation[]; + errors: FormRecognizerError[]; pageCount: number; - status: TrainStatus; + status: TrainingStatus; } +// @public +export type TrainingStatus = "succeeded" | "partiallySucceeded" | "failed"; + // @public export type TrainModelOptions = FormRecognizerOperationOptions & { prefix?: string; @@ -548,14 +557,11 @@ export type TrainModelOptions = FormRecognizerOperationOptions & { // @public export interface TrainResult { averageModelAccuracy?: number; - errors?: ErrorInformation[]; + errors?: FormRecognizerError[]; fields?: FormFieldsReport[]; trainingDocuments: TrainingDocumentInfo[]; } -// @public -export type TrainStatus = "succeeded" | "partiallySucceeded" | "failed"; - // @public export interface USReceipt extends RecognizedReceipt { items: USReceiptItem[]; @@ -592,7 +598,7 @@ export type ValueTypes = "string" | "date" | "time" | "phoneNumber" | "number" | // Warnings were encountered during analysis: // // src/formRecognizerClient.ts:70:3 - (ae-forgotten-export) The symbol "BeginRecognizePollState" needs to be exported by the entry point index.d.ts -// src/formTrainingClient.ts:68:3 - (ae-forgotten-export) The symbol "BeginTrainingPollState" needs to be exported by the entry point index.d.ts +// src/formTrainingClient.ts:66:3 - (ae-forgotten-export) The symbol "BeginTrainingPollState" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/sdk/formrecognizer/ai-form-recognizer/samples/javascript/customModelManagement.js b/sdk/formrecognizer/ai-form-recognizer/samples/javascript/customModelManagement.js index 835627962a82..9c289a6cff40 100644 --- a/sdk/formrecognizer/ai-form-recognizer/samples/javascript/customModelManagement.js +++ b/sdk/formrecognizer/ai-form-recognizer/samples/javascript/customModelManagement.js @@ -20,11 +20,11 @@ async function main() { // First, we see how many custom models we have, and what our limit is const accountProperties = await client.getAccountProperties(); console.log( - `Our account has ${accountProperties.count} custom models, and we can have at most ${accountProperties.limit} custom models` + `Our account has ${accountProperties.customModelCount} custom models, and we can have at most ${accountProperties.customModelLimit} custom models` ); // Next, we get a paged async iterator of all of our custom models - const result = client.listModels(); + const result = client.listCustomModels(); // We could print out information about first ten models // and save the first model id for later use @@ -49,7 +49,7 @@ async function main() { } // Now we'll get the first custom model in the paged list - const model = await client.getModel(firstModel.modelId); + const model = await client.getCustomModel(firstModel.modelId); console.log(`Model Id: ${model.modelId}`); console.log(`Status: ${model.status}`); console.log("Documents used in training: ["); @@ -61,7 +61,7 @@ async function main() { // Finally, we can delete this model if we want (for example, if its status is 'invalid') // await client.deleteModel(firstModel.modelId); // try { - // const deleted = await client.getModel(firstModel.modelId); + // const deleted = await client.getCustomModel(firstModel.modelId); // console.log(deleted); // } catch (err) { // // Expected diff --git a/sdk/formrecognizer/ai-form-recognizer/samples/javascript/differentiateLabeledUnlabeled.js b/sdk/formrecognizer/ai-form-recognizer/samples/javascript/differentiateLabeledUnlabeled.js index a24ba1e8f79d..954d4ceff52a 100644 --- a/sdk/formrecognizer/ai-form-recognizer/samples/javascript/differentiateLabeledUnlabeled.js +++ b/sdk/formrecognizer/ai-form-recognizer/samples/javascript/differentiateLabeledUnlabeled.js @@ -50,7 +50,7 @@ async function main() { // The recognized form fields with a custom model from training without labels will also include data about recognized labels. const field = form.fields[fieldName]; console.log( - `\tField ${fieldName} has label '${field.fieldLabel.text}' with a confidence score of ${field.confidence}` + `\tField ${fieldName} has label '${field.labelText.text}' with a confidence score of ${field.confidence}` ); console.log( `\tField ${fieldName} has value '${field.value}' with a confidence score of ${field.confidence}` @@ -63,7 +63,7 @@ async function recognizeCustomForm(path, endpoint, apiKey, labeledModelId) { console.log("# Recognizing..."); const readStream = fs.createReadStream(path); const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey)); - const poller = await client.beginRecognizeForms(labeledModelId, readStream, "application/pdf", { + const poller = await client.beginRecognizeCustomForms(labeledModelId, readStream, "application/pdf", { onProgress: (state) => { console.log(`\tstatus: ${state.status}`); } diff --git a/sdk/formrecognizer/ai-form-recognizer/samples/javascript/getBoundingBoxes.js b/sdk/formrecognizer/ai-form-recognizer/samples/javascript/getBoundingBoxes.js index 3b4d8882283d..17d9d712b671 100644 --- a/sdk/formrecognizer/ai-form-recognizer/samples/javascript/getBoundingBoxes.js +++ b/sdk/formrecognizer/ai-form-recognizer/samples/javascript/getBoundingBoxes.js @@ -27,7 +27,7 @@ async function main() { const readStream = fs.createReadStream(path); const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey)); - const poller = await client.beginRecognizeForms(modelId, readStream, "application/pdf", { + const poller = await client.beginRecognizeCustomForms(modelId, readStream, "application/pdf", { onProgress: (state) => { console.log(`status: ${state.status}`); } diff --git a/sdk/formrecognizer/ai-form-recognizer/samples/javascript/iteratorModels.js b/sdk/formrecognizer/ai-form-recognizer/samples/javascript/iteratorModels.js index ad1a03981072..bab39ffcd103 100644 --- a/sdk/formrecognizer/ai-form-recognizer/samples/javascript/iteratorModels.js +++ b/sdk/formrecognizer/ai-form-recognizer/samples/javascript/iteratorModels.js @@ -18,7 +18,7 @@ async function main() { const client = new FormTrainingClient(endpoint, new AzureKeyCredential(apiKey)); - const result = await client.listModels(); + const result = await client.listCustomModels(); let i = 0; for await (const modelInfo of result) { console.log(`model ${i++}:`); @@ -27,7 +27,7 @@ async function main() { // using `iter.next()` i = 1; - let iter = client.listModels(); + let iter = client.listCustomModels(); let modelItem = await iter.next(); while (!modelItem.done) { console.log(`model ${i++}: ${modelItem.value.modelId}`); @@ -36,7 +36,7 @@ async function main() { // using `byPage()` i = 1; - for await (const response of client.listModels().byPage()) { + for await (const response of client.listCustomModels().byPage()) { for (const modelInfo of response.modelList) { console.log(`model ${i++}: ${modelInfo.modelId}`); } diff --git a/sdk/formrecognizer/ai-form-recognizer/samples/javascript/recognizeCustomForm.js b/sdk/formrecognizer/ai-form-recognizer/samples/javascript/recognizeCustomForm.js index 5fb41b86be69..d68072a1af18 100644 --- a/sdk/formrecognizer/ai-form-recognizer/samples/javascript/recognizeCustomForm.js +++ b/sdk/formrecognizer/ai-form-recognizer/samples/javascript/recognizeCustomForm.js @@ -25,7 +25,7 @@ async function main() { const readStream = fs.createReadStream(path); const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey)); - const poller = await client.beginRecognizeForms(modelId, readStream, "application/pdf", { + const poller = await client.beginRecognizeCustomForms(modelId, readStream, "application/pdf", { onProgress: (state) => { console.log(`status: ${state.status}`); } diff --git a/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/customModelManagement.ts b/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/customModelManagement.ts index 4dcdc35dee41..540bdab7abfc 100644 --- a/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/customModelManagement.ts +++ b/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/customModelManagement.ts @@ -21,11 +21,11 @@ export async function main() { // First, we see how many custom models we have, and what our limit is const accountProperties = await client.getAccountProperties(); console.log( - `Our account has ${accountProperties.count} custom models, and we can have at most ${accountProperties.limit} custom models` + `Our account has ${accountProperties.customModelCount} custom models, and we can have at most ${accountProperties.customModelLimit} custom models` ); // Next, we get a paged async iterator of all of our custom models - const result = client.listModels(); + const result = client.listCustomModels(); // We could print out information about first ten models // and save the first model id for later use @@ -50,7 +50,7 @@ export async function main() { } // Now we'll get the first custom model in the paged list - const model = await client.getModel(firstModel.modelId); + const model = await client.getCustomModel(firstModel.modelId); console.log(`Model Id: ${model.modelId}`); console.log(`Status: ${model.status}`); console.log("Documents used in training: ["); @@ -62,7 +62,7 @@ export async function main() { // Finally, we can delete this model if we want (for example, if its status is 'invalid') // await client.deleteModel(firstModel.modelId); // try { - // const deleted = await client.getModel(firstModel.modelId); + // const deleted = await client.getCustomModel(firstModel.modelId); // console.log(deleted); // } catch (err) { // // Expected diff --git a/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/differentiateLabeledUnlabeled.ts b/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/differentiateLabeledUnlabeled.ts index 55a36ed339d6..d47a1c9eaa36 100644 --- a/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/differentiateLabeledUnlabeled.ts +++ b/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/differentiateLabeledUnlabeled.ts @@ -55,7 +55,7 @@ export async function main() { // The recognized form fields with an unlabeled custom model will also include data about recognized labels. const field = form.fields[fieldName]; console.log( - `\tField ${fieldName} has label '${field.fieldLabel?.text}' with a confidence score of ${field.confidence}` + `\tField ${fieldName} has label '${field.labelText?.text}' with a confidence score of ${field.confidence}` ); console.log( `\tField ${fieldName} has value '${field.value}' with a confidence score of ${field.confidence}` @@ -73,7 +73,7 @@ async function recognizeCustomForm( console.log("# Recognizing..."); const readStream = fs.createReadStream(path); const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey)); - const poller = await client.beginRecognizeForms(labeledModelId, readStream, "application/pdf", { + const poller = await client.beginRecognizeCustomForms(labeledModelId, readStream, "application/pdf", { onProgress: (state) => { console.log(`\tstatus: ${state.status}`); } diff --git a/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/getBoundingBoxes.ts b/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/getBoundingBoxes.ts index 8732047c5513..ee0812f00512 100644 --- a/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/getBoundingBoxes.ts +++ b/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/getBoundingBoxes.ts @@ -27,7 +27,7 @@ export async function main() { const readStream = fs.createReadStream(path); const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey)); - const poller = await client.beginRecognizeForms(modelId, readStream, "application/pdf", { + const poller = await client.beginRecognizeCustomForms(modelId, readStream, "application/pdf", { onProgress: (state) => { console.log(`status: ${state.status}`); } diff --git a/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/iteratorModels.ts b/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/iteratorModels.ts index 849a2d528ffe..305c5d56c6e9 100644 --- a/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/iteratorModels.ts +++ b/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/iteratorModels.ts @@ -19,7 +19,7 @@ export async function main() { const client = new FormTrainingClient(endpoint, new AzureKeyCredential(apiKey)); // using `for await` syntax: - const result = client.listModels(); + const result = client.listCustomModels(); let i = 0; for await (const model of result) { console.log(`model ${i++}:`); @@ -28,7 +28,7 @@ export async function main() { // using `iter.next()` i = 1; - let iter = client.listModels(); + let iter = client.listCustomModels(); let modelItem = await iter.next(); while (!modelItem.done) { console.log(`model ${i++}: ${modelItem.value.modelId}`); @@ -37,7 +37,7 @@ export async function main() { // using `byPage()` i = 1; - for await (const response of client.listModels().byPage()) { + for await (const response of client.listCustomModels().byPage()) { for (const modelInfo of response.modelList!) { console.log(`model ${i++}: ${modelInfo.modelId}`); } diff --git a/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/recognizeCustomForm.ts b/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/recognizeCustomForm.ts index 10e809d22557..0199dd8aac32 100644 --- a/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/recognizeCustomForm.ts +++ b/sdk/formrecognizer/ai-form-recognizer/samples/typescript/src/recognizeCustomForm.ts @@ -29,7 +29,7 @@ export async function main() { const readStream = fs.createReadStream(path); const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey)); - const poller = await client.beginRecognizeForms(modelId, readStream, "application/pdf", { + const poller = await client.beginRecognizeCustomForms(modelId, readStream, "application/pdf", { onProgress: (state) => { console.log(`status: ${state.status}`); } diff --git a/sdk/formrecognizer/ai-form-recognizer/src/formRecognizerClient.ts b/sdk/formrecognizer/ai-form-recognizer/src/formRecognizerClient.ts index 9971827b3d6e..d3f4992bd43f 100644 --- a/sdk/formrecognizer/ai-form-recognizer/src/formRecognizerClient.ts +++ b/sdk/formrecognizer/ai-form-recognizer/src/formRecognizerClient.ts @@ -338,12 +338,12 @@ export class FormRecognizerClient { * console.log(response.pages); * ``` * @summary Recognizes content/layout information from a url to a form document - * @param {string} url Url to an accessible form document + * @param {string} formFileUrl Url to an accessible form document ng", and "image/tiff"; * @param {BeginRecognizeContentOptions} [options] Options to start content recognition operation */ public async beginRecognizeContentFromUrl( - documentUrl: string, + formFileUrl: string, options: BeginRecognizeContentOptions = {} ): Promise { const analyzePollerClient: RecognizePollerClient = { @@ -353,7 +353,7 @@ ng", and "image/tiff"; const poller = new BeginRecognizePoller({ client: analyzePollerClient, - source: documentUrl, + source: formFileUrl, contentType: undefined, ...options }); @@ -405,7 +405,7 @@ ng", and "image/tiff"; * const readStream = fs.createReadStream(path); * * const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey)); - * const poller = await client.beginRecognizeForms(modelId, readStream, "application/pdf", { + * const poller = await client.beginRecognizeCustomForms(modelId, readStream, "application/pdf", { * onProgress: (state) => { console.log(`status: ${state.status}`); } * }); * await poller.pollUntilDone(); @@ -418,7 +418,7 @@ ng", and "image/tiff"; * @param {ContentType} contentType Content type of the input. Supported types are "application/pdf", "image/jpeg", "image/png", and "image/tiff"; * @param {BeginRecognizeFormsOptions} [options] Options to start the form recognition operation */ - public async beginRecognizeForms( + public async beginRecognizeCustomForms( modelId: string, data: FormRecognizerRequestBody, contentType?: ContentType, @@ -463,7 +463,7 @@ ng", and "image/tiff"; * const url = "
"; * * const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey)); - * const poller = await client.beginRecognizeFormsFromUrl(modelId, url, { + * const poller = await client.beginRecognizeCustomFormsFromUrl(modelId, url, { * onProgress: (state) => { console.log(`status: ${state.status}`); } * }); * await poller.pollUntilDone(); @@ -472,13 +472,13 @@ ng", and "image/tiff"; * ``` * @summary Recognizes form information from a url to a form document using a custom form model. * @param {string} modelId Id of the custom form model to use - * @param {string} url Url to an accessible form document + * @param {string} formFileUrl Url to an accessible form document ng", and "image/tiff"; * @param {BeginRecognizeFormsOptions} [options] Options to start the form recognition operation */ - public async beginRecognizeFormsFromUrl( + public async beginRecognizeCustomFormsFromUrl( modelId: string, - documentUrl: string, + formFileUrl: string, options: BeginRecognizeFormsOptions = {} ): Promise< PollerLike, RecognizeFormResultResponse> @@ -500,7 +500,7 @@ ng", and "image/tiff"; const poller = new BeginRecognizePoller({ client: analyzePollerClient, modelId, - source: documentUrl, + source: formFileUrl, contentType: undefined, ...options }); @@ -612,10 +612,10 @@ ng", and "image/tiff"; * * Example usage: * ```ts - * const receiptUrl = ""; + * const url = ""; * const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey)); * const poller = await client.beginRecognizeReceiptsFromUrl( - * receiptUrl, { + * url, { * includeTextDetails: true, * onProgress: (state) => { console.log(`analyzing status: ${state.status}`); } * }); @@ -632,11 +632,11 @@ ng", and "image/tiff"; * console.log(usReceipt.recognizedForm.fields["MerchantAddress"]); * ``` * @summary Recognizes receipt information from a given accessible url to input document - * @param {string} documentUrl url to the input receipt document + * @param {string} receiptFileUrl url to the input receipt document * @param {BeginRecognizeReceiptsOptions} [options] Options to start receipt recognition operation */ public async beginRecognizeReceiptsFromUrl( - documentUrl: string, + receiptFileUrl: string, options: BeginRecognizeReceiptsOptions = {} ): Promise { const analyzePollerClient: RecognizePollerClient = { @@ -646,7 +646,7 @@ ng", and "image/tiff"; const poller = new BeginRecognizePoller({ client: analyzePollerClient, - source: documentUrl, + source: receiptFileUrl, contentType: undefined, ...options }); diff --git a/sdk/formrecognizer/ai-form-recognizer/src/formTrainingClient.ts b/sdk/formrecognizer/ai-form-recognizer/src/formTrainingClient.ts index fc026f669e41..f52d980991e4 100644 --- a/sdk/formrecognizer/ai-form-recognizer/src/formTrainingClient.ts +++ b/sdk/formrecognizer/ai-form-recognizer/src/formTrainingClient.ts @@ -20,18 +20,16 @@ import { CanonicalCode } from "@opentelemetry/api"; import { GeneratedClient } from "./generated/generatedClient"; import { GeneratedClientGetCustomModelsResponse as ListModelsResponseModel, - Model, - ModelInfo, GeneratedClientTrainCustomModelAsyncResponse } from "./generated/models"; import { TrainPollerClient, BeginTrainingPoller, BeginTrainingPollState } from "./lro/train/poller"; import { PollOperationState, PollerLike } from "@azure/core-lro"; import { FormRecognizerClientOptions, FormRecognizerOperationOptions } from "./common"; -import { FormModelResponse, AccountProperties } from "./models"; +import { FormModelResponse, AccountProperties, CustomFormModelInfo } from "./models"; import { createFormRecognizerAzureKeyCredentialPolicy } from "./azureKeyCredentialPolicy"; import { toFormModelResponse } from "./transforms"; -export { ListModelsResponseModel, Model, ModelInfo, RestResponse }; +export { ListModelsResponseModel, RestResponse }; /** * Options for model listing operation. */ @@ -166,8 +164,8 @@ export class FormTrainingClient { }); return { - limit: result.summary!.limit, - count: result.summary!.count + customModelLimit: result.summary!.limit, + customModelCount: result.summary!.count }; } catch (e) { span.setStatus({ @@ -215,13 +213,13 @@ export class FormTrainingClient { * @param {string} modelId Id of the model to get information * @param {GetModelOptions} options Options to the Get Model operation */ - public async getModel( + public async getCustomModel( modelId: string, options: GetModelOptions = {} ): Promise { const realOptions = options || {}; const { span, updatedOptions: finalOptions } = createSpan( - "FormTrainingClient-getModel", + "FormTrainingClient-getCustomModel", realOptions ); @@ -260,7 +258,7 @@ export class FormTrainingClient { private async *listModelsAll( settings: PageSettings, options: ListModelsOptions = {} - ): AsyncIterableIterator { + ): AsyncIterableIterator { for await (const page of this.listModelsPage(settings, options)) { yield* page.modelList || []; } @@ -275,7 +273,7 @@ export class FormTrainingClient { * * ```js * const client = new FormTrainingClient(endpoint, new AzureKeyCredential(apiKey)); - * const result = client.listModels(); + * const result = client.listCustomModels(); * let i = 1; * for await (const model of result) { * console.log(`model ${i++}:`); @@ -287,7 +285,7 @@ export class FormTrainingClient { * * ```js * let i = 1; - * let iter = client.listModels(); + * let iter = client.listCustomModels(); * let modelItem = await iter.next(); * while (!modelItem.done) { * console.log(`model ${i++}: ${modelItem.value}`); @@ -299,7 +297,7 @@ export class FormTrainingClient { * * ```js * let i = 1; - * for await (const response of client.listModels().byPage()) { + * for await (const response of client.listCustomModels().byPage()) { * for (const modelInfo of response.modelList!) { * console.log(`model ${i++}: ${modelInfo.modelId}`); * } @@ -308,9 +306,9 @@ export class FormTrainingClient { * * @param {ListModelOptions} options Options to the List Models operation */ - public listModels( + public listCustomModels( options: ListModelsOptions = {} - ): PagedAsyncIterableIterator { + ): PagedAsyncIterableIterator { const iter = this.listModelsAll({}, options); return { @@ -389,11 +387,11 @@ export class FormTrainingClient { * * Example usage: * ```ts - * const blobContainerUrl = ""; + * const trainingFilesUrl = ""; * const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey)); * const trainingClient = client.getFormTrainingClient(); * - * const poller = await trainingClient.beginTraining(blobContainerUrl, { + * const poller = await trainingClient.beginTraining(trainingFilesUrl, { * onProgress: (state) => { console.log("training status: "); console.log(state); } * }); * await poller.pollUntilDone(); @@ -401,26 +399,27 @@ export class FormTrainingClient { * console.log(response) * ``` * @summary Creats and trains a model - * @param {string} blobContainerUrl Accessible url to an Azure Storage Blob container storing the training documents + * @param {string} trainingFilesUrl Accessible url to an Azure Storage Blob container storing the training documents + * @param {boolean} useTrainingLabels specifies whether to training the model using label files * @param {BeginTrainingOptions} [options] Options to start model training operation */ public async beginTraining( - blobContainerUrl: string, - useLabels: boolean = false, + trainingFilesUrl: string, + useTrainingLabels: boolean = false, options: BeginTrainingOptions = {} ): Promise, FormModelResponse>> { const trainPollerClient: TrainPollerClient = { - getModel: (modelId: string, options: GetModelOptions) => this.getModel(modelId, options), + getCustomModel: (modelId: string, options: GetModelOptions) => this.getCustomModel(modelId, options), trainCustomModelInternal: ( source: string, _useLabelFile?: boolean, options?: TrainModelOptions - ) => trainCustomModelInternal(this.client, source, useLabels, options) + ) => trainCustomModelInternal(this.client, source, useTrainingLabels, options) }; const poller = new BeginTrainingPoller({ client: trainPollerClient, - source: blobContainerUrl, + source: trainingFilesUrl, intervalInMs: options.intervalInMs, onProgress: options.onProgress, resumeFrom: options.resumeFrom, diff --git a/sdk/formrecognizer/ai-form-recognizer/src/lro/train/poller.ts b/sdk/formrecognizer/ai-form-recognizer/src/lro/train/poller.ts index e96aea672b8b..4a8ff46d998d 100644 --- a/sdk/formrecognizer/ai-form-recognizer/src/lro/train/poller.ts +++ b/sdk/formrecognizer/ai-form-recognizer/src/lro/train/poller.ts @@ -16,7 +16,7 @@ export { ModelStatus, TrainCustomModelAsyncResponse }; * returned by {@link FormRecognizerClient.beginTraining} to work. */ export type TrainPollerClient = { - getModel: (modelId: string, options: GetModelOptions) => Promise; + getCustomModel: (modelId: string, options: GetModelOptions) => Promise; trainCustomModelInternal: ( source: string, useLabelFile?: boolean, @@ -126,7 +126,7 @@ function makeBeginTrainingPollOperation( state.modelId = result.location.substring(lastSlashIndex + 1); } - const model = await client.getModel(state.modelId!, { + const model = await client.getCustomModel(state.modelId!, { abortSignal: trainModelOptions?.abortSignal }); diff --git a/sdk/formrecognizer/ai-form-recognizer/src/models.ts b/sdk/formrecognizer/ai-form-recognizer/src/models.ts index 3a64cfe8b2dc..cd5133cdace4 100644 --- a/sdk/formrecognizer/ai-form-recognizer/src/models.ts +++ b/sdk/formrecognizer/ai-form-recognizer/src/models.ts @@ -5,40 +5,34 @@ import * as coreHttp from "@azure/core-http"; import { AnalyzeOperationResult as AnalyzeOperationResultModel, - ErrorInformation, FormFieldsReport, KeysResult, KeyValueElement as KeyValueElementModel, KeyValuePair as KeyValuePairModel, Language, LengthUnit, - Model, + ModelInfo, Models, ModelsSummary, - ModelStatus, - TrainingDocumentInfo, - TrainResult, - TrainStatus, - OperationStatus, - ModelInfo + ModelStatus as CustomFormModelStatus, + TrainStatus as TrainingStatus, + OperationStatus } from "./generated/models"; export { AnalyzeOperationResultModel, - ErrorInformation, FormFieldsReport, KeysResult, KeyValueElementModel, KeyValuePairModel, Language, LengthUnit, + ModelInfo, Models, ModelsSummary, - ModelStatus, + CustomFormModelStatus, OperationStatus, - TrainingDocumentInfo, - TrainStatus, - TrainResult + TrainingStatus }; /** @@ -58,7 +52,7 @@ export interface Point2D { /** * Represents common properties of recognized form contents. */ -export interface FormElementCommon { +export interface FormContentCommon { /** * The 1-based page number in the input document. */ @@ -76,7 +70,7 @@ export interface FormElementCommon { /** * Represents an recognized word. */ -export interface FormWord extends FormElementCommon { +export interface FormWord extends FormContentCommon { /** * Element kind - "word" */ @@ -94,7 +88,7 @@ export interface FormWord extends FormElementCommon { /** * Represents an recognized text line. */ -export interface FormLine extends FormElementCommon { +export interface FormLine extends FormContentCommon { /** * Element kind - "line" */ @@ -125,7 +119,7 @@ export interface FormLine extends FormElementCommon { * Information about an recognized element in the form. Examples include * words, lines, checkbox, etc. */ -export type FormElement = FormWord | FormLine; // | FormCheckBox; +export type FormContent = FormWord | FormLine; // | FormCheckBox; /** * Represents a cell in recognized table @@ -162,7 +156,7 @@ export interface FormTableCell { /** * When includeTextDetails is set to true, a list of references to the text elements constituting this table cell. */ - textContent?: FormElement[]; + textContent?: FormContent[]; /** * Is the current cell a header cell? */ @@ -214,7 +208,7 @@ export interface FormText { /** * When includeTextDetails is set to true, a list of references to the text elements constituting this name or value. */ - textContent?: FormElement[]; + textContent?: FormContent[]; /** * The text content of the recognized label or value */ @@ -233,7 +227,7 @@ export interface FormField { /** * Text of the recognized label of the field. */ - fieldLabel?: FormText; + labelText?: FormText; /** * A user defined label for the field. */ @@ -352,7 +346,7 @@ interface CommonFieldValue { * When includeTextDetails is set to true, a list of references to the text elements constituting * this field. */ - textContent?: FormElement[]; + textContent?: FormContent[]; /** * The 1-based page number in the input document. */ @@ -671,6 +665,20 @@ export type RecognizeContentResultResponse = RecognizeContentOperationResult & { }; }; +/** + * Represents errors from Azure Form Recognizer service + */ +export interface FormRecognizerError { + /** + * Error code + */ + code: string; + /** + * Error message + */ + message: string; +} + /** * Represents an recognized form using a custom model. */ @@ -687,7 +695,7 @@ export interface FormResult { /** * List of errors reported during the form recognition operation. */ - errors?: ErrorInformation[]; + errors?: FormRecognizerError[]; } /** @@ -728,6 +736,28 @@ export type RecognizeFormResultResponse = RecognizeFormOperationResult & { }; }; +/** + * Report for a custom model training document. + */ +export interface TrainingDocumentInfo { + /** + * Training document name. + */ + documentName: string; + /** + * Total number of pages trained. + */ + pageCount: number; + /** + * List of errors. + */ + errors: FormRecognizerError[]; + /** + * Status of the training operation. + */ + status: TrainingStatus; +} + /** * Contains the unlabeled training results. */ @@ -739,7 +769,29 @@ export interface FormTrainResult { /** * Errors returned during training operation. */ - errors?: ErrorInformation[]; + errors?: FormRecognizerError[]; +} + +/** + * Basic custom model information. + */ +export interface CustomFormModelInfo { + /** + * Model identifier. + */ + modelId: string; + /** + * Status of the model. + */ + status: CustomFormModelStatus; + /** + * Date and time (UTC) when the model was created. + */ + createdOn: Date; + /** + * Date and time (UTC) when the status was last updated. + */ + lastModified: Date; } /** @@ -749,7 +801,7 @@ export interface FormModel { /** * Information about the model */ - modelInfo: ModelInfo; + modelInfo: CustomFormModelInfo; /** * Keys recognized from unlabeled training. */ @@ -760,7 +812,7 @@ export interface FormModel { trainResult?: FormTrainResult; } -export interface CustomFormSubModelField { +export interface CustomFormField { /** * Estimated extraction accuracy for this field. */ @@ -779,7 +831,7 @@ export interface CustomFormSubModel { /** * Form fields */ - fields: { [propertyName: string]: CustomFormSubModelField }; + fields: { [propertyName: string]: CustomFormField }; /** * Form type */ @@ -797,7 +849,7 @@ export interface CustomFormModel { /** * Status of the model. */ - status: ModelStatus; + status: CustomFormModelStatus; /** * Date and time (UTC) when the model was created. */ @@ -813,13 +865,53 @@ export interface CustomFormModel { /** * Errors returned during training operation. */ - errors?: ErrorInformation[]; + errors?: FormRecognizerError[]; /** * Form models created by training. */ models?: CustomFormSubModel[]; } +/** + * Custom model training result. + */ +export interface TrainResult { + /** + * List of the documents used to train the model and any errors reported in each document. + */ + trainingDocuments: TrainingDocumentInfo[]; + /** + * List of fields used to train the model and the train operation error reported by each. + */ + fields?: FormFieldsReport[]; + /** + * Average accuracy. + */ + averageModelAccuracy?: number; + /** + * Errors returned during the training operation. + */ + errors?: FormRecognizerError[]; +} + +/** + * Response to the get custom model operation. + */ +export interface Model { + /** + * Basic custom model information. + */ + modelInfo: ModelInfo; + /** + * Keys extracted by the custom model. + */ + keys?: KeysResult; + /** + * Custom model training result. + */ + trainResult?: TrainResult; +} + /** * Contains the response data for retrieving a model from unlabeled training. */ @@ -856,9 +948,9 @@ export interface AccountProperties { /** * Current count of trained custom models. */ - count: number; + customModelCount: number; /** * Max number of models that can be trained for this account. */ - limit: number; + customModelLimit: number; } diff --git a/sdk/formrecognizer/ai-form-recognizer/src/transforms.ts b/sdk/formrecognizer/ai-form-recognizer/src/transforms.ts index 31f46a9a96c2..de888ee7a070 100644 --- a/sdk/formrecognizer/ai-form-recognizer/src/transforms.ts +++ b/sdk/formrecognizer/ai-form-recognizer/src/transforms.ts @@ -20,7 +20,7 @@ import { import { FormPage, FormLine, - FormElement, + FormContent, FormTableRow, FormTable, RecognizedForm, @@ -41,7 +41,7 @@ import { ArrayFieldValue, Point2D, FormModelResponse, - CustomFormSubModelField, + CustomFormField, CustomFormSubModel, RecognizedReceipt, USReceiptType, @@ -96,7 +96,7 @@ export function toFormPage(original: ReadResultModel): FormPage { // Note: might need to support other element types in future, e.g., checkbox const textPattern = /\/readResults\/(\d+)\/lines\/(\d+)(?:\/words\/(\d+))?/; -export function toFormElement(element: string, readResults: FormPage[]): FormElement { +export function toFormContent(element: string, readResults: FormPage[]): FormContent { const result = textPattern.exec(element); if (!result || !result[0] || !result[1] || !result[2]) { throw new Error(`Unexpected element reference encountered: ${element}`); @@ -116,7 +116,7 @@ export function toFormText(original: KeyValueElementModel, readResults?: FormPag return { text: original.text, boundingBox: original.boundingBox ? toBoundingBox(original.boundingBox) : undefined, - textContent: original.elements?.map((element) => toFormElement(element, readResults!)) + textContent: original.elements?.map((element) => toFormContent(element, readResults!)) }; } @@ -124,7 +124,7 @@ export function toFormField(original: KeyValuePairModel, readResults?: FormPage[ return { name: original.label, confidence: original.confidence || 1, - fieldLabel: toFormText(original.key, readResults), + labelText: toFormText(original.key, readResults), valueText: toFormText(original.value, readResults), value: original.value.text, valueType: "string" @@ -142,7 +142,7 @@ export function toFormTable(original: DataTableModel, readResults?: FormPage[]): columnIndex: cell.columnIndex, columnSpan: cell.columnSpan || 1, confidence: cell.confidence, - textContent: cell.elements?.map((element) => toFormElement(element, readResults!)), + textContent: cell.elements?.map((element) => toFormContent(element, readResults!)), isFooter: cell.isFooter || false, isHeader: cell.isHeader || false, rowIndex: cell.rowIndex, @@ -224,7 +224,7 @@ export function toFieldValue(original: FieldValueModel, readResults: FormPage[]) boundingBox: original.boundingBox ? toBoundingBox(original.boundingBox) : undefined, confidence: original.confidence || 1, pageNumber: original.pageNumber, - textContent: original.elements?.map((element) => toFormElement(element, readResults)) + textContent: original.elements?.map((element) => toFormContent(element, readResults)) }; switch (original.type) { case "string": @@ -544,7 +544,7 @@ export function toFormModelResponse(response: GetCustomModelResponse): FormModel if (response.trainResult?.averageModelAccuracy || response.trainResult?.fields) { // training with forms and labels, populate from trainingResult.fields - const fields: { [propertyName: string]: CustomFormSubModelField } = {}; + const fields: { [propertyName: string]: CustomFormField } = {}; for (const f of response.trainResult.fields!) { fields[f.fieldName] = { name: f.fieldName, accuracy: f.accuracy }; } @@ -565,7 +565,7 @@ export function toFormModelResponse(response: GetCustomModelResponse): FormModel const models: CustomFormSubModel[] = []; for (const clusterKey in response.keys.clusters) { const cluster = response.keys.clusters[clusterKey]; - const fields: { [propertyName: string]: CustomFormSubModelField } = {}; + const fields: { [propertyName: string]: CustomFormField } = {}; for (let i = 0; i < cluster.length; i++) { fields[`field-${i}`] = { name: `field-${i}` }; diff --git a/sdk/formrecognizer/ai-form-recognizer/test/browser/formtrainingclient.spec.ts b/sdk/formrecognizer/ai-form-recognizer/test/browser/formtrainingclient.spec.ts index 7599da5832ce..e962a7a55876 100644 --- a/sdk/formrecognizer/ai-form-recognizer/test/browser/formtrainingclient.spec.ts +++ b/sdk/formrecognizer/ai-form-recognizer/test/browser/formtrainingclient.spec.ts @@ -136,16 +136,16 @@ describe("FormTrainingClient browser only", () => { it("getAccountProperties() gets model count and limit for this account", async () => { const properties = await trainingClient.getAccountProperties(); - assert.ok(properties.count > 0, `Expecting models in account but got ${properties.count}`); + assert.ok(properties.customModelCount > 0, `Expecting models in account but got ${properties.customModelCount}`); assert.ok( - properties.limit > 0, - `Expecting maximum number of models in account but got ${properties.limit}` + properties.customModelLimit > 0, + `Expecting maximum number of models in account but got ${properties.customModelLimit}` ); }); it("listModels() iterates models in this account", async () => { let count = 0; - for await (const _model of trainingClient.listModels()) { + for await (const _model of trainingClient.listCustomModels()) { count++; if (count > 30) { break; // work around issue https://github.com/Azure/azure-sdk-for-js/issues/8353 @@ -155,7 +155,7 @@ describe("FormTrainingClient browser only", () => { }); it("listModels() allows getting next model info", async () => { - const iter = trainingClient.listModels(); + const iter = trainingClient.listCustomModels(); const item = await iter.next(); assert.ok(item, `Expecting a model but got ${item}`); assert.ok(item.value.modelId, `Expecting a model id but got ${item.value.modelId}`); @@ -166,7 +166,7 @@ describe("FormTrainingClient browser only", () => { this.skip(); } - const modelInfo = await trainingClient.getModel(modelIdToDelete!); + const modelInfo = await trainingClient.getCustomModel(modelIdToDelete!); assert.ok(modelInfo.modelId === modelIdToDelete, "Expecting same model id"); assert.ok( @@ -182,7 +182,7 @@ describe("FormTrainingClient browser only", () => { await trainingClient.deleteModel(modelIdToDelete!); try { - await trainingClient.getModel(modelIdToDelete!); + await trainingClient.getCustomModel(modelIdToDelete!); throw new Error("Expect that an error has already been thrown"); } catch (err) { const message = (err as Error).message; @@ -217,7 +217,7 @@ describe("FormRecognizerClient custom form recognition browser only", () => { const url = `${urlParts[0]}/Form_1.jpg?${urlParts[1]}`; assert.ok(unlabeledModelId, "Expecting valid model id from training without labels"); - const poller = await recognizerClient.beginRecognizeFormsFromUrl(unlabeledModelId!, url); + const poller = await recognizerClient.beginRecognizeCustomFormsFromUrl(unlabeledModelId!, url); await poller.pollUntilDone(); const response = poller.getResult(); @@ -255,7 +255,7 @@ describe("FormRecognizerClient custom form recognition browser only", () => { assert.ok(unlabeledModelId, "Expecting valid model id from training without labels"); assert.ok(data, "Expect valid Blob data to use as input"); - const poller = await recognizerClient.beginRecognizeForms(unlabeledModelId!, data!); + const poller = await recognizerClient.beginRecognizeCustomForms(unlabeledModelId!, data!); await poller.pollUntilDone(); const response = poller.getResult(); diff --git a/sdk/formrecognizer/ai-form-recognizer/test/node/formtrainingclient.spec.ts b/sdk/formrecognizer/ai-form-recognizer/test/node/formtrainingclient.spec.ts index e1a17a459d5e..979eae484993 100644 --- a/sdk/formrecognizer/ai-form-recognizer/test/node/formtrainingclient.spec.ts +++ b/sdk/formrecognizer/ai-form-recognizer/test/node/formtrainingclient.spec.ts @@ -144,16 +144,16 @@ describe("FormTrainingClient NodeJS only", () => { it("getAccountProperties() gets model count and limit for this account", async () => { const properties = await trainingClient.getAccountProperties(); - assert.ok(properties.count > 0, `Expecting models in account but got ${properties.count}`); + assert.ok(properties.customModelCount > 0, `Expecting models in account but got ${properties.customModelCount}`); assert.ok( - properties.limit > 0, - `Expecting maximum number of models in account but got ${properties.limit}` + properties.customModelLimit > 0, + `Expecting maximum number of models in account but got ${properties.customModelLimit}` ); }); it("listModels() iterates models in this account", async () => { let count = 0; - for await (const _model of trainingClient.listModels()) { + for await (const _model of trainingClient.listCustomModels()) { count++; if (count > 30) { break; // work around issue https://github.com/Azure/azure-sdk-for-js/issues/8353 @@ -163,7 +163,7 @@ describe("FormTrainingClient NodeJS only", () => { }); it("listModels() allows getting next model info", async () => { - const iter = trainingClient.listModels(); + const iter = trainingClient.listCustomModels(); const item = await iter.next(); assert.ok(item, `Expecting a model but got ${item}`); assert.ok(item.value.modelId, `Expecting a model id but got ${item.value.modelId}`); @@ -174,7 +174,7 @@ describe("FormTrainingClient NodeJS only", () => { this.skip(); } - const modelInfo = await trainingClient.getModel(modelIdToDelete!); + const modelInfo = await trainingClient.getCustomModel(modelIdToDelete!); assert.ok(modelInfo.modelId === modelIdToDelete, "Expecting same model id"); assert.ok( @@ -190,7 +190,7 @@ describe("FormTrainingClient NodeJS only", () => { await trainingClient.deleteModel(modelIdToDelete!); try { - await trainingClient.getModel(modelIdToDelete!); + await trainingClient.getCustomModel(modelIdToDelete!); throw new Error("Expect that an error has already been thrown"); } catch (err) { const message = (err as Error).message; @@ -225,7 +225,7 @@ describe("FormRecognizerClient form recognition NodeJS", () => { const stream = fs.createReadStream(filePath); assert.ok(unlabeledModelId, "Expecting valid model id from training without labels"); - const poller = await recognizerClient.beginRecognizeForms( + const poller = await recognizerClient.beginRecognizeCustomForms( unlabeledModelId!, stream, "image/jpeg" @@ -257,7 +257,7 @@ describe("FormRecognizerClient form recognition NodeJS", () => { const url = `${urlParts[0]}/Form_1.jpg?${urlParts[1]}`; assert.ok(unlabeledModelId, "Expecting valid model id from training without labels"); - const poller = await recognizerClient.beginRecognizeFormsFromUrl(unlabeledModelId!, url); + const poller = await recognizerClient.beginRecognizeCustomFormsFromUrl(unlabeledModelId!, url); await poller.pollUntilDone(); const response = poller.getResult(); @@ -284,7 +284,7 @@ describe("FormRecognizerClient form recognition NodeJS", () => { const stream = fs.createReadStream(filePath); assert.ok(unlabeledModelId, "Expecting valid model id from training without labels"); - const poller = await recognizerClient.beginRecognizeForms( + const poller = await recognizerClient.beginRecognizeCustomForms( labeledModelId!, stream, "image/jpeg" @@ -318,7 +318,7 @@ describe("FormRecognizerClient form recognition NodeJS", () => { const stream = fs.createReadStream(filePath); assert.ok(labeledModelId, "Expecting valid model id from training without labels"); - const poller = await recognizerClient.beginRecognizeForms(labeledModelId!, stream); + const poller = await recognizerClient.beginRecognizeCustomForms(labeledModelId!, stream); await poller.pollUntilDone(); const response = poller.getResult(); @@ -348,7 +348,7 @@ describe("FormRecognizerClient form recognition NodeJS", () => { const stream = fs.createReadStream(filePath); assert.ok(labeledModelId, "Expecting valid model id from training without labels"); - const poller = await recognizerClient.beginRecognizeForms(labeledModelId!, stream); + const poller = await recognizerClient.beginRecognizeCustomForms(labeledModelId!, stream); await poller.pollUntilDone(); const response = poller.getResult(); @@ -373,9 +373,9 @@ describe("FormRecognizerClient form recognition NodeJS", () => { "Expecting 'Merchant' field has undefined confidence" ); assert.equal( - form.fields["Merchant"].fieldLabel, + form.fields["Merchant"].labelText, undefined, - "Expecting 'Merchant' field has undefined fieldLabel" + "Expecting 'Merchant' field has undefined labelText" ); assert.equal( form.fields["Merchant"].value, diff --git a/sdk/formrecognizer/ai-form-recognizer/test/transforms.spec.ts b/sdk/formrecognizer/ai-form-recognizer/test/transforms.spec.ts index 401845ad4e47..94812c7b2e3c 100644 --- a/sdk/formrecognizer/ai-form-recognizer/test/transforms.spec.ts +++ b/sdk/formrecognizer/ai-form-recognizer/test/transforms.spec.ts @@ -6,7 +6,7 @@ import { assert } from "chai"; import { toTextLine, toFormPage, - toFormElement, + toFormContent, toFormText, toFormField, toFieldValue, @@ -138,7 +138,7 @@ describe("Transforms", () => { const stringRef = "#/readResults/0/lines/0/words/0"; const readResults = [originalReadResult1, originalReadResult2].map(toFormPage); - const transformed = toFormElement(stringRef, readResults); + const transformed = toFormContent(stringRef, readResults); assert.deepStrictEqual(transformed, readResults[0].lines![0].words[0]); }); @@ -148,7 +148,7 @@ describe("Transforms", () => { it("toExtractedElement() converts line string reference to extracted line", () => { const stringRef = "#/readResults/1/lines/1"; - const transformed = toFormElement(stringRef, formPages); + const transformed = toFormContent(stringRef, formPages); assert.deepStrictEqual(transformed, formPages[1].lines![1]); }); @@ -181,14 +181,14 @@ describe("Transforms", () => { assert.equal(transformed.name, original.label); assert.equal(transformed.confidence, original.confidence); - assert.ok(transformed.fieldLabel); - assert.ok(transformed.fieldLabel!.boundingBox); + assert.ok(transformed.labelText); + assert.ok(transformed.labelText!.boundingBox); assert.ok(transformed.valueText); assert.ok(transformed.valueText!.boundingBox); - verifyBoundingBox(transformed.fieldLabel!.boundingBox!, original.key.boundingBox); + verifyBoundingBox(transformed.labelText!.boundingBox!, original.key.boundingBox); verifyBoundingBox(transformed.valueText!.boundingBox!, original.value.boundingBox); assert.deepStrictEqual( - transformed.fieldLabel!.textContent![0], + transformed.labelText!.textContent![0], formPages[0].lines![0].words[0] ); assert.deepStrictEqual(transformed.valueText!.textContent![1], formPages[0].lines![0].words[1]); @@ -374,9 +374,9 @@ describe("Transforms", () => { "Expecting missingField has undefined confidence" ); assert.equal( - transformed.missingField.fieldLabel, + transformed.missingField.labelText, undefined, - "Expecting missingField has undefined fieldLabel" + "Expecting missingField has undefined labelText" ); assert.equal( transformed.missingField.value,