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

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.
Files changed (97) hide show
  1. package/README.md +376 -132
  2. package/dist/index.js +2803 -3497
  3. package/dist/index.js.map +1 -1
  4. package/dist-esm/src/azureKeyCredentialPolicy.js +2 -2
  5. package/dist-esm/src/azureKeyCredentialPolicy.js.map +1 -1
  6. package/dist-esm/src/constants.js +16 -0
  7. package/dist-esm/src/constants.js.map +1 -0
  8. package/dist-esm/src/generated/generatedClient.js +80 -334
  9. package/dist-esm/src/generated/generatedClient.js.map +1 -1
  10. package/dist-esm/src/generated/index.js +1 -1
  11. package/dist-esm/src/generated/index.js.map +1 -1
  12. package/dist-esm/src/generated/models/index.js +106 -35
  13. package/dist-esm/src/generated/models/index.js.map +1 -1
  14. package/dist-esm/src/generated/models/mappers.js +1607 -1464
  15. package/dist-esm/src/generated/models/mappers.js.map +1 -1
  16. package/dist-esm/src/generated/models/parameters.js +18 -104
  17. package/dist-esm/src/generated/models/parameters.js.map +1 -1
  18. package/dist-esm/src/generated/operations/analyzeText.js +105 -0
  19. package/dist-esm/src/generated/operations/analyzeText.js.map +1 -0
  20. package/dist-esm/src/generated/operations/index.js +9 -0
  21. package/dist-esm/src/generated/operations/index.js.map +1 -0
  22. package/dist-esm/src/generated/operationsInterfaces/analyzeText.js +9 -0
  23. package/dist-esm/src/generated/operationsInterfaces/analyzeText.js.map +1 -0
  24. package/dist-esm/src/generated/operationsInterfaces/index.js +9 -0
  25. package/dist-esm/src/generated/operationsInterfaces/index.js.map +1 -0
  26. package/dist-esm/src/index.js +14 -5
  27. package/dist-esm/src/index.js.map +1 -1
  28. package/dist-esm/src/lro.js +195 -0
  29. package/dist-esm/src/lro.js.map +1 -0
  30. package/dist-esm/src/models.js +42 -0
  31. package/dist-esm/src/models.js.map +1 -0
  32. package/dist-esm/src/textAnalysisClient.js +197 -0
  33. package/dist-esm/src/textAnalysisClient.js.map +1 -0
  34. package/dist-esm/src/transforms.js +279 -0
  35. package/dist-esm/src/transforms.js.map +1 -0
  36. package/dist-esm/src/util.js +36 -158
  37. package/dist-esm/src/util.js.map +1 -1
  38. package/package.json +28 -38
  39. package/types/ai-text-analytics.d.ts +1432 -1143
  40. package/CHANGELOG.md +0 -143
  41. package/LICENSE +0 -21
  42. package/dist-esm/src/analyzeActionsResult.js +0 -167
  43. package/dist-esm/src/analyzeActionsResult.js.map +0 -1
  44. package/dist-esm/src/analyzeHealthcareEntitiesResult.js +0 -53
  45. package/dist-esm/src/analyzeHealthcareEntitiesResult.js.map +0 -1
  46. package/dist-esm/src/analyzeLro.js +0 -130
  47. package/dist-esm/src/analyzeLro.js.map +0 -1
  48. package/dist-esm/src/analyzeSentimentResult.js +0 -74
  49. package/dist-esm/src/analyzeSentimentResult.js.map +0 -1
  50. package/dist-esm/src/analyzeSentimentResultArray.js +0 -11
  51. package/dist-esm/src/analyzeSentimentResultArray.js.map +0 -1
  52. package/dist-esm/src/detectLanguageResult.js +0 -17
  53. package/dist-esm/src/detectLanguageResult.js.map +0 -1
  54. package/dist-esm/src/detectLanguageResultArray.js +0 -11
  55. package/dist-esm/src/detectLanguageResultArray.js.map +0 -1
  56. package/dist-esm/src/extractKeyPhrasesResult.js +0 -17
  57. package/dist-esm/src/extractKeyPhrasesResult.js.map +0 -1
  58. package/dist-esm/src/extractKeyPhrasesResultArray.js +0 -11
  59. package/dist-esm/src/extractKeyPhrasesResultArray.js.map +0 -1
  60. package/dist-esm/src/extractSummaryResult.js +0 -17
  61. package/dist-esm/src/extractSummaryResult.js.map +0 -1
  62. package/dist-esm/src/extractSummaryResultArray.js +0 -11
  63. package/dist-esm/src/extractSummaryResultArray.js.map +0 -1
  64. package/dist-esm/src/generated/generatedClientContext.js +0 -42
  65. package/dist-esm/src/generated/generatedClientContext.js.map +0 -1
  66. package/dist-esm/src/healthLro.js +0 -131
  67. package/dist-esm/src/healthLro.js.map +0 -1
  68. package/dist-esm/src/paging.js +0 -83
  69. package/dist-esm/src/paging.js.map +0 -1
  70. package/dist-esm/src/pollerModels.js +0 -4
  71. package/dist-esm/src/pollerModels.js.map +0 -1
  72. package/dist-esm/src/recognizeCategorizedEntitiesResult.js +0 -17
  73. package/dist-esm/src/recognizeCategorizedEntitiesResult.js.map +0 -1
  74. package/dist-esm/src/recognizeCategorizedEntitiesResultArray.js +0 -11
  75. package/dist-esm/src/recognizeCategorizedEntitiesResultArray.js.map +0 -1
  76. package/dist-esm/src/recognizeLinkedEntitiesResult.js +0 -17
  77. package/dist-esm/src/recognizeLinkedEntitiesResult.js.map +0 -1
  78. package/dist-esm/src/recognizeLinkedEntitiesResultArray.js +0 -11
  79. package/dist-esm/src/recognizeLinkedEntitiesResultArray.js.map +0 -1
  80. package/dist-esm/src/recognizePiiEntitiesResult.js +0 -18
  81. package/dist-esm/src/recognizePiiEntitiesResult.js.map +0 -1
  82. package/dist-esm/src/recognizePiiEntitiesResultArray.js +0 -11
  83. package/dist-esm/src/recognizePiiEntitiesResultArray.js.map +0 -1
  84. package/dist-esm/src/textAnalyticsAction.js +0 -4
  85. package/dist-esm/src/textAnalyticsAction.js.map +0 -1
  86. package/dist-esm/src/textAnalyticsClient.js +0 -523
  87. package/dist-esm/src/textAnalyticsClient.js.map +0 -1
  88. package/dist-esm/src/textAnalyticsOperationOptions.js +0 -4
  89. package/dist-esm/src/textAnalyticsOperationOptions.js.map +0 -1
  90. package/dist-esm/src/textAnalyticsResult.js +0 -78
  91. package/dist-esm/src/textAnalyticsResult.js.map +0 -1
  92. package/dist-esm/src/tracing.js +0 -12
  93. package/dist-esm/src/tracing.js.map +0 -1
  94. package/dist-esm/src/utils/url.browser.js +0 -6
  95. package/dist-esm/src/utils/url.browser.js.map +0 -1
  96. package/dist-esm/src/utils/url.js +0 -4
  97. package/dist-esm/src/utils/url.js.map +0 -1
package/README.md CHANGED
@@ -1,17 +1,19 @@
1
- # Azure Text Analytics client library for JavaScript
1
+ # Azure Text Analysis client library for JavaScript
2
2
 
3
- [Azure TextAnalytics](https://azure.microsoft.com/services/cognitive-services/text-analytics/) is a cloud-based service that provides advanced natural language processing over raw text, and includes the following main features:
3
+ [Azure Cognitive Service for Language](https://azure.microsoft.com/services/cognitive-services/language-service/) is a cloud-based service that provides advanced natural language processing over raw text, and includes the following main features:
4
4
 
5
- **Note:** This SDK targets Azure Text Analytics service API version 3.2.0-preview.1.
5
+ **Note:** This SDK targets Azure Cognitive Service for Language API version 2022-04-01-preview.
6
6
 
7
7
  - Language Detection
8
8
  - Sentiment Analysis
9
9
  - Key Phrase Extraction
10
10
  - Named Entity Recognition
11
11
  - Recognition of Personally Identifiable Information
12
- - Linked Entity Recognition
13
- - Extractive Summarization
12
+ - Entity Linking
14
13
  - Healthcare Analysis
14
+ - Extractive Summarization
15
+ - Custom Entity Recognition
16
+ - Custom Document Classification
15
17
  - Support Multiple Actions Per Document
16
18
 
17
19
  Use the client library to:
@@ -27,7 +29,7 @@ Key links:
27
29
  - [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/)
28
30
  - [Package (NPM)](https://www.npmjs.com/package/@azure/ai-text-analytics)
29
31
  - [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-text-analytics)
30
- - [Product documentation](https://docs.microsoft.com/azure/cognitive-services/text-analytics/)
32
+ - [Product documentation](https://docs.microsoft.com/azure/cognitive-services/language-service/)
31
33
  - [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/textanalytics/ai-text-analytics/samples)
32
34
 
33
35
  ## Getting started
@@ -42,7 +44,7 @@ See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUP
42
44
  ### Prerequisites
43
45
 
44
46
  - An [Azure subscription][azure_sub].
45
- - An existing [Cognitive Services][cognitive_resource] or Text Analytics resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].
47
+ - An existing [Cognitive Services][cognitive_resource] or Language resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].
46
48
 
47
49
  If you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:
48
50
 
@@ -52,25 +54,25 @@ az cognitiveservices account create --kind TextAnalytics --resource-group <your-
52
54
 
53
55
  ### Install the `@azure/ai-text-analytics` package
54
56
 
55
- Install the Azure Text Analytics client library for JavaScript with `npm`:
57
+ Install the Azure Text Analysis client library for JavaScript with `npm`:
56
58
 
57
59
  ```bash
58
60
  npm install @azure/ai-text-analytics
59
61
  ```
60
62
 
61
- ### Create and authenticate a `TextAnalyticsClient`
63
+ ### Create and authenticate a `TextAnalysisClient`
62
64
 
63
- To create a client object to access the Text Analytics API, you will need the `endpoint` of your Text Analytics resource and a `credential`. The Text Analytics client can use either Azure Active Directory credentials or an API key credential to authenticate.
65
+ To create a client object to access the Language API, you will need the `endpoint` of your Language resource and a `credential`. The Text Analysis client can use either Azure Active Directory credentials or an API key credential to authenticate.
64
66
 
65
- You can find the endpoint for your text analytics resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:
67
+ You can find the endpoint for your Language resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:
66
68
 
67
69
  ```bash
68
- az cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query "endpoint"
70
+ az cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query "properties.endpoint"
69
71
  ```
70
72
 
71
73
  #### Using an API Key
72
74
 
73
- Use the [Azure Portal][azure_portal] to browse to your Text Analytics resource and retrieve an API key, or use the [Azure CLI][azure_cli] snippet below:
75
+ Use the [Azure Portal][azure_portal] to browse to your Language resource and retrieve an API key, or use the [Azure CLI][azure_cli] snippet below:
74
76
 
75
77
  **Note:** Sometimes the API key is referred to as a "subscription key" or "subscription API key."
76
78
 
@@ -81,9 +83,9 @@ az cognitiveservices account keys list --resource-group <your-resource-group-nam
81
83
  Once you have an API key and endpoint, you can use the `AzureKeyCredential` class to authenticate the client as follows:
82
84
 
83
85
  ```javascript
84
- const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
86
+ const { TextAnalysisClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
85
87
 
86
- const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
88
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
87
89
  ```
88
90
 
89
91
  #### Using an Azure Active Directory Credential
@@ -95,26 +97,26 @@ or other credential providers provided with the Azure SDK, please install the `@
95
97
  npm install @azure/identity
96
98
  ```
97
99
 
98
- You will also need to [register a new AAD application][register_aad_app] and grant access to Text Analytics by assigning the `"Cognitive Services User"` role to your service principal (note: other roles such as `"Owner"` will not grant the necessary permissions, only `"Cognitive Services User"` will suffice to run the examples and the sample code).
100
+ You will also need to [register a new AAD application][register_aad_app] and grant access to Language by assigning the `"Cognitive Services User"` role to your service principal (note: other roles such as `"Owner"` will not grant the necessary permissions, only `"Cognitive Services User"` will suffice to run the examples and the sample code).
99
101
 
100
102
  Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.
101
103
 
102
104
  ```javascript
103
- const { TextAnalyticsClient } = require("@azure/ai-text-analytics");
105
+ const { TextAnalysisClient } = require("@azure/ai-text-analytics");
104
106
  const { DefaultAzureCredential } = require("@azure/identity");
105
107
 
106
- const client = new TextAnalyticsClient("<endpoint>", new DefaultAzureCredential());
108
+ const client = new TextAnalysisClient("<endpoint>", new DefaultAzureCredential());
107
109
  ```
108
110
 
109
111
  ## Key concepts
110
112
 
111
- ### TextAnalyticsClient
113
+ ### TextAnalysisClient
112
114
 
113
- `TextAnalyticsClient` is the primary interface for developers using the Text Analytics client library. Explore the methods on this client object to understand the different features of the Text Analytics service that you can access.
115
+ `TextAnalysisClient` is the primary interface for developers using the Text Analysis client library. Explore the methods on this client object to understand the different features of the Language service that you can access.
114
116
 
115
117
  ### Input
116
118
 
117
- A **document** represents a single unit of input to be analyzed by the predictive models in the Text Analytics service. Operations on `TextAnalyticsClient` take a collection of inputs to be analyzed as a batch. The operation methods have overloads that allow the inputs to be represented as strings, or as objects with attached metadata.
119
+ A **document** represents a single unit of input to be analyzed by the predictive models in the Language service. Operations on `TextAnalysisClient` take a collection of inputs to be analyzed as a batch. The operation methods have overloads that allow the inputs to be represented as strings, or as objects with attached metadata.
118
120
 
119
121
  For example, each document can be passed as a string in an array, e.g.
120
122
 
@@ -122,7 +124,7 @@ For example, each document can be passed as a string in an array, e.g.
122
124
  const documents = [
123
125
  "I hated the movie. It was so slow!",
124
126
  "The movie made it into my top ten favorites.",
125
- "What a great movie!"
127
+ "What a great movie!",
126
128
  ];
127
129
  ```
128
130
 
@@ -132,7 +134,7 @@ or, if you wish to pass in a per-item document `id` or `language`/`countryHint`,
132
134
  const textDocumentInputs = [
133
135
  { id: "1", language: "en", text: "I hated the movie. It was so slow!" },
134
136
  { id: "2", language: "en", text: "The movie made it into my top ten favorites." },
135
- { id: "3", language: "en", text: "What a great movie!" }
137
+ { id: "3", language: "en", text: "What a great movie!" },
136
138
  ];
137
139
  ```
138
140
 
@@ -140,66 +142,56 @@ See [service limitations][data_limits] for the input, including document length
140
142
 
141
143
  ### Return Value
142
144
 
143
- The return value corresponding to a single document is either a successful result or an error object. Each `TextAnalyticsClient` method returns a heterogeneous array of results and errors that correspond to the inputs by index. A text input and its result will have the same index in the input and result collections. The collection may also optionally include information about the input batch and how it was processed in the `statistics` field.
145
+ The return value corresponding to a single document is either a successful result or an error object. Each `TextAnalysisClient` method returns a heterogeneous array of results and errors that correspond to the inputs by index. A text input and its result will have the same index in the input and result collections.
144
146
 
145
- An **result**, such as `AnalyzeSentimentResult`, is the result of a Text Analytics operation, containing a prediction or predictions about a single text input. An operation's result type also may optionally include information about the input document and how it was processed.
147
+ An **result**, such as `SentimentAnalysisResult`, is the result of a Language operation, containing a prediction or predictions about a single text input. An operation's result type also may optionally include information about the input document and how it was processed.
146
148
 
147
- The **error** object, `TextAnalyticsErrorResult`, indicates that the service encountered an error while processing the document and contains information about the error.
149
+ The **error** object, `TextAnalysisErrorResult`, indicates that the service encountered an error while processing the document and contains information about the error.
148
150
 
149
151
  ### Document Error Handling
150
152
 
151
- In the collection returned by an operation, errors are distinguished from successful responses by the presence of the `error` property, which contains the inner `TextAnalyticsError` object if an error was encountered. For successful result objects, this property is _always_ `undefined`.
153
+ In the collection returned by an operation, errors are distinguished from successful responses by the presence of the `error` property, which contains the inner `TextAnalysisError` object if an error was encountered. For successful result objects, this property is _always_ `undefined`.
152
154
 
153
155
  For example, to filter out all errors, you could use the following `filter`:
154
156
 
155
157
  ```javascript
156
- const results = await client.analyzeSentiment(documents);
158
+ const results = await client.analyze("SentimentAnalysis", documents);
157
159
  const onlySuccessful = results.filter((result) => result.error === undefined);
158
160
  ```
159
161
 
160
162
  **Note**: TypeScript users can benefit from better type-checking of result and error objects if `compilerOptions.strictNullChecks` is set to `true` in the `tsconfig.json` configuration. For example:
161
163
 
162
164
  ```typescript
163
- const [result] = await client.analyzeSentiment(["Hello world!"]);
165
+ const [result] = await client.analyze("SentimentAnalysis", ["Hello world!"]);
164
166
 
165
167
  if (result.error !== undefined) {
166
168
  // In this if block, TypeScript will be sure that the type of `result` is
167
- // `TextAnalyticsError` if compilerOptions.strictNullChecks is enabled in
169
+ // `TextAnalysisError` if compilerOptions.strictNullChecks is enabled in
168
170
  // the tsconfig.json
169
171
 
170
172
  console.log(result.error);
171
173
  }
172
174
  ```
173
175
 
174
- This capability was introduced in TypeScript 3.2, so users of TypeScript 3.1 must cast result values to their corresponding success variant as follows:
175
-
176
- ```typescript
177
- const [result] = await client.detectLanguage(["Hello world!"]);
178
-
179
- if (result.error === undefined) {
180
- const { primaryLanguage } = result as DetectLanguageSuccessResult;
181
- }
182
- ```
183
-
184
176
  ## Examples
185
177
 
186
- ### Analyze Sentiment
178
+ ### Sentiment Analysis
187
179
 
188
180
  Analyze sentiment of text to determine if it is positive, negative, neutral, or mixed, including per-sentence sentiment analysis and confidence scores.
189
181
 
190
182
  ```javascript
191
- const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
183
+ const { TextAnalysisClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
192
184
 
193
- const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
185
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
194
186
 
195
187
  const documents = [
196
188
  "I did not like the restaurant. The food was too spicy.",
197
189
  "The restaurant was decorated beautifully. The atmosphere was unlike any other restaurant I've been to.",
198
- "The food was yummy. :)"
190
+ "The food was yummy. :)",
199
191
  ];
200
192
 
201
193
  async function main() {
202
- const results = await client.analyzeSentiment(documents);
194
+ const results = await client.analyze("SentimentAnalysis", documents);
203
195
 
204
196
  for (const result of results) {
205
197
  if (result.error === undefined) {
@@ -216,25 +208,25 @@ main();
216
208
 
217
209
  To get more granular information about the opinions related to aspects of a product/service, also known as Aspect-based Sentiment Analysis in Natural Language Processing (NLP), see a sample on sentiment analysis with opinion mining [here][analyze_sentiment_opinion_mining_sample].
218
210
 
219
- ### Recognize Entities
211
+ ### Entity Recognition
220
212
 
221
213
  Recognize and categorize entities in text as people, places, organizations, dates/times, quantities, currencies, etc.
222
214
 
223
215
  The `language` parameter is optional. If it is not specified, the default English model will be used.
224
216
 
225
217
  ```javascript
226
- const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
218
+ const { TextAnalysisClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
227
219
 
228
- const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
220
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
229
221
 
230
222
  const documents = [
231
223
  "Microsoft was founded by Bill Gates and Paul Allen.",
232
224
  "Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle.",
233
- "Jeff bought three dozen eggs because there was a 50% discount."
225
+ "Jeff bought three dozen eggs because there was a 50% discount.",
234
226
  ];
235
227
 
236
228
  async function main() {
237
- const results = await client.recognizeEntities(documents, "en");
229
+ const results = await client.analyze("EntityRecognition", documents, "en");
238
230
 
239
231
  for (const result of results) {
240
232
  if (result.error === undefined) {
@@ -251,19 +243,19 @@ async function main() {
251
243
  main();
252
244
  ```
253
245
 
254
- ### Recognize PII Entities
246
+ ### PII Entity Recognition
255
247
 
256
- There is a separate endpoint and operation for recognizing Personally Identifiable Information (PII) in text such as Social Security Numbers, bank account information, credit card numbers, etc. Its usage is very similar to the standard entity recognition above:
248
+ There is a separate action for recognizing Personally Identifiable Information (PII) in text such as Social Security Numbers, bank account information, credit card numbers, etc. Its usage is very similar to the standard entity recognition above:
257
249
 
258
250
  ```javascript
259
- const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
260
- const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
251
+ const { TextAnalysisClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
252
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
261
253
  const documents = [
262
254
  "The employee's SSN is 555-55-5555.",
263
- "The employee's phone number is (555) 555-5555."
255
+ "The employee's phone number is (555) 555-5555.",
264
256
  ];
265
257
  async function main() {
266
- const results = await client.recognizePiiEntities(documents, "en");
258
+ const results = await client.analyze("PiiEntityRecognition", documents, "en");
267
259
  for (const result of results) {
268
260
  if (result.error === undefined) {
269
261
  console.log(" -- Recognized PII entities for input", result.id, "--");
@@ -278,23 +270,23 @@ async function main() {
278
270
  main();
279
271
  ```
280
272
 
281
- ### Recognize Linked Entities
273
+ ### Entity Linking
282
274
 
283
- A "Linked" entity is one that exists in a knowledge base (such as Wikipedia). The `recognizeLinkedEntities` operation can disambiguate entities by determining which entry in a knowledge base they likely refer to (for example, in a piece of text, does the word "Mars" refer to the planet, or to the Roman god of war). Linked entities contain associated URLs to the knowledge base that provides the definition of the entity.
275
+ A "Linked" entity is one that exists in a knowledge base (such as Wikipedia). The `EntityLinking` action can disambiguate entities by determining which entry in a knowledge base they likely refer to (for example, in a piece of text, does the word "Mars" refer to the planet, or to the Roman god of war). Linked entities contain associated URLs to the knowledge base that provides the definition of the entity.
284
276
 
285
277
  ```javascript
286
- const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
278
+ const { TextAnalysisClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
287
279
 
288
- const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
280
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
289
281
 
290
282
  const documents = [
291
283
  "Microsoft was founded by Bill Gates and Paul Allen.",
292
284
  "Easter Island, a Chilean territory, is a remote volcanic island in Polynesia.",
293
- "I use Azure Functions to develop my product."
285
+ "I use Azure Functions to develop my product.",
294
286
  ];
295
287
 
296
288
  async function main() {
297
- const results = await client.recognizeLinkedEntities(documents, "en");
289
+ const results = await client.analyze("EntityLinking", documents, "en");
298
290
 
299
291
  for (const result of results) {
300
292
  if (result.error === undefined) {
@@ -320,23 +312,23 @@ async function main() {
320
312
  main();
321
313
  ```
322
314
 
323
- ### Extract Key Phrases
315
+ ### Key Phrase Extraction
324
316
 
325
317
  Key Phrase extraction identifies the main talking points in a document. For example, given input text "The food was delicious and there were wonderful staff", the service returns "food" and "wonderful staff".
326
318
 
327
319
  ```javascript
328
- const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
320
+ const { TextAnalysisClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
329
321
 
330
- const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
322
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
331
323
 
332
324
  const documents = [
333
325
  "Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle.",
334
326
  "I need to take my cat to the veterinarian.",
335
- "I will travel to South America in the summer."
327
+ "I will travel to South America in the summer.",
336
328
  ];
337
329
 
338
330
  async function main() {
339
- const results = await client.extractKeyPhrases(documents, "en");
331
+ const results = await client.analyze("KeyPhraseExtraction", documents, "en");
340
332
 
341
333
  for (const result of results) {
342
334
  if (result.error === undefined) {
@@ -351,25 +343,25 @@ async function main() {
351
343
  main();
352
344
  ```
353
345
 
354
- ### Detect Language
346
+ ### Language Detection
355
347
 
356
348
  Determine the language of a piece of text.
357
349
 
358
- The `countryHint` parameter is optional, but can assist the service in providing correct output if the country of origin is known. If provided, it should be set to an ISO-3166 Alpha-2 two-letter country code (such as "us" for the United States or "jp" for Japan) or to the value `"none"`. If the parameter is not provided, then the default `"us"` (United States) model will be used. If you do not know the country of origin of the document, then the parameter `"none"` should be used, and the Text Analytics service will apply a model that is tuned for an unknown country of origin.
350
+ The `countryHint` parameter is optional, but can assist the service in providing correct output if the country of origin is known. If provided, it should be set to an ISO-3166 Alpha-2 two-letter country code (such as "us" for the United States or "jp" for Japan) or to the value `"none"`. If the parameter is not provided, then the default `"us"` (United States) model will be used. If you do not know the country of origin of the document, then the parameter `"none"` should be used, and the Language service will apply a model that is tuned for an unknown country of origin.
359
351
 
360
352
  ```javascript
361
- const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
353
+ const { TextAnalysisClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
362
354
 
363
- const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
355
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
364
356
 
365
357
  const documents = [
366
358
  "This is written in English.",
367
359
  "Il documento scritto in italiano.",
368
- "Dies ist in deutscher Sprache verfasst."
360
+ "Dies ist in deutscher Sprache verfasst.",
369
361
  ];
370
362
 
371
363
  async function main() {
372
- const results = await client.detectLanguage(documents, "none");
364
+ const results = await client.analyze("LanguageDetection", documents, "none");
373
365
 
374
366
  for (const result of results) {
375
367
  if (result.error === undefined) {
@@ -394,105 +386,356 @@ async function main() {
394
386
  main();
395
387
  ```
396
388
 
397
- ### Analyze Healthcare Entities
389
+ ### Healthcare Analysis
398
390
 
399
391
  Healthcare analysis identifies healthcare entities. For example, given input text "Prescribed 100mg ibuprofen, taken twice daily", the service returns "100mg" categorized as Dosage, "ibuprofen" as MedicationName, and "twice daily" as Frequency.
400
392
 
401
393
  ```javascript
402
- const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
394
+ const {
395
+ AnalyzeBatchAction,
396
+ AzureKeyCredential,
397
+ TextAnalysisClient,
398
+ } = require("@azure/ai-text-analytics");
399
+
400
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
401
+
402
+ const documents = [
403
+ "Prescribed 100mg ibuprofen, taken twice daily.",
404
+ "Patient does not suffer from high blood pressure.",
405
+ ];
406
+
407
+ async function main() {
408
+ const actions: AnalyzeBatchAction[] = [
409
+ {
410
+ kind: "Healthcare",
411
+ },
412
+ ];
413
+ const poller = await client.beginAnalyzeBatch(actions, documents, "en");
414
+ const results = await poller.pollUntilDone();
415
+ for await (const actionResult of results) {
416
+ if (actionResult.kind !== "Healthcare") {
417
+ throw new Error(`Expected a healthcare results but got: ${actionResult.kind}`);
418
+ }
419
+ if (actionResult.error) {
420
+ const { code, message } = actionResult.error;
421
+ throw new Error(`Unexpected error (${code}): ${message}`);
422
+ }
423
+ for (const result of actionResult.results) {
424
+ console.log(`- Document ${result.id}`);
425
+ if (result.error) {
426
+ const { code, message } = result.error;
427
+ throw new Error(`Unexpected error (${code}): ${message}`);
428
+ }
429
+ console.log("\tRecognized Entities:");
430
+ for (const entity of result.entities) {
431
+ console.log(`\t- Entity "${entity.text}" of type ${entity.category}`);
432
+ if (entity.dataSources.length > 0) {
433
+ console.log("\t and it can be referenced in the following data sources:");
434
+ for (const ds of entity.dataSources) {
435
+ console.log(`\t\t- ${ds.name} with Entity ID: ${ds.entityId}`);
436
+ }
437
+ }
438
+ }
439
+ }
440
+ }
441
+ }
442
+
443
+ main();
444
+ ```
445
+
446
+ ### Extractive Summarization
447
+
448
+ Extractive summarization identifies sentences that summarize the article they belong to.
449
+
450
+ ```javascript
451
+ const {
452
+ AnalyzeBatchAction,
453
+ AzureKeyCredential,
454
+ TextAnalysisClient,
455
+ } = require("@azure/ai-text-analytics");
403
456
 
404
- const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
457
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
405
458
 
406
459
  const documents = [
407
460
  "Prescribed 100mg ibuprofen, taken twice daily.",
408
- "Patient does not suffer from high blood pressure."
461
+ "Patient does not suffer from high blood pressure.",
409
462
  ];
410
463
 
411
464
  async function main() {
412
- const poller = await client.beginAnalyzeHealthcareEntities(documents);
465
+ const actions: AnalyzeBatchAction[] = [
466
+ {
467
+ kind: "ExtractiveSummarization",
468
+ maxSentenceCount: 2,
469
+ },
470
+ ];
471
+ const poller = await client.beginAnalyzeBatch(actions, documents, "en");
413
472
  const results = await poller.pollUntilDone();
414
473
 
415
- for await (const result of results) {
416
- console.log(`- Document ${result.id}`);
417
- if (!result.error) {
474
+ for await (const actionResult of results) {
475
+ if (actionResult.kind !== "ExtractiveSummarization") {
476
+ throw new Error(`Expected extractive summarization results but got: ${actionResult.kind}`);
477
+ }
478
+ if (actionResult.error) {
479
+ const { code, message } = actionResult.error;
480
+ throw new Error(`Unexpected error (${code}): ${message}`);
481
+ }
482
+ for (const result of actionResult.results) {
483
+ console.log(`- Document ${result.id}`);
484
+ if (result.error) {
485
+ const { code, message } = result.error;
486
+ throw new Error(`Unexpected error (${code}): ${message}`);
487
+ }
488
+ console.log("Summary:");
489
+ console.log(result.sentences.map((sentence) => sentence.text).join("\n"));
490
+ }
491
+ }
492
+ }
493
+
494
+ main();
495
+ ```
496
+
497
+ ### Custom Entity Recognition
498
+
499
+ Recognize and categorize entities in text as entities using custom entity detection models built using [Azure Language Studio][lang_studio].
500
+
501
+ ```javascript
502
+ const {
503
+ AnalyzeBatchAction,
504
+ AzureKeyCredential,
505
+ TextAnalysisClient,
506
+ } = require("@azure/ai-text-analytics");
507
+
508
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
509
+
510
+ const documents = [
511
+ "We love this trail and make the trip every year. The views are breathtaking and well worth the hike! Yesterday was foggy though, so we missed the spectacular views. We tried again today and it was amazing. Everyone in my family liked the trail although it was too challenging for the less athletic among us.",
512
+ "Last week we stayed at Hotel Foo to celebrate our anniversary. The staff knew about our anniversary so they helped me organize a little surprise for my partner. The room was clean and with the decoration I requested. It was perfect!",
513
+ ];
514
+
515
+ async function main() {
516
+ const actions: AnalyzeBatchAction[] = [
517
+ {
518
+ kind: "CustomEntityRecognition",
519
+ deploymentName,
520
+ projectName,
521
+ },
522
+ ];
523
+ const poller = await client.beginAnalyzeBatch(actions, documents, "en");
524
+ for await (const actionResult of results) {
525
+ if (actionResult.kind !== "CustomEntityRecognition") {
526
+ throw new Error(`Expected a CustomEntityRecognition results but got: ${actionResult.kind}`);
527
+ }
528
+ if (actionResult.error) {
529
+ const { code, message } = actionResult.error;
530
+ throw new Error(`Unexpected error (${code}): ${message}`);
531
+ }
532
+ for (const result of actionResult.results) {
533
+ console.log(`- Document ${result.id}`);
534
+ if (result.error) {
535
+ const { code, message } = result.error;
536
+ throw new Error(`Unexpected error (${code}): ${message}`);
537
+ }
418
538
  console.log("\tRecognized Entities:");
419
539
  for (const entity of result.entities) {
420
- console.log(`\t- Entity ${entity.text} of type ${entity.category}`);
540
+ console.log(`\t- Entity "${entity.text}" of type ${entity.category}`);
541
+ }
542
+ }
543
+ }
544
+ }
545
+
546
+ main();
547
+ ```
548
+
549
+ ### Custom Single-label Classification
550
+
551
+ Classify documents using custom single-label models built using [Azure Language Studio][lang_studio].
552
+
553
+ ```javascript
554
+ const { TextAnalysisClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
555
+
556
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
557
+
558
+ const documents = [
559
+ "The plot begins with a large group of characters where everyone thinks that the two main ones should be together but foolish things keep them apart. Misunderstandings, miscommunication, and confusion cause a series of humorous situations.",
560
+ ];
561
+
562
+ async function main() {
563
+ const actions: AnalyzeBatchAction[] = [
564
+ {
565
+ kind: "CustomSingleLabelClassification",
566
+ deploymentName,
567
+ projectName,
568
+ },
569
+ ];
570
+ const poller = await client.beginAnalyzeBatch(actions, documents, "en");
571
+ const results = await poller.pollUntilDone();
572
+
573
+ for await (const actionResult of results) {
574
+ if (actionResult.kind !== "CustomSingleLabelClassification") {
575
+ throw new Error(
576
+ `Expected a CustomSingleLabelClassification results but got: ${actionResult.kind}`
577
+ );
578
+ }
579
+ if (actionResult.error) {
580
+ const { code, message } = actionResult.error;
581
+ throw new Error(`Unexpected error (${code}): ${message}`);
582
+ }
583
+ for (const result of actionResult.results) {
584
+ console.log(`- Document ${result.id}`);
585
+ if (result.error) {
586
+ const { code, message } = result.error;
587
+ throw new Error(`Unexpected error (${code}): ${message}`);
588
+ }
589
+ console.log(`\tClassification: ${result.classification.category}`);
590
+ }
591
+ }
592
+ }
593
+
594
+ main();
595
+ ```
596
+
597
+ ### Custom Multi-label Classification
598
+
599
+ Classify documents using custom multi-label models built using [Azure Language Studio][lang_studio].
600
+
601
+ ```javascript
602
+ const {
603
+ AnalyzeBatchAction,
604
+ AzureKeyCredential,
605
+ TextAnalysisClient,
606
+ } = require("@azure/ai-text-analytics");
607
+
608
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
609
+
610
+ const documents = [
611
+ "The plot begins with a large group of characters where everyone thinks that the two main ones should be together but foolish things keep them apart. Misunderstandings, miscommunication, and confusion cause a series of humorous situations.",
612
+ ];
613
+
614
+ async function main() {
615
+ const actions: AnalyzeBatchAction[] = [
616
+ {
617
+ kind: "CustomMultiLabelClassification",
618
+ deploymentName,
619
+ projectName,
620
+ },
621
+ ];
622
+ const poller = await client.beginAnalyzeBatch(actions, documents, "en");
623
+ const results = await poller.pollUntilDone();
624
+
625
+ for await (const actionResult of results) {
626
+ if (actionResult.kind !== "CustomMultiLabelClassification") {
627
+ throw new Error(
628
+ `Expected a CustomMultiLabelClassification results but got: ${actionResult.kind}`
629
+ );
630
+ }
631
+ if (actionResult.error) {
632
+ const { code, message } = actionResult.error;
633
+ throw new Error(`Unexpected error (${code}): ${message}`);
634
+ }
635
+ for (const result of actionResult.results) {
636
+ console.log(`- Document ${result.id}`);
637
+ if (result.error) {
638
+ const { code, message } = result.error;
639
+ throw new Error(`Unexpected error (${code}): ${message}`);
640
+ }
641
+ console.log(`\tClassification:`);
642
+ for (const classification of result.classifications) {
643
+ console.log(`\t\t-category: ${classification.category}`);
421
644
  }
422
- } else console.error("\tError:", result.error);
645
+ }
423
646
  }
424
647
  }
425
648
 
426
649
  main();
427
650
  ```
428
651
 
429
- ### Analyze Actions
652
+ ### Action Batching
430
653
 
431
- Analyze actions enables the application of multiple analyses (named actions) at once.
654
+ Applies multiple actions on each input document in one service request.
432
655
 
433
656
  ```javascript
434
- const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
657
+ const {
658
+ AnalyzeBatchAction,
659
+ AzureKeyCredential,
660
+ TextAnalysisClient,
661
+ } = require("@azure/ai-text-analytics");
435
662
 
436
- const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
663
+ const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
437
664
 
438
665
  const documents = [
439
666
  "Microsoft was founded by Bill Gates and Paul Allen.",
440
667
  "The employee's SSN is 555-55-5555.",
441
668
  "Easter Island, a Chilean territory, is a remote volcanic island in Polynesia.",
442
- "I use Azure Functions to develop my product."
669
+ "I use Azure Functions to develop my product.",
443
670
  ];
444
671
 
445
672
  async function main() {
446
- const actions = {
447
- recognizeEntitiesActions: [{ modelVersion: "latest" }],
448
- recognizePiiEntitiesActions: [{ modelVersion: "latest" }],
449
- extractKeyPhrasesActions: [{ modelVersion: "latest" }]
450
- };
451
- const poller = await client.beginAnalyzeActions(documents, actions);
452
- const resultPages = await poller.pollUntilDone();
453
- for await (const page of resultPages) {
454
- const keyPhrasesAction = page.extractKeyPhrasesResults[0];
455
- if (!keyPhrasesAction.error) {
456
- for (const doc of keyPhrasesAction.results) {
457
- console.log(`- Document ${doc.id}`);
458
- if (!doc.error) {
459
- console.log("\tKey phrases:");
460
- for (const phrase of doc.keyPhrases) {
461
- console.log(`\t- ${phrase}`);
673
+ const actions: AnalyzeBatchAction[] = [
674
+ {
675
+ kind: "EntityRecognition",
676
+ modelVersion: "latest",
677
+ },
678
+ {
679
+ kind: "PiiEntityRecognition",
680
+ modelVersion: "latest",
681
+ },
682
+ {
683
+ kind: "KeyPhraseExtraction",
684
+ modelVersion: "latest",
685
+ },
686
+ ];
687
+ const poller = await client.beginAnalyzeBatch(actions, documents, "en");
688
+ const actionResults = await poller.pollUntilDone();
689
+ for await (const actionResult of actionResults) {
690
+ if (actionResult.error) {
691
+ const { code, message } = actionResult.error;
692
+ throw new Error(`Unexpected error (${code}): ${message}`);
693
+ }
694
+ switch (actionResult.kind) {
695
+ case "KeyPhraseExtraction": {
696
+ for (const doc of actionResult.results) {
697
+ console.log(`- Document ${doc.id}`);
698
+ if (!doc.error) {
699
+ console.log("\tKey phrases:");
700
+ for (const phrase of doc.keyPhrases) {
701
+ console.log(`\t- ${phrase}`);
702
+ }
703
+ } else {
704
+ console.error("\tError:", doc.error);
462
705
  }
463
- } else {
464
- console.error("\tError:", doc.error);
465
706
  }
707
+ break;
466
708
  }
467
- }
468
-
469
- const entitiesAction = page.recognizeEntitiesResults[0];
470
- if (!entitiesAction.error) {
471
- for (const doc of entitiesAction.results) {
472
- console.log(`- Document ${doc.id}`);
473
- if (!doc.error) {
474
- console.log("\tEntities:");
475
- for (const entity of doc.entities) {
476
- console.log(`\t- Entity ${entity.text} of type ${entity.category}`);
709
+ case "EntityRecognition": {
710
+ for (const doc of actionResult.results) {
711
+ console.log(`- Document ${doc.id}`);
712
+ if (!doc.error) {
713
+ console.log("\tEntities:");
714
+ for (const entity of doc.entities) {
715
+ console.log(`\t- Entity ${entity.text} of type ${entity.category}`);
716
+ }
717
+ } else {
718
+ console.error("\tError:", doc.error);
477
719
  }
478
- } else {
479
- console.error("\tError:", doc.error);
480
720
  }
721
+ break;
481
722
  }
482
- }
483
-
484
- const piiEntitiesAction = page.recognizePiiEntitiesResults[0];
485
- if (!piiEntitiesAction.error) {
486
- for (const doc of piiEntitiesAction.results) {
487
- console.log(`- Document ${doc.id}`);
488
- if (!doc.error) {
489
- console.log("\tPii Entities:");
490
- for (const entity of doc.entities) {
491
- console.log(`\t- Entity ${entity.text} of type ${entity.category}`);
723
+ case "PiiEntityRecognition": {
724
+ for (const doc of actionResult.results) {
725
+ console.log(`- Document ${doc.id}`);
726
+ if (!doc.error) {
727
+ console.log("\tPii Entities:");
728
+ for (const entity of doc.entities) {
729
+ console.log(`\t- Entity ${entity.text} of type ${entity.category}`);
730
+ }
731
+ } else {
732
+ console.error("\tError:", doc.error);
492
733
  }
493
- } else {
494
- console.error("\tError:", doc.error);
495
734
  }
735
+ break;
736
+ }
737
+ default: {
738
+ throw new Error(`Unexpected action results: ${actionResult.kind}`);
496
739
  }
497
740
  }
498
741
  }
@@ -537,5 +780,6 @@ If you'd like to contribute to this library, please read the [contributing guide
537
780
  [cognitive_auth]: https://docs.microsoft.com/azure/cognitive-services/authentication
538
781
  [register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal
539
782
  [defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential
540
- [data_limits]: https://docs.microsoft.com/azure/cognitive-services/text-analytics/overview#data-limits
541
- [analyze_sentiment_opinion_mining_sample]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/textanalytics/ai-text-analytics/samples/v5/typescript/src/analyzeSentimentWithOpinionMining.ts
783
+ [data_limits]: https://docs.microsoft.com/azure/cognitive-services/language-service/concepts/data-limits
784
+ [analyze_sentiment_opinion_mining_sample]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/textanalytics/ai-text-analytics/samples-dev/opinionMining.ts
785
+ [lang_studio]: https://docs.microsoft.com/azure/cognitive-services/language-service/language-studio