Skip to content

Commit ce780db

Browse files
authored
Merge pull request #227205 from aahill/js-updates
[SCOPED] JS package and code updates
2 parents fc4bd7a + f7c1659 commit ce780db

File tree

14 files changed

+359
-257
lines changed

14 files changed

+359
-257
lines changed

articles/cognitive-services/language-service/entity-linking/includes/quickstarts/nodejs-sdk.md

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ manager: nitinme
66
ms.service: cognitive-services
77
ms.subservice: language-service
88
ms.topic: include
9-
ms.date: 12/12/2022
9+
ms.date: 02/13/2023
1010
ms.author: aahi
1111
ms.custom: devx-track-js, ignite-fall-2021
1212
---
1313

14-
[Reference documentation](/javascript/api/overview/azure/ai-text-analytics-readme?preserve-view=true&view=azure-node-latest) | [Additional samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/textanalytics/ai-text-analytics/samples) | [Package (npm)](https://www.npmjs.com/package/@azure/ai-text-analytics/v/5.1.0) | [Library source code](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/textanalytics/ai-text-analytics)
14+
[Reference documentation](/javascript/api/overview/azure/ai-language-text-readme?view=azure-node-latest) | [Additional samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/cognitivelanguage/ai-language-text/samples/v1) | [Package (npm)](https://www.npmjs.com/package/@azure/ai-language-text) | [Library source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/cognitivelanguage/ai-language-text)
1515

1616
Use this quickstart to create an entity linking application with the client library for Node.js. In the following example, you will create a JavaScript application that can identify and disambiguate entities found in text.
1717

@@ -53,7 +53,7 @@ npm init
5353
Install the npm package:
5454

5555
```console
56-
npm install @azure/ai-[email protected]
56+
npm install @azure/ai-language-text
5757
```
5858

5959
> [!div class="nextstepaction"]
@@ -68,32 +68,45 @@ Open the file and copy the below code. Remember to replace the `key` variable wi
6868
```javascript
6969
"use strict";
7070

71-
const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
71+
const { TextAnalysisClient, AzureKeyCredential } = require("@azure/ai-language-text");
7272
const endpoint = '<paste-your-endpoint-here>';
7373
const key = '<paste-your-key-here>';
74-
// Authenticate the client with your key and endpoint.
75-
const textAnalyticsClient = new TextAnalyticsClient(endpoint, new AzureKeyCredential(key));
76-
77-
// Example method for recognizing entities and providing a link to an online data source.
78-
async function linkedEntityRecognition(client){
79-
80-
const linkedEntityInput = [
81-
"Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975, to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman, chief executive officer, president and chief software architect, while also being the largest individual shareholder until May 2014."
82-
];
83-
const entityResults = await client.recognizeLinkedEntities(linkedEntityInput);
84-
85-
entityResults.forEach(document => {
86-
console.log(`Document ID: ${document.id}`);
87-
document.entities.forEach(entity => {
88-
console.log(`\tName: ${entity.name} \tID: ${entity.dataSourceEntityId} \tURL: ${entity.url} \tData Source: ${entity.dataSource}`);
89-
console.log(`\tMatches:`)
90-
entity.matches.forEach(match => {
91-
console.log(`\t\tText: ${match.text} \tScore: ${match.confidenceScore.toFixed(2)}`);
92-
})
93-
});
94-
});
95-
}
96-
linkedEntityRecognition(textAnalyticsClient);
74+
//example sentence for recognizing entities
75+
const documents = ["Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975."];
76+
77+
//example of how to use the client to perform entity linking on a document
78+
async function main() {
79+
console.log("== Entity linking sample ==");
80+
81+
const client = new TextAnalysisClient(endpoint, new AzureKeyCredential(key));
82+
83+
const results = await client.analyze("EntityLinking", documents);
84+
85+
for (const result of results) {
86+
console.log(`- Document ${result.id}`);
87+
if (!result.error) {
88+
console.log("\tEntities:");
89+
for (const entity of result.entities) {
90+
console.log(
91+
`\t- Entity ${entity.name}; link ${entity.url}; datasource: ${entity.dataSource}`
92+
);
93+
console.log("\t\tMatches:");
94+
for (const match of entity.matches) {
95+
console.log(
96+
`\t\t- Entity appears as "${match.text}" (confidence: ${match.confidenceScore}`
97+
);
98+
}
99+
}
100+
} else {
101+
console.error(" Error:", result.error);
102+
}
103+
}
104+
}
105+
106+
//call the main function
107+
main().catch((err) => {
108+
console.error("The sample encountered an error:", err);
109+
});
97110

98111
```
99112

@@ -103,27 +116,21 @@ linkedEntityRecognition(textAnalyticsClient);
103116
### Output
104117

105118
```console
106-
Document ID: 0
107-
Name: Altair 8800 ID: Altair 8800 URL: https://en.wikipedia.org/wiki/Altair_8800 Data Source: Wikipedia
108-
Matches:
109-
Text: Altair 8800 Score: 0.88
110-
Name: Bill Gates ID: Bill Gates URL: https://en.wikipedia.org/wiki/Bill_Gates Data Source: Wikipedia
111-
Matches:
112-
Text: Bill Gates Score: 0.63
113-
Text: Gates Score: 0.63
114-
Name: Paul Allen ID: Paul Allen URL: https://en.wikipedia.org/wiki/Paul_Allen Data Source: Wikipedia
115-
Matches:
116-
Text: Paul Allen Score: 0.60
117-
Name: Microsoft ID: Microsoft URL: https://en.wikipedia.org/wiki/Microsoft Data Source: Wikipedia
118-
Matches:
119-
Text: Microsoft Score: 0.55
120-
Text: Microsoft Score: 0.55
121-
Name: April 4 ID: April 4 URL: https://en.wikipedia.org/wiki/April_4 Data Source: Wikipedia
122-
Matches:
123-
Text: April 4 Score: 0.32
124-
Name: BASIC ID: BASIC URL: https://en.wikipedia.org/wiki/BASIC Data Source: Wikipedia
125-
Matches:
126-
Text: BASIC Score: 0.33
119+
== Entity linking sample ==
120+
- Document 0
121+
Entities:
122+
- Entity Microsoft; link https://en.wikipedia.org/wiki/Microsoft; datasource: Wikipedia
123+
Matches:
124+
- Entity appears as "Microsoft" (confidence: 0.48
125+
- Entity Bill Gates; link https://en.wikipedia.org/wiki/Bill_Gates; datasource: Wikipedia
126+
Matches:
127+
- Entity appears as "Bill Gates" (confidence: 0.52
128+
- Entity Paul Allen; link https://en.wikipedia.org/wiki/Paul_Allen; datasource: Wikipedia
129+
Matches:
130+
- Entity appears as "Paul Allen" (confidence: 0.54
131+
- Entity April 4; link https://en.wikipedia.org/wiki/April_4; datasource: Wikipedia
132+
Matches:
133+
- Entity appears as "April 4" (confidence: 0.38
127134
```
128135

129136
[!INCLUDE [clean up resources](../../../includes/clean-up-resources.md)]
@@ -135,5 +142,5 @@ Document ID: 0
135142

136143
* [Entity linking language support](../../language-support.md)
137144
* [How to call the entity linking API](../../how-to/call-api.md)
138-
* [Reference documentation](/javascript/api/overview/azure/ai-text-analytics-readme?preserve-view=true&view=azure-node-latest)
139-
* [Additional samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/textanalytics/ai-text-analytics/samples)
145+
* [Reference documentation](/javascript/api/overview/azure/ai-language-text-readme?view=azure-node-latest)
146+
* [Additional samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/cognitivelanguage/ai-language-text/samples/v1)

articles/cognitive-services/language-service/entity-linking/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: language-service
1010
ms.topic: quickstart
11-
ms.date: 12/12/2022
11+
ms.date: 02/13/2023
1212
ms.author: aahi
1313
ms.devlang: csharp, java, javascript, python
1414
ms.custom: language-service-entity-linking, ignite-fall-2021, mode-api

articles/cognitive-services/language-service/key-phrase-extraction/includes/quickstarts/nodejs-sdk.md

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ manager: nitinme
44
ms.service: cognitive-services
55
ms.subservice: language-service
66
ms.topic: include
7-
ms.date: 12/12/2022
7+
ms.date: 02/13/2023
88
ms.author: jboback
99
ms.custom: devx-track-js, ignite-fall-2021
1010
---
1111

12-
[Reference documentation](/javascript/api/overview/azure/ai-text-analytics-readme?preserve-view=true&view=azure-node-latest) | [Additional samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/textanalytics/ai-text-analytics/samples) | [Package (npm)](https://www.npmjs.com/package/@azure/ai-text-analytics/v/5.1.0) | [Library source code](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/textanalytics/ai-text-analytics)
12+
[Reference documentation](/javascript/api/overview/azure/ai-language-text-readme?view=azure-node-latest) | [Additional samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/cognitivelanguage/ai-language-text/samples/v1) | [Package (npm)](https://www.npmjs.com/package/@azure/ai-language-text) | [Library source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/cognitivelanguage/ai-language-text)
1313

1414
Use this quickstart to create a key phrase extraction application with the client library for Node.js. In the following example, you will create a JavaScript application that can identify key words and phrases found in text.
1515

@@ -50,7 +50,7 @@ npm init
5050
Install the npm package:
5151

5252
```console
53-
npm install --save @azure/ai-[email protected]
53+
npm install @azure/ai-language-text
5454
```
5555

5656
> [!div class="nextstepaction"]
@@ -67,33 +67,49 @@ Open the file and copy the below code. Remember to replace the `key` variable wi
6767
```javascript
6868
"use strict";
6969

70-
const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
70+
const { TextAnalysisClient, AzureKeyCredential } = require("@azure/ai-language-text");
7171
const key = '<paste-your-key-here>';
7272
const endpoint = '<paste-your-endpoint-here>';
73-
// Authenticate the client with your key and endpoint
74-
const textAnalyticsClient = new TextAnalyticsClient(endpoint, new AzureKeyCredential(key));
75-
76-
// Example method for extracting key phrases from text
77-
async function keyPhraseExtraction(client){
78-
79-
const keyPhrasesInput = [
80-
"Dr. Smith has a very modern medical office, and she has great staff.",
81-
];
82-
const keyPhraseResult = await client.extractKeyPhrases(keyPhrasesInput);
83-
84-
keyPhraseResult.forEach(document => {
85-
console.log(`ID: ${document.id}`);
86-
console.log(`\tDocument Key Phrases: ${document.keyPhrases}`);
87-
});
88-
}
89-
keyPhraseExtraction(textAnalyticsClient);
73+
74+
//example sentence for performing key phrase extraction
75+
const documents = ["Dr. Smith has a very modern medical office, and she has great staff."];
76+
77+
//example of how to use the client to perform entity linking on a document
78+
async function main() {
79+
console.log("== key phrase extraction sample ==");
80+
81+
const client = new TextAnalysisClient(endpoint, new AzureKeyCredential(key));
82+
83+
const results = await client.analyze("KeyPhraseExtraction", documents);
84+
85+
for (const result of results) {
86+
console.log(`- Document ${result.id}`);
87+
if (!result.error) {
88+
console.log("\tKey phrases:");
89+
for (const phrase of result.keyPhrases) {
90+
console.log(`\t- ${phrase}`);
91+
}
92+
} else {
93+
console.error(" Error:", result.error);
94+
}
95+
}
96+
}
97+
98+
main().catch((err) => {
99+
console.error("The sample encountered an error:", err);
100+
});
101+
90102
```
91103

92104
### Output
93105

94106
```console
95-
ID: 0
96-
Document Key Phrases: modern medical office,Dr. Smith,great staff
107+
== key phrase extraction sample ==
108+
- Document 0
109+
Key phrases:
110+
- modern medical office
111+
- Dr. Smith
112+
- great staff
97113
```
98114

99115
> [!div class="nextstepaction"]

articles/cognitive-services/language-service/key-phrase-extraction/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: language-service
1010
ms.topic: quickstart
11-
ms.date: 12/12/2022
11+
ms.date: 02/13/2023
1212
ms.author: jboback
1313
ms.devlang: csharp, java, javascript, python
1414
ms.custom: language-service-key-phrase, ignite-fall-2021, mode-api

articles/cognitive-services/language-service/language-detection/includes/quickstarts/nodejs-sdk.md

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.author: jboback
99
ms.custom: devx-track-js, ignite-fall-2021
1010
---
1111

12-
[Reference documentation](/javascript/api/overview/azure/ai-text-analytics-readme?preserve-view=true&view=azure-node-latest) | [Additional samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/textanalytics/ai-text-analytics/samples) | [Package (npm)](https://www.npmjs.com/package/@azure/ai-text-analytics/v/5.1.0) | [Library source code](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/textanalytics/ai-text-analytics)
12+
[Reference documentation](/javascript/api/overview/azure/ai-language-text-readme?view=azure-node-latest) | [Additional samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/cognitivelanguage/ai-language-text/samples/v1) | [Package (npm)](https://www.npmjs.com/package/@azure/ai-language-text) | [Library source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/cognitivelanguage/ai-language-text)
1313

1414

1515
Use this quickstart to create a language detection application with the client library for Node.js. In the following example, you will create a JavaScript application that can identify the language a text sample was written in.
@@ -52,7 +52,7 @@ npm init
5252
Install the npm package:
5353

5454
```console
55-
npm install --save @azure/ai-[email protected]
55+
npm install @azure/ai-language-text
5656
```
5757

5858
> [!div class="nextstepaction"]
@@ -67,26 +67,37 @@ Open the file and copy the below code. Remember to replace the `key` variable wi
6767
```javascript
6868
"use strict";
6969

70-
const { TextAnalyticsClient, AzureKeyCredential } = require("@azure/ai-text-analytics");
70+
const { TextAnalysisClient, AzureKeyCredential } = require("@azure/ai-language-text");
7171
const key = '<paste-your-key-here>';
7272
const endpoint = '<paste-your-endpoint-here>';
73-
// Authenticate the client with your key and endpoint
74-
const textAnalyticsClient = new TextAnalyticsClient(endpoint, new AzureKeyCredential(key));
7573

76-
// Example method for detecting the language of text
77-
async function languageDetection(client) {
78-
79-
const languageInputArray = [
80-
"Ce document est rédigé en Français."
81-
];
82-
const languageResult = await client.detectLanguage(languageInputArray);
83-
84-
languageResult.forEach(document => {
85-
console.log(`ID: ${document.id}`);
86-
console.log(`\tPrimary Language ${document.primaryLanguage.name}`)
87-
});
74+
//Example sentences in different languages to be analyzed
75+
const documents = [
76+
"This document is written in English.",
77+
"这是一个用中文写的文件",
78+
];
79+
80+
81+
//Example of how to use the client library to detect language
82+
async function main() {
83+
console.log("== Language detection sample ==");
84+
85+
const client = new TextAnalysisClient(endpoint, new AzureKeyCredential(key));
86+
87+
const result = await client.analyze("LanguageDetection", documents);
88+
89+
for (const doc of result) {
90+
if (!doc.error) {
91+
console.log(
92+
`ID ${doc.id} - Primary language: ${doc.primaryLanguage.name} (iso6391 name: ${doc.primaryLanguage.iso6391Name})`
93+
);
94+
}
95+
}
8896
}
89-
languageDetection(textAnalyticsClient);
97+
98+
main().catch((err) => {
99+
console.error("The sample encountered an error:", err);
100+
});
90101
```
91102

92103
> [!div class="nextstepaction"]
@@ -95,8 +106,9 @@ languageDetection(textAnalyticsClient);
95106
### Output
96107

97108
```console
98-
ID: 0
99-
Primary Language French
109+
== Language detection sample ==
110+
ID 0 - Primary language: English (iso6391 name: en)
111+
ID 1 - Primary language: Chinese_Simplified (iso6391 name: zh_chs)
100112
```
101113

102114
## Clean up resources

articles/cognitive-services/language-service/language-detection/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: language-service
1010
ms.topic: quickstart
11-
ms.date: 12/12/2022
11+
ms.date: 02/13/2023
1212
ms.author: jboback
1313
ms.devlang: csharp, java, javascript, python
1414
ms.custom: language-service-language-detection, ignite-fall-2021, mode-api

0 commit comments

Comments
 (0)