Skip to content

Commit cdc68c0

Browse files
[Text Analytics] Adding analyze and healthcare APIs (Azure#11375)
* adding analyze and health APIs * address feedback and streamline analyze * Adding a know issues section to README * improve samples * adding recordings * fix link errors * fix lint issues * no karma timeout * fix release date in changelog * increase karma timeout * Recorded browser #analyze tests * Recorded even more browser tests that were missing Co-authored-by: Will Temple <witemple@microsoft.com>
1 parent 1810528 commit cdc68c0

File tree

264 files changed

+40031
-1668
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

264 files changed

+40031
-1668
lines changed

sdk/textanalytics/ai-text-analytics/CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Release History
22

3-
## 5.1.0-beta.3 (Unreleased)
3+
## 5.1.0-beta.3 (2020-11-20)
44

5+
- We are now targeting the service's v3.1-preview.3 API as the default instead of v3.1-preview.2.
6+
- We now have added support for performing multiple analyses at once with the introduction of the `beginAnalyze` API.
7+
- We now have added support for the recognition of healthcare entities with the introduction of the `beginAnalyzeHealthcare` API.
58

69
## 5.1.0-beta.2 (2020-10-06)
710

@@ -18,7 +21,7 @@
1821

1922
## 5.0.1 (2020-08-18)
2023

21-
- Handles REST exceptions with code InvalidDocumentBatch in a way that maintains backward compatability.
24+
- Handles REST exceptions with code InvalidDocumentBatch in a way that maintains backward compatibility.
2225

2326
## 5.0.0 (2020-07-27)
2427

sdk/textanalytics/ai-text-analytics/README.md

Lines changed: 126 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@
22

33
[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 six main functions:
44

5-
__Note:__ This SDK targets Azure Text Analytics service API version 3.1.0-preview.2.
5+
**Note:** This SDK targets Azure Text Analytics service API version 3.1.0-preview.2.
66

77
- Language Detection
88
- Sentiment Analysis
99
- Key Phrase Extraction
1010
- Named Entity Recognition
1111
- Recognition of Personally Identifiable Information
1212
- Linked Entity Recognition
13+
- Healthcare Analysis
14+
- Batch Processing
1315

1416
Use the client library to:
1517

1618
- Detect what language input text is written in.
1719
- Determine what customers think of your brand or topic by analyzing raw text for clues about positive or negative sentiment.
1820
- Automatically extract key phrases to quickly identify the main points.
19-
- Identify and categorize entities in your text as people, places, organizations, date/time, quantities, percentages, currencies, and more.
21+
- Identify and categorize entities in your text as people, places, organizations, date/time, quantities, percentages, currencies, healthcare specific, and more.
22+
- Perform multiple of the above tasks at once.
2023

2124
[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/textanalytics/ai-text-analytics/) |
2225
[Package (NPM)](https://www.npmjs.com/package/@azure/ai-text-analytics) |
@@ -113,7 +116,7 @@ For example, each document can be passed as a string in an array, e.g.
113116
const documents = [
114117
"I hated the movie. It was so slow!",
115118
"The movie made it into my top ten favorites.",
116-
"What a great movie!",
119+
"What a great movie!"
117120
];
118121
```
119122

@@ -123,7 +126,7 @@ or, if you wish to pass in a per-item document `id` or `language`/`countryHint`,
123126
const textDocumentInputs = [
124127
{ id: "1", language: "en", text: "I hated the movie. It was so slow!" },
125128
{ id: "2", language: "en", text: "The movie made it into my top ten favorites." },
126-
{ id: "3", language: "en", text: "What a great movie!" },
129+
{ id: "3", language: "en", text: "What a great movie!" }
127130
];
128131
```
129132

@@ -186,7 +189,7 @@ const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<AP
186189
const documents = [
187190
"I did not like the restaurant. The food was too spicy.",
188191
"The restaurant was decorated beautifully. The atmosphere was unlike any other restaurant I've been to.",
189-
"The food was yummy. :)",
192+
"The food was yummy. :)"
190193
];
191194

192195
async function main() {
@@ -221,7 +224,7 @@ const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<AP
221224
const documents = [
222225
"Microsoft was founded by Bill Gates and Paul Allen.",
223226
"Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle.",
224-
"Jeff bought three dozen eggs because there was a 50% discount.",
227+
"Jeff bought three dozen eggs because there was a 50% discount."
225228
];
226229

227230
async function main() {
@@ -284,7 +287,7 @@ const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<AP
284287
const documents = [
285288
"Microsoft was founded by Bill Gates and Paul Allen.",
286289
"Easter Island, a Chilean territory, is a remote volcanic island in Polynesia.",
287-
"I use Azure Functions to develop my product.",
290+
"I use Azure Functions to develop my product."
288291
];
289292

290293
async function main() {
@@ -296,7 +299,13 @@ async function main() {
296299
for (const entity of result.entities) {
297300
console.log(entity.name, "(URL:", entity.url, ", Source:", entity.dataSource, ")");
298301
for (const match of entity.matches) {
299-
console.log(" Occurrence:", "\"" + match.text + "\"", "(Score:", match.confidenceScore, ")");
302+
console.log(
303+
" Occurrence:",
304+
'"' + match.text + '"',
305+
"(Score:",
306+
match.confidenceScore,
307+
")"
308+
);
300309
}
301310
}
302311
} else {
@@ -320,7 +329,7 @@ const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<AP
320329
const documents = [
321330
"Redmond is a city in King County, Washington, United States, located 15 miles east of Seattle.",
322331
"I need to take my cat to the veterinarian.",
323-
"I will travel to South America in the summer.",
332+
"I will travel to South America in the summer."
324333
];
325334

326335
async function main() {
@@ -382,6 +391,113 @@ async function main() {
382391
main();
383392
```
384393

394+
### Analyze Healthcare Entities
395+
396+
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.
397+
398+
```javascript
399+
const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
400+
401+
const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
402+
403+
const documents = [
404+
"Prescribed 100mg ibuprofen, taken twice daily.",
405+
"Patient does not suffer from high blood pressure."
406+
];
407+
408+
async function main() {
409+
const poller = await client.beginAnalyzeHealthcare(documents);
410+
const results = await poller.pollUntilDone();
411+
412+
for await (const result of results) {
413+
console.log(`- Document ${result.id}`);
414+
if (!result.error) {
415+
console.log("\tRecognized Entities:");
416+
for (const entity of result.entities) {
417+
console.log(`\t- Entity ${entity.text} of type ${entity.category}`);
418+
}
419+
} else console.error("\tError:", result.error);
420+
}
421+
}
422+
423+
main();
424+
```
425+
426+
### Analyze
427+
428+
Analyze enables the application of multiple analyses at once.
429+
430+
```javascript
431+
const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
432+
433+
const client = new TextAnalyticsClient("<endpoint>", new AzureKeyCredential("<API key>"));
434+
435+
const documents = [
436+
"Microsoft was founded by Bill Gates and Paul Allen.",
437+
"The employee's SSN is 555-55-5555.",
438+
"Easter Island, a Chilean territory, is a remote volcanic island in Polynesia.",
439+
"I use Azure Functions to develop my product."
440+
];
441+
442+
async function main() {
443+
const tasks = {
444+
entityRecognitionTasks: [{ modelVersion: "latest" }],
445+
entityRecognitionPiiTasks: [{ modelVersion: "latest" }],
446+
keyPhraseExtractionTasks: [{ modelVersion: "latest" }]
447+
};
448+
const poller = await client.beginAnalyze(documents, tasks);
449+
const resultPages = await poller.pollUntilDone();
450+
451+
for await (const page of resultPages) {
452+
const keyPhrasesResults = page.keyPhrasesExtractionResults[0];
453+
for (const doc of keyPhrasesResults) {
454+
console.log(`- Document ${doc.id}`);
455+
if (!doc.error) {
456+
console.log("\tKey phrases:");
457+
for (const phrase of doc.keyPhrases) {
458+
console.log(`\t- ${phrase}`);
459+
}
460+
} else {
461+
console.error("\tError:", doc.error);
462+
}
463+
}
464+
465+
const entitiesResults = page.entitiesRecognitionResults[0];
466+
for (const doc of entitiesResults) {
467+
console.log(`- Document ${doc.id}`);
468+
if (!doc.error) {
469+
console.log("\tEntities:");
470+
for (const entity of doc.entities) {
471+
console.log(`\t- Entity ${entity.text} of type ${entity.category}`);
472+
}
473+
} else {
474+
console.error("\tError:", doc.error);
475+
}
476+
}
477+
478+
const piiEntitiesResults = page.piiEntitiesRecognitionResults[0];
479+
for (const doc of piiEntitiesResults) {
480+
console.log(`- Document ${doc.id}`);
481+
if (!doc.error) {
482+
console.log("\tPii Entities:");
483+
for (const entity of doc.entities) {
484+
console.log(`\t- Entity ${entity.text} of type ${entity.category}`);
485+
}
486+
} else {
487+
console.error("\tError:", doc.error);
488+
}
489+
}
490+
}
491+
}
492+
493+
main();
494+
```
495+
496+
## Known Issues
497+
498+
- Currently, the `beginAnalyze` API accepts `includeStatistics` in its options bag, a feature that was not yet supported by the service at the time of the current release. This feature is expected to be supported soon after the release.
499+
- `beginAnalyzeHealthcare` is still in gated preview and can not be used with AAD credentials.
500+
385501
## Troubleshooting
386502

387503
### Enable logs
@@ -421,4 +537,4 @@ If you'd like to contribute to this library, please read the [contributing guide
421537
[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal
422538
[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential
423539
[data_limits]: https://docs.microsoft.com/azure/cognitive-services/text-analytics/overview#data-limits
424-
[analyze_sentiment_opinion_mining_sample]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/textanalytics/ai-text-analytics/samples/typescript/src/analyzeSentimentWithOpinionMining.ts
540+
[analyze_sentiment_opinion_mining_sample]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/textanalytics/ai-text-analytics/samples/typescript/src/analyzeSentimentWithOpinionMining.ts

sdk/textanalytics/ai-text-analytics/karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ module.exports = function(config) {
132132
// how many browser should be started simultaneous
133133
concurrency: 1,
134134

135-
browserNoActivityTimeout: 600000,
135+
browserNoActivityTimeout: 60000000,
136136
browserDisconnectTimeout: 10000,
137137
browserDisconnectTolerance: 3,
138138
browserConsoleLogOptions: {
@@ -143,7 +143,7 @@ module.exports = function(config) {
143143
mocha: {
144144
// change Karma's debug.html to the mocha web reporter
145145
reporter: "html",
146-
timeout: "600000"
146+
timeout: 0
147147
}
148148
}
149149
});

sdk/textanalytics/ai-text-analytics/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
"//smokeTestConfiguration": {
4747
"skipFolder": true
4848
},
49+
"browser": {
50+
"./dist-esm/src/utils/url.js": "./dist-esm/src/utils/url.browser.js"
51+
},
4952
"scripts": {
5053
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
5154
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
@@ -78,6 +81,8 @@
7881
"dependencies": {
7982
"@azure/core-auth": "^1.1.3",
8083
"@azure/core-http": "^1.2.0",
84+
"@azure/core-lro": "^1.0.2",
85+
"@azure/core-paging": "^1.1.1",
8186
"@azure/core-tracing": "1.0.0-preview.9",
8287
"@azure/logger": "^1.0.0",
8388
"@opentelemetry/api": "^0.10.2",

sdk/textanalytics/ai-text-analytics/recordings/browsers/aad_textanalyticsclient_analyze/recording_bad_request_empty_string.json

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)