@azure/ai-language-text 1.0.1-alpha.20221014.1 → 1.1.0-alpha.20221102.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.
- package/README.md +132 -17
- package/dist/index.js +1741 -376
- package/dist/index.js.map +1 -1
- package/dist-esm/src/constants.js +1 -1
- package/dist-esm/src/constants.js.map +1 -1
- package/dist-esm/src/generated/generatedClient.js +2 -19
- package/dist-esm/src/generated/generatedClient.js.map +1 -1
- package/dist-esm/src/generated/models/index.js +454 -0
- package/dist-esm/src/generated/models/index.js.map +1 -1
- package/dist-esm/src/generated/models/mappers.js +1118 -265
- package/dist-esm/src/generated/models/mappers.js.map +1 -1
- package/dist-esm/src/generated/models/parameters.js +1 -1
- package/dist-esm/src/generated/models/parameters.js.map +1 -1
- package/dist-esm/src/index.js +1 -1
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/models.js +11 -0
- package/dist-esm/src/models.js.map +1 -1
- package/dist-esm/src/textAnalysisClient.js +3 -2
- package/dist-esm/src/textAnalysisClient.js.map +1 -1
- package/dist-esm/src/transforms.js +24 -3
- package/dist-esm/src/transforms.js.map +1 -1
- package/package.json +1 -1
- package/types/ai-language-text.d.ts +1219 -5
package/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
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 Cognitive Service for Language API version 2022-
|
5
|
+
**Note:** This SDK targets Azure Cognitive Service for Language API version 2022-10-01-preview.
|
6
6
|
|
7
7
|
- Language Detection
|
8
8
|
- Sentiment Analysis
|
@@ -11,8 +11,11 @@
|
|
11
11
|
- Recognition of Personally Identifiable Information
|
12
12
|
- Entity Linking
|
13
13
|
- Healthcare Analysis
|
14
|
+
- Extractive Summarization
|
15
|
+
- Abstractive Summarization
|
14
16
|
- Custom Entity Recognition
|
15
17
|
- Custom Document Classification
|
18
|
+
- Dynamic Classification
|
16
19
|
- Support Multiple Actions Per Document
|
17
20
|
|
18
21
|
Use the client library to:
|
@@ -389,15 +392,48 @@ async function main() {
|
|
389
392
|
main();
|
390
393
|
```
|
391
394
|
|
395
|
+
### Dynamic Classification
|
396
|
+
|
397
|
+
On the fly classification of the input documents into one or multiple categories. Assigns either one or multiple categories per document. This type of classification doesn't require model training.
|
398
|
+
|
399
|
+
```javascript
|
400
|
+
const { TextAnalysisClient, AzureKeyCredential } = require("@azure/ai-language-text");
|
401
|
+
|
402
|
+
const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
|
403
|
+
|
404
|
+
const documents = [
|
405
|
+
"The WHO is issuing a warning about Monkey Pox.",
|
406
|
+
"Mo Salah plays in Liverpool FC in England.",
|
407
|
+
];
|
408
|
+
|
409
|
+
export async function main() {
|
410
|
+
const results = await client.analyze("DynamicClassification", documents, "en", {
|
411
|
+
categories: ["Health", "Politics", "Music", "Sports"],
|
412
|
+
classificationType: "Multi",
|
413
|
+
});
|
414
|
+
|
415
|
+
for (const result of results) {
|
416
|
+
console.log(`- Document ${result.id}`);
|
417
|
+
if (!result.error) {
|
418
|
+
console.log("\tClassifications:");
|
419
|
+
for (const category of result.classifications) {
|
420
|
+
console.log(`\t- ${category.category}`);
|
421
|
+
}
|
422
|
+
} else {
|
423
|
+
console.error(" Error:", result.error);
|
424
|
+
}
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
main();
|
429
|
+
```
|
430
|
+
|
392
431
|
### Healthcare Analysis
|
393
432
|
|
394
433
|
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.
|
395
434
|
|
396
435
|
```javascript
|
397
|
-
const {
|
398
|
-
AzureKeyCredential,
|
399
|
-
TextAnalysisClient,
|
400
|
-
} = require("@azure/ai-language-text");
|
436
|
+
const { AzureKeyCredential, TextAnalysisClient } = require("@azure/ai-language-text");
|
401
437
|
|
402
438
|
const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
|
403
439
|
|
@@ -414,6 +450,7 @@ async function main() {
|
|
414
450
|
];
|
415
451
|
const poller = await client.beginAnalyzeBatch(actions, documents, "en");
|
416
452
|
const results = await poller.pollUntilDone();
|
453
|
+
|
417
454
|
for await (const actionResult of results) {
|
418
455
|
if (actionResult.kind !== "Healthcare") {
|
419
456
|
throw new Error(`Expected a healthcare results but got: ${actionResult.kind}`);
|
@@ -445,15 +482,98 @@ async function main() {
|
|
445
482
|
main();
|
446
483
|
```
|
447
484
|
|
485
|
+
### Extractive Summarization
|
486
|
+
|
487
|
+
Extractive summarization identifies sentences that summarize the article they belong to.
|
488
|
+
|
489
|
+
```javascript
|
490
|
+
const { AzureKeyCredential, TextAnalysisClient } = require("@azure/ai-language-text");
|
491
|
+
const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
|
492
|
+
const documents = [
|
493
|
+
"<long article>"
|
494
|
+
];
|
495
|
+
async function main() {
|
496
|
+
const actions = [
|
497
|
+
{
|
498
|
+
kind: "ExtractiveSummarization",
|
499
|
+
maxSentenceCount: 2,
|
500
|
+
},
|
501
|
+
];
|
502
|
+
const poller = await client.beginAnalyzeBatch(actions, documents, "en");
|
503
|
+
const results = await poller.pollUntilDone();
|
504
|
+
|
505
|
+
for await (const actionResult of results) {
|
506
|
+
if (actionResult.kind !== "ExtractiveSummarization") {
|
507
|
+
throw new Error(`Expected extractive summarization results but got: ${actionResult.kind}`);
|
508
|
+
}
|
509
|
+
if (actionResult.error) {
|
510
|
+
const { code, message } = actionResult.error;
|
511
|
+
throw new Error(`Unexpected error (${code}): ${message}`);
|
512
|
+
}
|
513
|
+
for (const result of actionResult.results) {
|
514
|
+
console.log(`- Document ${result.id}`);
|
515
|
+
if (result.error) {
|
516
|
+
const { code, message } = result.error;
|
517
|
+
throw new Error(`Unexpected error (${code}): ${message}`);
|
518
|
+
}
|
519
|
+
console.log("Summary:");
|
520
|
+
console.log(result.sentences.map((sentence) => sentence.text).join("\n"));
|
521
|
+
}
|
522
|
+
}
|
523
|
+
}
|
524
|
+
main();
|
525
|
+
```
|
526
|
+
|
527
|
+
### Abstractive Summarization
|
528
|
+
|
529
|
+
Abstractive summarization generates a summary for the input articles. Abstractive summarization is different from extractive summarization in that extractive summarization is the strategy of concatenating extracted sentences from the input document into a summary, while abstractive summarization involves paraphrasing the document using novel sentences.
|
530
|
+
|
531
|
+
```javascript
|
532
|
+
const { AzureKeyCredential, TextAnalysisClient } = require("@azure/ai-language-text");
|
533
|
+
const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
|
534
|
+
const documents = [
|
535
|
+
"<long article>"
|
536
|
+
];
|
537
|
+
async function main() {
|
538
|
+
const actions = [
|
539
|
+
{
|
540
|
+
kind: "AbstractiveSummarization",
|
541
|
+
maxSentenceCount: 2,
|
542
|
+
},
|
543
|
+
];
|
544
|
+
const poller = await client.beginAnalyzeBatch(actions, documents, "en");
|
545
|
+
const results = await poller.pollUntilDone();
|
546
|
+
|
547
|
+
for await (const actionResult of results) {
|
548
|
+
if (actionResult.kind !== "AbstractiveSummarization") {
|
549
|
+
throw new Error(`Expected abstractive summarization results but got: ${actionResult.kind}`);
|
550
|
+
}
|
551
|
+
if (actionResult.error) {
|
552
|
+
const { code, message } = actionResult.error;
|
553
|
+
throw new Error(`Unexpected error (${code}): ${message}`);
|
554
|
+
}
|
555
|
+
for (const result of actionResult.results) {
|
556
|
+
console.log(`- Document ${result.id}`);
|
557
|
+
if (result.error) {
|
558
|
+
const { code, message } = result.error;
|
559
|
+
throw new Error(`Unexpected error (${code}): ${message}`);
|
560
|
+
}
|
561
|
+
console.log("\t- Summary:");
|
562
|
+
for (const summary of result.summaries) {
|
563
|
+
console.log(summary.text);
|
564
|
+
}
|
565
|
+
}
|
566
|
+
}
|
567
|
+
}
|
568
|
+
main();
|
569
|
+
```
|
570
|
+
|
448
571
|
### Custom Entity Recognition
|
449
572
|
|
450
573
|
Recognize and categorize entities in text as entities using custom entity detection models built using [Azure Language Studio][lang_studio].
|
451
574
|
|
452
575
|
```javascript
|
453
|
-
const {
|
454
|
-
AzureKeyCredential,
|
455
|
-
TextAnalysisClient,
|
456
|
-
} = require("@azure/ai-language-text");
|
576
|
+
const { AzureKeyCredential, TextAnalysisClient } = require("@azure/ai-language-text");
|
457
577
|
|
458
578
|
const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
|
459
579
|
|
@@ -551,10 +671,7 @@ main();
|
|
551
671
|
Classify documents using custom multi-label models built using [Azure Language Studio][lang_studio].
|
552
672
|
|
553
673
|
```javascript
|
554
|
-
const {
|
555
|
-
AzureKeyCredential,
|
556
|
-
TextAnalysisClient,
|
557
|
-
} = require("@azure/ai-language-text");
|
674
|
+
const { AzureKeyCredential, TextAnalysisClient } = require("@azure/ai-language-text");
|
558
675
|
|
559
676
|
const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
|
560
677
|
|
@@ -605,10 +722,7 @@ main();
|
|
605
722
|
Applies multiple actions on each input document in one service request.
|
606
723
|
|
607
724
|
```javascript
|
608
|
-
const {
|
609
|
-
AzureKeyCredential,
|
610
|
-
TextAnalysisClient,
|
611
|
-
} = require("@azure/ai-language-text");
|
725
|
+
const { AzureKeyCredential, TextAnalysisClient } = require("@azure/ai-language-text");
|
612
726
|
|
613
727
|
const client = new TextAnalysisClient("<endpoint>", new AzureKeyCredential("<API key>"));
|
614
728
|
|
@@ -636,6 +750,7 @@ async function main() {
|
|
636
750
|
];
|
637
751
|
const poller = await client.beginAnalyzeBatch(actions, documents, "en");
|
638
752
|
const actionResults = await poller.pollUntilDone();
|
753
|
+
|
639
754
|
for await (const actionResult of actionResults) {
|
640
755
|
if (actionResult.error) {
|
641
756
|
const { code, message } = actionResult.error;
|