@azure/ai-text-analytics 6.0.0-alpha.20220516.1 → 6.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Microsoft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,373 @@
1
+ # Migrating to `@azure/ai-text-analytics` Version 6
2
+
3
+ **Note ⚠️**: `@azure/ai-text-analytics` version 6 is currently a beta package. Certain aspects of the package's API surface and implementation may change during the course of its development, and this document is a work-in-progress and may change to reflect updates to the package. We value your feedback, and it is especially useful during the beta development cycle. Please [create an issue](https://github.com/Azure/azure-sdk-for-js/issues/new/choose) to suggest any improvements or report any problems with this guide or with the package itself.
4
+
5
+ Major version 6 introduces a full redesign of the Azure Text Analytics client library. To leverage features of the Azure Cognitive Language Service API (version "2022-04-01-preview" and newer), the new client library is required, and application code must be updated accordingly as will be detailed below. To summarize:
6
+
7
+ - Version 5 of the `@azure/ai-text-analytics` package _only_ supports Text Analytics service API version 3.0 and 3.1, and will not support the new Azure Cognitive Language Service.
8
+ - Version 6 (beta) of the package supports Azure Cognitive Language Service API version "2022-04-01-preview", and future releases of this major version will support newer service API versions as well. It also drops support for the old Text Analytics API.
9
+
10
+ This document provides instructions for updating your application code to the new major version 6 of the client library. In this document, the examples provided use TypeScript to provide type information, but all runtime behavior changes naturally apply to plain JavaScript as well.
11
+
12
+ ## Partial Migration (Side-by-Side)
13
+
14
+ To avoid migrating an application all at once, major version 6 may be installed alongside major version 5 using a dependency alias. Either version may be aliased. For example, to install the new client library under an alias, add the following to the `dependencies` field of `package.json`:
15
+
16
+ ```javascript
17
+ {
18
+ ...,
19
+ "dependencies": {
20
+ ...,
21
+ "@azure/ai-text-analytics": "^5.1.0",
22
+ "@azure/ai-text-analytics-new": "npm:@azure/ai-text-analytics@6.0.0-beta.1"
23
+ }
24
+ }
25
+ ```
26
+
27
+ With this configuration, imports from `"@azure/ai-text-analytics"` will import from major version 5, and imports from `"@azure/ai-text-analytics-new"` will import from major version 6. Of course, major version 5 could be aliased instead:
28
+
29
+ ```javascript
30
+ {
31
+ ...,
32
+ "dependencies": {
33
+ ...,
34
+ "@azure/ai-text-analytics": "6.0.0-beta.1",
35
+ "@azure/ai-text-analytics-old": "npm:@azure/ai-text-analytics@^5.1.0"
36
+ }
37
+ }
38
+ ```
39
+
40
+ Then, the two packages may be used side-by-side, and an application may be migrated partially or over time:
41
+
42
+ ```javascript
43
+ import { TextAnalyticsClient } from "@azure/ai-text-analytics-old";
44
+ import { TextAnalysisClient } from "@azure/ai-text-analytics";
45
+ ```
46
+
47
+ ## Understanding the New Types
48
+
49
+ In the new major version 6, several types have been introduced, renamed, restructured, and removed. This section describes the differences between the two versions.
50
+
51
+ ### Terminology
52
+
53
+ Some terminology has changed to reflect the enhanced capabilities of the newest Azure Cognitive Language Service APIs. For starters, the service changed its name from Azure Text Analytics to Azure Cognitive Language Service and added advanced capabilities for answering questions and analyzing conversations. However, major version 6 will only support the text analysis capabilities that are provided by the Azure Cognitive Language Service. As a result, we've made the following broad changes to the terminology used throughout the client:
54
+
55
+ - Operations are now referred to as actions in all contexts and not only when batching them.
56
+ - The actions are renamed from verb phrases to nouns, and rather than calling the corresponding individual method, a single action can be performed by passing its name as a string literal to the one method that is capable of performing single actions. For example, in major version 5, an entity recognition action is performed when calling the `recognizeEntities` method. In major version 6, this call is done by passing the `"EntityRecognition"` literal to the method that performs single actions.
57
+ - The plural word "Actions" has been replaced with the word "Batch" to indicate a batch of actions.
58
+
59
+ ### Changes to Types
60
+
61
+ The following table explores several type names from the previous (v5.x) client and shows their nearest new (v6.x) equivalent. The name changes illustrate several of the above-mentioned changes in terminology. The breaking changes between each of the pairs of types are also listed. This table provides an overview, and more detail and code samples are provided in the following sections.
62
+
63
+ <!-- prettier-ignore -->
64
+ | Previous (v5.x) Type Name | Current (v6.x) Equivalent | Symbol Type | Change description |
65
+ | ------------------------- | ------------------------- | ----------- | ----------------------------- |
66
+ | `TextAnalyticsClient` | `TextAnalysisClient` | Class | This class replaces the former and has no methods in common with it. See the section on `TextAnalysisClient` below. |
67
+ | `AnalysisPollOperationState`, `AnalyzeActionsOperationState` | `AnalyzeBatchOperationState` | Interface | This interface replaces both of the former ones |
68
+ | `OperationMetadata` and `AnalyzeActionsOperationMetadata` | `AnalyzeBatchOperationMetadata` | Interface | This interface replaces both of the former ones but still uses the same field names. However, all fields specific to the analyze batch operation are now read-only |
69
+ | `AnalyzeActionsPollerLike` | `AnalyzeBatchPoller` | Interface | This interface replaces the former one. See the entries for `AnalyzeBatchOperationState` and `PagedAnalyzeBatchResult` for more details |
70
+ | `AnalyzeActionsResult` | `AnalyzeBatchResult` | Interface | The old one contained a field for each kind of action and those fields contained arrays of results. On the other hand, the new interface is a union of a set of interfaces where each one represents the result of a particular action with `kind` as a common field to act as a discriminator between different results |
71
+ | `AnalyzeHealthcareEntitiesErrorResult` | `HealthcareErrorResult` | Interface | |
72
+ | `AnalyzeHealthcareEntitiesResult` | `HealthcareResult` | Interface | |
73
+ | `AnalyzeHealthcareEntitiesSuccessResult` | `HealthcareSuccessResult` | Interface | |
74
+ | `AnalyzeSentimentAction` and `AnalyzeSentimentOptions` | `SentimentAnalysisAction` | Interface | |
75
+ | `AnalyzeSentimentErrorResult` | `SentimentAnalysisErrorResult` | Interface | |
76
+ | `AnalyzeSentimentActionErrorResult`, `ExtractKeyPhrasesActionErrorResult`, `ExtractSummaryActionErrorResult`, `MultiCategoryClassifyActionErrorResult`, `RecognizeCategorizedEntitiesActionErrorResult`, `RecognizeLinkedEntitiesActionErrorResult`, `RecognizePiiEntitiesActionErrorResult`, `RecongizeCustomEntitiesActionErrorResult`, and `SingleCategoryClassifyActionErrorResult` | `BatchActionErrorResult` | Interface | The old types were strucurally similar and the new type replaces them all |
77
+ | `AnalyzeSentimentActionResult` | `SentimentAnalysisBatchResult` | Interface | The new interface is part of the union of `AnalyzeBatchResult` |
78
+ | `AnalyzeSentimentActionSuccessResult`, `ExtractKeyPhrasesActionSuccessResult`, `ExtractSummaryActionSuccessResult`, `MultiCategoryClassifyActionSuccessResult`, `RecognizeCategorizedEntitiesActionSuccessResult`, `RecognizeLinkedEntitiesActionSuccessResult`, `RecognizePiiEntitiesActionSuccessResult`, `RecongizeCustomEntitiesActionSuccessResult`, and `SingleCategoryClassifyActionSuccessResult` | `BatchActionSuccessResult` | Interface | The old types were strucurally similar and the new type replaces them all. Furthermore, the `results` field is now read-only |
79
+ | `AnalyzeSentimentResult` | `SentimentAnalysisResult` | Interface | |
80
+ | `AnalyzeSentimentResultArray`, `DetectLanguageResultArray`, `ExtractKeyPhrasesResultArray`, `ExtractSummaryResultArray`, `RecognizeCategorizedEntitiesResultArray`, `RecognizeLinkedEntitiesResultArray`, and `RecognizePiiEntitiesResultArray` | `SentimentAnalysisResult[]`, `LanguageDetectionResult[]`, `KeyPhraseExtractionResult[]`, `ExtractiveSummarizationResult[]`, `EntityRecognitionResult[]`, `EntityLinkingResult[]`, and `PiiEntityRecognitionResult[]` | Interface | The old types used to have `statistics` and `modelVersion` fields attached but the type has been deleted in the new client |
81
+ | `SingleCategoryClassifyResultArray`, `MultiCategoryClassifyResultArray`, and `RecognizeCustomEntitiesResultArray` | `CustomSingleLabelClassificationResult`, `CustomMultiLabelClassificationResult[]`, and `CustomEntityRecognitionResult[]` | The old types used to have `statistics`, `projectName`, and `deploymentName` fields attached but the type has been deleted in the new client |
82
+ | `AnalyzeSentimentSuccessResult` | `SentimentAnalysisSuccessResult` | Interface | All fields are now marked as read-only |
83
+ | `BeginAnalyzeActionsOptions` | `BeginAnalyzeBatchOptions` | Interface | `resumeFrom` has been deleted in the new interface |
84
+ | `CustomTextAnalyticsAction` | `ActionCustom` | Interface | `disableServiceLogs` has been added in the new interface and `actionName` has been moved to `AnalyzeBatchActionCommon` |
85
+ | `DetectLanguageErrorResult` | `LanguageDetectionErrorResult` | Interface | |
86
+ | `DetectLanguageInput` | `LanguageDetectionInput` | Interface | |
87
+ | `DetectLanguageOptions` | `LanguageDetectionAction` | Interface | |
88
+ | `DetectLanguageResult` | `LanguageDetectionResult` | Interface | |
89
+ | `DetectLanguageSuccessResult` | `LanguageDetectionSuccessResult` | Interface | |
90
+ | `EntityAssertion` | `LanguageDetectionSuccessResult` | Interface | |
91
+ | `ExtractKeyPhrasesAction` and `ExtractKeyPhrasesOptions` | `KeyPhraseExtractionAction` | Interface | |
92
+ | `ExtractKeyPhrasesActionResult` | `KeyPhraseExtractionBatchResult` | Interface | |
93
+ | `ExtractKeyPhrasesErrorResult` | `KeyPhraseExtractionErrorResult` | Interface | |
94
+ | `ExtractKeyPhrasesResult` | `KeyPhraseExtractionResult` | Interface | |
95
+ | `ExtractKeyPhrasesSuccessResult` | `KeyPhraseExtractionSuccessResult` | Interface | `keyPhrases` is now read-only |
96
+ | `ExtractSummaryAction` | `ExtractiveSummarizationAction` | Interface | |
97
+ | `ExtractSummaryActionResult` | `ExtractiveSummarizationBatchResult` | Interface | |
98
+ | `ExtractSummaryResult` | `SummarizationExtractionResult` | Interface | |
99
+ | `ExtractSummarySuccessResult` | `SummarizationExtractionSuccessResult` | Interface | `sentences` is now read-only |
100
+ | `HealthcareEntityRelation` | `HealthcareEntityRelation` | Interface | all fields are now read-only |
101
+ | `HealthcareEntityRelationRole` | `HealthcareEntityRelationRole` | Interface | all fields are now read-only |
102
+ | `KnownSummarySentencesOrderBy` | `ExtractiveSummarizationOrderingCriteria` | Interface | |
103
+ | `MultiCategoryClassifyAction` | `CustomMultiLabelClassificationAction` | Interface | |
104
+ | `MultiCategoryClassifyActionResult` | `CustomMultiLabelClassificationBatchResult` | Interface | |
105
+ | `MultiCategoryClassifyErrorResult` | `CustomMultiLabelClassificationErrorResult` | Interface | |
106
+ | `MultiCategoryClassifyResult` | `CustomMultiLabelClassificationResult` | Interface | |
107
+ | `MultiCategoryClassifySuccessResult` | `CustomMultiLabelClassificationSuccessResult` | Interface | `classifications` is now read-only |
108
+ | `Opinion` | `Opinion` | Interface | all fields are now read-only |
109
+ | `PagedAnalyzeActionsResult` | `PagedAnalyzeBatchResult` | Interface | all fields are now read-only |
110
+ | `PagedAsyncIterableAnalyzeActionsResult` | `PagedAsyncIterableIterator<AnalyzeBatchResult>` | Interface | The type of a page of results is now an array of `AnalyzeBatchResult` |
111
+ | `PiiEntity` | `Entity` | Interface | |
112
+ | `RecognizeCategorizedEntitiesAction` and `RecognizeCategorizedEntitiesOptions` | `EntityRecognitionAction` | Interface | |
113
+ | `RecognizeCategorizedEntitiesActionResult` | `EntityRecognitionBatchResult` | Interface | |
114
+ | `RecognizeCategorizedEntitiesErrorResult` | `EntityRecognitionErrorResult` | Interface | |
115
+ | `RecognizeCategorizedEntitiesResult` | `EntityRecognitionResult` | Interface | |
116
+ | `RecognizeCategorizedEntitiesSuccessResult` | `EntityRecognitionSuccessResult` | Interface | `entities` is now read-only |
117
+ | `RecognizeCustomEntitiesAction` | `CustomEntityRecognitionAction` | Interface | |
118
+ | `RecognizeCustomEntitiesActionResult` | `CustomEntityRecognitionBatchResult` | Interface | |
119
+ | `RecognizeCustomEntitiesErrorResult` | `CustomEntityRecognitionErrorResult` | Interface | |
120
+ | `RecognizeCustomEntitiesResult` | `CustomEntityRecognitionResult` | Interface | |
121
+ | `RecognizeCustomEntitiesSuccessResult` | `CustomEntityRecognitionSuccessResult` | Interface | `entities` is now read-only |
122
+ | `RecognizeLinkedEntitiesAction` and `RecognizeLinkedEntitiesOptions` | `EntityLinkingAction` | Interface | |
123
+ | `RecognizeLinkedEntitiesActionResult` | `EntityLinkingBatchResult` | Interface | |
124
+ | `RecognizeLinkedEntitiesErrorResult` | `EntityLinkingErrorResult` | Interface | |
125
+ | `RecognizeLinkedEntitiesResult` | `EntityLinkingResult` | Interface | |
126
+ | `RecognizeLinkedEntitiesSuccessResult` | `EntityLinkingSuccessResult` | Interface | |
127
+ | `RecognizePiiEntitiesAction` and `RecognizePiiEntitiesOptions` | `PiiEntityRecognitionAction` | Interface | |
128
+ | `RecognizePiiEntitiesActionResult` | `PiiEntityRecognitionBatchResult` | Interface | |
129
+ | `RecognizePiiEntitiesErrorResult` | `PiiEntityRecognitionErrorResult` | Interface | |
130
+ | `RecognizePiiEntitiesResult` | `PiiEntityRecognitionResult` | Interface | |
131
+ | `RecognizePiiEntitiesSuccessResult` | `PiiEntityRecognitionSuccessResult` | Interface | `redactedText` is now read-only |
132
+ | `SentenceSentiment` | `SentenceSentiment` | Interface | all fields are now read-only |
133
+ | `SingleCategoryClassifyAction` | `CustomSingleLabelClassificationAction` | Interface | |
134
+ | `SingleCategoryClassifyActionResult` | `CustomSingleLabelClassificationBatchResult` | Interface | |
135
+ | `SingleCategoryClassifyActionSuccessResult` | `CustomSingleLabelClassificationSuccessResult` | Interface | `classification` has been renamed to `classifications` and is now an array |
136
+ | `StringIndexType` | `StringIndexType` | Type Alias | It was a union and has been updated to be a string |
137
+ | `TargetConfidenceScoreLabel` | `TargetConfidenceScores` | Type Alias | |
138
+ | `TargetSentiment` | `TargetSentiment` | Interface | All fields are now read-only |
139
+ | `TextAnalyticsAction` | `ActionPrebuilt & AnalyzeBatchActionCommon` | Interface | |
140
+ | `TextAnalyticsActionErrorResult` | `BatchActionErrorResult` | Interface | |
141
+ | `TextAnalyticsActions` | `AnalyzeBatchAction[]` | Interface | The old one contained a field for each kind of action and those fields contained arrays of actions. On the other hand, the new interface is a union of a set of interfaces where each one represents a particular action with `kind` as a common field to act as a discriminator between different ones |
142
+ | `TextAnalyticsActionState` | `BatchActionState` | Interface | The new interface adds `kind` and `statistics` and all fields are marked as read-only |
143
+ | `TextAnalyticsActionSuccessState` | `BatchActionSuccessResult` | Interface | The new interface adds a read-only `results` field |
144
+ | `TextAnalyticsClientOptions` | `TextAnalysisClientOptions` | Interface | The new interface adds a new `apiVersion` field |
145
+ | `TextAnalyticsError` | `TextAnalysisError` | Interface | |
146
+ | `TextAnalyticsErrorResult` | `TextAnalysisErrorResult` | Interface | |
147
+ | `TextAnalyticsOperationOptions` | `ActionPrebuilt & TextAnalysisOperationOptions` | Interface | |
148
+ | `TextAnalyticsOperationStatus` | `OperationStatus` | Type Alias | |
149
+ | `TextAnalyticsSuccessResult` | `TextAnalysisSuccessResult` | Interface | |
150
+ | `TokenSentimentValue` | `TokenSentimentLabel` | Type Alias | |
151
+
152
+ ## Migrating from `TextAnalyticsClient` to `TextAnalysisClient`
153
+
154
+ The `TextAnalysisClient` class, used for all text analysis actions, has replaced `TextAnalyticsClient` (which has been removed). The constructor signature is the same, but one new option has been introduced to the client constructor, `apiVersion`, which allows the application to specify the version of the Azure Cognitive Language Service API to use (the default is the most recent version at the time of the library release, e.g. `2022-04-01-preview` for `@azure/ai-text-analytics@6.0.0-beta.1`).
155
+
156
+ The previous `TextAnalyticsClient` class and new `TextAnalysisClient` class have no methods in common. The new class only has three methods in total. They are:
157
+
158
+ - `analyze`, which replaces all of the following:
159
+ - `recognizeEntities`
160
+ - `recognizePiiEntities`
161
+ - `extractKeyPhrases`
162
+ - `detectLanguage`
163
+ - `analyzeSentiment`
164
+ - `recognizeLinkedEntities`
165
+ - `beginAnalyzeBatch`, which replaces `beginAnalyzeActions` and `beginAnalyzeHealthcareEntities`.
166
+ - `restoreAnalyzeBatchPoller`, which is new, and provides customers with the ability to restore a poller for a batch analysis operation from a serialized poller state.
167
+
168
+ All of these methods can produce `AnalyzeResult`, `AnalyzeBatchResult[]`, and `AnalyzeBatchPoller` types respectively. Please see the section above about these types for more information.
169
+
170
+ ### Action specification
171
+
172
+ In major version 5, there is one method per action for actions that are not long-running operations. For example, the `recognizeEntities` method perfoms entity recognition. In major version 6, there is only one method, `analyze`, that can perform one such action at a time. Compare the following samples using `recognizeEntities` and `analyze`:
173
+
174
+ Previous (5.1.0):
175
+
176
+ ```typescript
177
+ const client = new TextAnalyticsClient(...);
178
+ const documents = [...];
179
+
180
+ // Previously, there was one method per action for most actions
181
+ const result = await client.recognizeEntities(documents);
182
+ ```
183
+
184
+ Current (6.0.0-beta.1):
185
+
186
+ ```typescript
187
+ const client = new TextAnalysisClient(...);
188
+ const documents = [...];
189
+
190
+ // Now, an action can be performed by passing its name
191
+ const result = await client.analyze("EntityRecognition", documents);
192
+ ```
193
+
194
+ On the other hand, the way to consume the results of such actions didn't change. Furthermore, in major version 5, long-running operations actions can be batched and performed using the `beginAnalyzeActions` method. In major version 6, the same can be done using the `beginAnalyzeBatch` method but with the following two major differences:
195
+
196
+ - Healthcare analysis is now supported. In major version 5, healthcare analysis is performed exclusively using the `beginAnalyzeHealthcareEntities` method. In major version 6, it is supported exclusively as an action in `beginAnalyzeBatch`.
197
+ - Each action and their result is identified by a `kind` field in a list. In major version 5, specifying an action list of entity recognition and entity linking is done as `{ recognizeEntities: [ { ... } ], recognizeLinkedEntities: [ { ... } ] }`. In major version 6, the same is done as `[ { kind: "EntityRecognition", ... }, { kind: "EntityLinking", ... } ]`.
198
+
199
+ To look at those changes more closely, compare the following samples:
200
+
201
+ Healthcare analysis:
202
+
203
+ Previous (5.1.0):
204
+
205
+ ```typescript
206
+ const client = new TextAnalyticsClient(...);
207
+ const documents = [...];
208
+
209
+ // Previously, healthcare analysis is done by calling the following method
210
+ const poller = await client.beginAnalyzeHealthcareEntities(documents);
211
+ ```
212
+
213
+ Current (6.0.0-beta.1):
214
+
215
+ ```typescript
216
+ const client = new TextAnalysisClient(...);
217
+ const documents = [...];
218
+
219
+ // Now, it can be performed by passing it as a batch action
220
+ const poller = await client.beginAnalyzeBatch([{ kind: "Healthcare" }], documents);
221
+ ```
222
+
223
+ Specifying input actions:
224
+
225
+ Previous (5.1.0):
226
+
227
+ ```typescript
228
+ const client = new TextAnalyticsClient(...);
229
+ const documents = [...];
230
+
231
+ // Previously, batching actions we done in a deep object
232
+ const poller = await client.beginAnalyzeActions(documents, { recognizeEntities: [ {} ], recognizeLinkedEntities: [ {} ] });
233
+ ```
234
+
235
+ Current (6.0.0-beta.1):
236
+
237
+ ```typescript
238
+ const client = new TextAnalysisClient(...);
239
+ const documents = [...];
240
+
241
+ // Now, it can be done in a flat list
242
+ const poller = await client.beginAnalyzeBatch([{ kind: "EntityRecognition" }, { kind: "EntityLinking" }], documents);
243
+ ```
244
+
245
+ Consuming action results:
246
+
247
+ Previous (5.1.0):
248
+
249
+ ```typescript
250
+ const actionResults = await poller.pollUntilDone();
251
+
252
+ for await (const actionResultsPage of actionResults) {
253
+ for (const entityRecognitionActionResult of actionResultsPage.recognizeEntitiesResults) {
254
+ if (entityRecognitionActionResult.error) {
255
+ // handle errors
256
+ }
257
+ for (const doc of entityRecognitionActionResult.results) {
258
+ // do something
259
+ }
260
+ }
261
+
262
+ for (const entityLinkingActionResult of actionResultsPage.recognizeLinkedEntitiesResults) {
263
+ if (entityLinkingActionResult.error) {
264
+ // handle errors
265
+ }
266
+ for (const doc of entityLinkingActionResult.results) {
267
+ // do something
268
+ }
269
+ }
270
+ }
271
+ ```
272
+
273
+ Current (6.0.0-beta.1):
274
+
275
+ ```typescript
276
+ const actionResults = await poller.pollUntilDone();
277
+ for await (const actionResult of actionResults) {
278
+ if (actionResult.error) {
279
+ throw new Error(`Unexpected error`);
280
+ }
281
+ switch (actionResult.kind) {
282
+ case "EntityLinking": {
283
+ for (const doc of actionResult.results) {
284
+ // do something
285
+ }
286
+ break;
287
+ }
288
+ case "PiiEntityRecognition": {
289
+ for (const doc of actionResult.results) {
290
+ // do something
291
+ }
292
+ break;
293
+ }
294
+ }
295
+ }
296
+ ```
297
+
298
+ ### Accessing statistics and model information for `analyze` results
299
+
300
+ In major version 5, statistics about an action were returned as part of the results in a `statistics` property attached to the array of results. In major version 6, `statistics` is no longer attached and can be accessed instead in the http response:
301
+
302
+ Previous (5.1.0):
303
+
304
+ ```typescript
305
+ const client = new TextAnalyticsClient(...);
306
+ const documents = [...];
307
+
308
+ // Previously, `statistics` is part of the results array
309
+ const results = await client.analyze("EntityLinking", documents, "en", { includeStatistics: true });
310
+ const stats = results.statistics;
311
+ console.log(`- Documents count: ${stats.documentCount}`);
312
+ console.log(`- Valid documents count: ${stats.validDocumentCount}`);
313
+ console.log(`- Erroneous documents count: ${stats.erroneousDocumentCount}`);
314
+ console.log(`- Transactions count: ${stats.transactionCount}`);
315
+ ```
316
+
317
+ Current (6.0.0-beta.1):
318
+
319
+ ```typescript
320
+ const client = new TextAnalysisClient(...);
321
+ const documents = [...];
322
+
323
+ // Now, it can be accessed from the http response
324
+ const results = await client.analyze("EntityLinking", documents, "en", {
325
+ includeStatistics: true,
326
+ /**
327
+ * Access general statistics information about the action from the HTTP
328
+ * response.
329
+ */
330
+ onResponse: (_rawResponse, flatResponse) => {
331
+ const stats = (flatResponse as any).results.statistics as TextDocumentBatchStatistics;
332
+ console.log(`- Documents count: ${stats.documentCount}`);
333
+ console.log(`- Valid documents count: ${stats.validDocumentCount}`);
334
+ console.log(`- Erroneous documents count: ${stats.erroneousDocumentCount}`);
335
+ console.log(`- Transactions count: ${stats.transactionCount}`);
336
+ },
337
+ });
338
+ ```
339
+
340
+ Furthermore, in major version 5, model information about an action were returned as part of the results in a `modelVersion` property attached to the array of results. In major version 6, the same information can be accessed instead from the http response:
341
+
342
+ Previous (5.1.0):
343
+
344
+ ```typescript
345
+ const client = new TextAnalyticsClient(...);
346
+ const documents = [...];
347
+
348
+ // Previously, `statistics` is part of the results array
349
+ const results = await client.analyze("EntityLinking", documents, "en", { includeStatistics: true });
350
+ console.log(`The result of the sentiment analysis was computed using model version: ${results.modelVersion}`);
351
+ ```
352
+
353
+ Current (6.0.0-beta.1):
354
+
355
+ ```typescript
356
+ const client = new TextAnalysisClient(...);
357
+ const documents = [...];
358
+
359
+ // Now, it can be accessed from the http response
360
+ const results = await client.analyze("EntityLinking", documents, "en", {
361
+ modelVersion: "latest",
362
+ /**
363
+ * Access general model information about the action from the HTTP
364
+ * response.
365
+ */
366
+ onResponse: (_rawResponse, flatResponse) => {
367
+ const modelVersion = (flatResponse as any).results.modelVersion;
368
+ console.log(
369
+ `The result of the entity linking was computed using model version: ${modelVersion}`
370
+ );
371
+ },
372
+ });
373
+ ```