@@ -6,12 +6,12 @@ manager: nitinme
6
6
ms.service : cognitive-services
7
7
ms.subservice : language-service
8
8
ms.topic : include
9
- ms.date : 12/12/2022
9
+ ms.date : 02/13/2023
10
10
ms.author : aahi
11
11
ms.custom : devx-track-js, ignite-fall-2021
12
12
---
13
13
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 )
15
15
16
16
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.
17
17
@@ -53,7 +53,7 @@ npm init
53
53
Install the npm package:
54
54
55
55
``` console
56
- npm install @azure/ai-[email protected]
56
+ npm install @azure/ai-language-text
57
57
```
58
58
59
59
> [ !div class="nextstepaction"]
@@ -68,32 +68,45 @@ Open the file and copy the below code. Remember to replace the `key` variable wi
68
68
``` javascript
69
69
" use strict" ;
70
70
71
- const { TextAnalyticsClient , AzureKeyCredential } = require (" @azure/ai-text-analytics " );
71
+ const { TextAnalysisClient , AzureKeyCredential } = require (" @azure/ai-language-text " );
72
72
const endpoint = ' <paste-your-endpoint-here>' ;
73
73
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 (` \t Name: ${ entity .name } \t ID: ${ entity .dataSourceEntityId } \t URL: ${ entity .url } \t Data Source: ${ entity .dataSource } ` );
89
- console .log (` \t Matches:` )
90
- entity .matches .forEach (match => {
91
- console .log (` \t\t Text: ${ match .text } \t Score: ${ 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 (" \t Entities:" );
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\t Matches:" );
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
+ });
97
110
98
111
```
99
112
@@ -103,27 +116,21 @@ linkedEntityRecognition(textAnalyticsClient);
103
116
### Output
104
117
105
118
``` 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
127
134
```
128
135
129
136
[ !INCLUDE [ clean up resources] ( ../../../includes/clean-up-resources.md )]
@@ -135,5 +142,5 @@ Document ID: 0
135
142
136
143
* [ Entity linking language support] ( ../../language-support.md )
137
144
* [ 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 )
0 commit comments