Skip to content

Commit 20703d4

Browse files
Merge pull request #101741 from aahill/v3-quickstarts
[CogSvcs] Combining v2 & v3 quickstarts
2 parents 6e62018 + 671a90e commit 20703d4

17 files changed

+568
-708
lines changed

.openpublishing.redirection.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18381,17 +18381,12 @@
1838118381
"redirect_document_id": false
1838218382
},
1838318383
{
18384-
"source_path": "articles/cognitive-services/text-analytics/quickstarts/go-sdk.md",
18385-
"redirect_url": "/azure/cognitive-services/text-analytics/quickstarts/text-analytics-sdk",
18386-
"redirect_document_id": false
18387-
},
18388-
{
18389-
"source_path": "articles/cognitive-services/text-analytics/quickstarts/ruby-sdk.md",
18384+
"source_path": "articles/cognitive-services/text-analytics/quickstarts/nodejs-sdk.md",
1839018385
"redirect_url": "/azure/cognitive-services/text-analytics/quickstarts/text-analytics-sdk",
1839118386
"redirect_document_id": false
1839218387
},
1839318388
{
18394-
"source_path": "articles/cognitive-services/text-analytics/quickstarts/nodejs-sdk.md",
18389+
"source_path": "articles/cognitive-services/text-analytics/quickstarts/text-analytics-sdk-v2.md",
1839518390
"redirect_url": "/azure/cognitive-services/text-analytics/quickstarts/text-analytics-sdk",
1839618391
"redirect_document_id": false
1839718392
},

articles/cognitive-services/text-analytics/includes/find-azure-resource-info.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ ms.author: aahi
1212
---
1313

1414
> [!IMPORTANT]
15-
> Go to the resource you created to find your key and endpoint. They'll be located on the resource's **Quick start** page, under **resource management**.
15+
> Go to the Azure portal and find the key and endpoint for the Text Analytics resource you created in the prerequisites. They will be located on the resource's **Quick start** page, under **resource management**. Then replace the strings in the code below with your key and endpoint.
1616
>
1717
> Remember to remove the key from your code when you're done, and never post it publicly. For production, consider using a secure way of storing and accessing your credentials. For example, [Azure key vault](https://docs.microsoft.com/azure/key-vault/key-vault-overview).

articles/cognitive-services/text-analytics/includes/quickstarts/v3/csharp.md renamed to articles/cognitive-services/text-analytics/includes/quickstarts/csharp-sdk.md

Lines changed: 144 additions & 28 deletions
Large diffs are not rendered by default.

articles/cognitive-services/text-analytics/includes/quickstarts/v3/java-sdk.md renamed to articles/cognitive-services/text-analytics/includes/quickstarts/java-sdk.md

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,15 @@ ms.reviewer: tasharm, assafi
1515

1616
[Reference documentation](https://aka.ms/azsdk-java-textanalytics-ref-docs) | [Library source code](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/textanalytics/azure-ai-textanalytics) | [Package (Maven)](https://oss.sonatype.org/#nexus-search;quick~com.azure) | [Samples](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/textanalytics/azure-ai-textanalytics/src/samples/java/com/azure/ai/textanalytics)
1717

18-
> [!NOTE]
19-
> * This quickstart uses version `3.0-preview` of the Text Analytics client library, which includes a public preview for improved [Sentiment Analysis](../../../how-tos/text-analytics-how-to-sentiment-analysis.md#sentiment-analysis-versions-and-features) and [Named Entity Recognition (NER)](../../../how-tos/text-analytics-how-to-entity-linking.md#named-entity-recognition-versions-and-features).
20-
> * The code in this article uses synchronous methods and un-secured credentials storage for simplicity reasons. For production scenarios, we recommend using the batched asynchronous methods for performance and scalability. For example, calling `SentimentBatchAsync()` instead of `Sentiment()`.
21-
2218
## Prerequisites
2319

2420
* Azure subscription - [Create one for free](https://azure.microsoft.com/free/)
2521
* [Java Development Kit](https://www.oracle.com/technetwork/java/javase/downloads/index.html) (JDK) with version 8 or above
2622

27-
## Setting up
2823

29-
### Create a Text Analytics Azure resource
24+
[!INCLUDE [text-analytics-resource-creation](resource-creation.md)]
3025

31-
[!INCLUDE [text-analytics-resource-creation](../resource-creation.md)]
26+
## Setting up
3227

3328
### Create a new Maven project
3429

@@ -67,7 +62,7 @@ import java.util.List;
6762

6863
In the java file, add a new class and add your azure resource's key and endpoint as shown below.
6964

70-
[!INCLUDE [text-analytics-find-resource-information](../../find-azure-resource-info.md)]
65+
[!INCLUDE [text-analytics-find-resource-information](../find-azure-resource-info.md)]
7166

7267
```java
7368
public class TextAnalyticsSample {
@@ -99,10 +94,9 @@ The Text Analytics client is a `TextAnalyticsClient` object that authenticates t
9994
## Code examples
10095

10196
* [Authenticate the client](#authenticate-the-client)
102-
* [Sentiment Analysis](#sentiment-analysis) (public preview)
97+
* [Sentiment Analysis](#sentiment-analysis)
10398
* [Language detection](#language-detection)
104-
* [Named Entity recognition](#named-entity-recognition-public-preview) (public preview)
105-
* [Named Entity recognition - personal information](#named-entity-recognition---personal-information-public-preview) (public preview)
99+
* [Named Entity recognition](#named-entity-recognition-ner)
106100
* [Entity linking](#entity-linking)
107101
* [Key phrase extraction](#key-phrase-extraction)
108102

@@ -123,9 +117,6 @@ In your program's `main()` method, call the authentication method to instantiate
123117

124118
## Sentiment analysis
125119

126-
> [!NOTE]
127-
> The below code is for sentiment analysis v3, which is in public preview.
128-
129120
Create a new function called `sentimentAnalysisExample()` that takes the client that you created earlier, and call its `analyzeSentiment()` function. The returned `AnalyzeSentimentResult` object will contain `documentSentiment` and `sentenceSentiments` if successful, or an `errorMessage` if not.
130121

131122
```java
@@ -189,10 +180,12 @@ static void detectLanguageExample(TextAnalyticsClient client)
189180
```console
190181
Language: French, ISO 6391 Name: fr, Score: 1.0.
191182
```
192-
## Named Entity recognition (public preview)
183+
## Named Entity recognition (NER)
193184

194185
> [!NOTE]
195-
> The below code is for Named Entity Recognition v3, which is in public preview.
186+
> In version `3.0-preview`:
187+
> * NER includes separate methods for detecting personal information.
188+
> * Entity linking is a separate request than NER.
196189
197190
Create a new function called `recognizeEntitiesExample()` that takes the client that you created earlier, and call its `recognizeEntities()` function. The returned `RecognizeEntitiesResult` object will contain a list of `NamedEntity` if successful, or an `errorMessage` if not.
198191

@@ -224,10 +217,7 @@ Recognized NamedEntity Text: Seattle, Type: Location, Subtype: N/A, Offset: 26,
224217
Recognized NamedEntity Text: last week, Type: DateTime, Subtype: DateRange, Offset: 34, Length: 9, Score: 0.800.
225218
```
226219

227-
## Named Entity Recognition - personal information (public preview)
228-
229-
> [!NOTE]
230-
> The below code is for detecting personal information using Named Entity Recognition v3, which is in public preview.
220+
## Using NER to detect personal information
231221

232222
Create a new function called `recognizePIIEntitiesExample()` that takes the client that you created earlier, and call its `recognizePiiEntities()` function. The returned `RecognizePiiEntitiesResult` object will contain a list of `NamedEntity` if successful, or an `errorMessage` if not.
233223

articles/cognitive-services/text-analytics/includes/quickstarts/v3/nodejs-sdk.md renamed to articles/cognitive-services/text-analytics/includes/quickstarts/nodejs-sdk.md

Lines changed: 138 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,25 @@ ms.reviewer: sumeh, assafi
1313

1414
<a name="HOLTop"></a>
1515

16-
[Reference documentation](https://aka.ms/azsdk-js-textanalytics-ref-docs) | [Library source code](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/textanalytics/ai-text-analytics) | [Package (NPM)](https://www.npmjs.com/package/@azure/ai-text-analytics) | [Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/textanalytics/ai-text-analytics/samples)
16+
#### [Version 3.0-preview](#tab/version-3)
1717

18-
> [!NOTE]
19-
> * This quickstart uses version `3.0-preview` of the Text Analytics client library, which includes a public preview for improved [Sentiment Analysis](../../../how-tos/text-analytics-how-to-sentiment-analysis.md#sentiment-analysis-versions-and-features) and [Named Entity Recognition (NER)](../../../how-tos/text-analytics-how-to-entity-linking.md#named-entity-recognition-versions-and-features).
20-
>
21-
> * The code in this article uses un-secured credentials storage for simplicity reasons. For production scenarios, we recommend sending strings in batches for performance and scalability. For example, calling `SentimentBatchAsync()` instead of `Sentiment()`.
18+
[v3 Reference documentation](https://aka.ms/azsdk-js-textanalytics-ref-docs) | [v3 Library source code](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/textanalytics/ai-text-analytics) | [v3 Package (NPM)](https://www.npmjs.com/package/@azure/ai-text-analytics) | [v3 Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/textanalytics/ai-text-analytics/samples)
19+
20+
21+
#### [Version 2.1](#tab/version-2)
22+
23+
[v2 Reference documentation](https://docs.microsoft.com/javascript/api/@azure/cognitiveservices-textanalytics) | [v2 Library source code](https://github.com/Azure/azure-sdk-for-node/tree/master/lib/services/cognitiveServicesTextAnalytics) | [v2 Package (NPM)](https://www.npmjs.com/package/@azure/cognitiveservices-textanalytics) | [v2 Samples](https://github.com/Azure-Samples/cognitive-services-node-sdk-samples/)
24+
25+
---
2226

2327
## Prerequisites
2428

2529
* Azure subscription - [Create one for free](https://azure.microsoft.com/free/)
2630
* The current version of [Node.js](https://nodejs.org/).
2731

28-
## Setting up
29-
30-
### Create a Text Analytics Azure resource
32+
[!INCLUDE [text-analytics-resource-creation](resource-creation.md)]
3133

32-
[!INCLUDE [text-analytics-resource-creation](../resource-creation.md)]
34+
## Setting up
3335

3436
### Create a new Node.js application
3537

@@ -67,7 +69,7 @@ const { TextAnalyticsClient, CognitiveServicesCredential } = require("@azure/cog
6769

6870
Create variables for your resource's Azure endpoint and key.
6971

70-
[!INCLUDE [text-analytics-find-resource-information](../../find-azure-resource-info.md)]
72+
[!INCLUDE [text-analytics-find-resource-information](../find-azure-resource-info.md)]
7173

7274
```javascript
7375
const key = '<paste-your-text-analytics-key-here>';
@@ -85,25 +87,33 @@ The response object is a list containing the analysis information for each docum
8587
## Code examples
8688

8789
* [Client Authentication](#client-authentication)
88-
* [Sentiment Analysis](#sentiment-analysis) (public preview)
90+
* [Sentiment Analysis](#sentiment-analysis)
8991
* [Language detection](#language-detection)
90-
* [Named Entity recognition](#named-entity-recognition-public-preview) (public preview)
91-
* [Named Entity recognition - personal information](#named-entity-recognition---personal-information-public-preview) (public preview)
92+
* [Named Entity recognition](#named-entity-recognition-ner)
9293
* [Entity linking](#entity-linking)
9394
* [Key phrase extraction](#key-phrase-extraction)
9495

9596
## Client Authentication
9697

98+
#### [Version 3.0-preview](#tab/version-3)
99+
97100
Create a new `TextAnalyticsClient` object with your key and endpoint as parameters.
98101

99102
```javascript
100103
const client = new TextAnalyticsClient(endpoint, new CognitiveServicesCredential(key));
101104
```
102105

103-
## Sentiment analysis (public preview)
106+
#### [Version 2.1](#tab/version-2)
104107

105-
> [!NOTE]
106-
> The below code is for sentiment analysis v3, which is in public preview.
108+
Create a new [TextAnalyticsClient](https://docs.microsoft.com/javascript/api/@azure/cognitiveservices-textanalytics/textanalyticsclient) object with `credentials` and `endpoint` as a parameter.
109+
110+
[!code-javascript[Authentication and client creation](~/cognitive-services-node-sdk-samples/Samples/textAnalytics.js?name=authentication)]
111+
112+
---
113+
114+
## Sentiment analysis
115+
116+
#### [Version 3.0-preview](#tab/version-3)
107117

108118
Create an array of strings containing the document you want to analyze. Call the client's `analyzeSentiment()` method and get the returned `SentimentBatchResult` object. Iterate through the list of results, and print each document's ID, document level sentiment with confidence scores. For each document, result contains sentence level sentiment along with offsets, length, and confidence scores.
109119

@@ -152,8 +162,29 @@ ID: 0
152162
Length: 30, Offset: 31
153163
```
154164

165+
#### [Version 2.1](#tab/version-2)
166+
167+
Create a list of dictionary objects, containing the documents you want to analyze. Call the client's [sentiment()](https://docs.microsoft.com/javascript/api/@azure/cognitiveservices-textanalytics/textanalyticsclient#sentiment-models-textanalyticsclientsentimentoptionalparams-) method and get the returned [SentimentBatchResult](https://docs.microsoft.com/javascript/api/@azure/cognitiveservices-textanalytics/sentimentbatchresult). Iterate through the list of results, and print each document's ID and sentiment score. A score closer to 0 indicates a negative sentiment, while a score closer to 1 indicates a positive sentiment.
168+
169+
[!code-javascript[Sentiment analysis](~/cognitive-services-node-sdk-samples/Samples/textAnalytics.js?name=sentimentAnalysis)]
170+
171+
Run your code with `node index.js` in your console window.
172+
173+
### Output
174+
175+
```console
176+
[ { id: '1', score: 0.87 } ]
177+
[ { id: '2', score: 0.11 } ]
178+
[ { id: '3', score: 0.44 } ]
179+
[ { id: '4', score: 1.00 } ]
180+
```
181+
182+
---
183+
155184
## Language detection
156185

186+
#### [Version 3.0-preview](#tab/version-3)
187+
157188
Create an array of strings containing the document you want to analyze. Call the client's `detectLanguages()` method and get the returned `DetectLanguageResult`. Then iterate through the results, and print each document's ID, with respective primary and detected language.
158189

159190
```javascript
@@ -186,10 +217,32 @@ ID: 0
186217
Primary Language French
187218
```
188219

189-
## Named Entity Recognition
220+
#### [Version 2.1](#tab/version-2)
221+
222+
Create a list of dictionary objects containing your documents. Call the client's [detectLanguage()](https://docs.microsoft.com/javascript/api/@azure/cognitiveservices-textanalytics/textanalyticsclient#detectlanguage-models-textanalyticsclientdetectlanguageoptionalparams-) method and get the returned [LanguageBatchResult](https://docs.microsoft.com/javascript/api/@azure/cognitiveservices-textanalytics/languagebatchresult). Then iterate through the results, and print each document's ID, and language.
223+
224+
[!code-javascript[Language detection](~/cognitive-services-node-sdk-samples/Samples/textAnalytics.js?name=languageDetection)]
225+
226+
Run your code with `node index.js` in your console window.
227+
228+
### Output
229+
230+
```console
231+
Document ID: 1 , Language: English
232+
Document ID: 2 , Language: Spanish
233+
Document ID: 3 , Language: Chinese_Simplified
234+
```
235+
236+
---
237+
238+
## Named Entity Recognition (NER)
239+
240+
#### [Version 3.0-preview](#tab/version-3)
190241

191242
> [!NOTE]
192-
> The below code is for Named Entity Recognition v3, which is in public preview.
243+
> In version `3.0-preview`:
244+
> * NER includes separate methods for detecting personal information.
245+
> * Entity linking is a separate request than NER.
193246
194247
Create an array of strings containing the document you want to analyze. Call the client's `recognizeEntities()` method and get the `RecognizeEntitiesResult` object. Iterate through the list of results, and print the entity name, type, subtype, offset, length, and score.
195248

@@ -239,10 +292,7 @@ Document ID: 1
239292
Offset: 71, Length: 2 Score: 0.8
240293
```
241294

242-
## Named Entity Recognition - personal information (public preview)
243-
244-
> [!NOTE]
245-
> The below code is for detecting personal information using Named Entity Recognition v3, which is in public preview.
295+
## Using NER to detect personal information
246296

247297
Create an array of strings containing the document you want to analyze. Call the client's `recognizePiiEntities()` method and get the `EntitiesBatchResult` object. Iterate through the list of results, and print the entity name, type, subtype, offset, length, and score.
248298

@@ -339,8 +389,53 @@ Document ID: 0
339389
Offset: 89, Length: 5 Score: 0.052
340390
```
341391

392+
#### [Version 2.1](#tab/version-2)
393+
394+
> [!NOTE]
395+
> In version 2.1, entity linking is included in the NER response.
396+
397+
Create a list of objects, containing your documents. Call the client's [entities()](https://docs.microsoft.com/javascript/api/@azure/cognitiveservices-textanalytics/textanalyticsclient#entities-models-textanalyticscliententitiesoptionalparams-) method and get the [EntitiesBatchResult](https://docs.microsoft.com/javascript/api/@azure/cognitiveservices-textanalytics/entitiesbatchresult) object. Iterate through the list of results, and print each document's ID. For each detected entity, print its wikipedia name, the type and sub-types (if exists) as well as the locations in the original text.
398+
399+
[!code-javascript[Entity recognition](~/cognitive-services-node-sdk-samples/Samples/textAnalytics.js?name=entityRecognition)]
400+
401+
Run your code with `node index.js` in your console window.
402+
403+
### Output
404+
405+
```console
406+
Document ID: 1
407+
Name: Microsoft, Type: Organization, Sub-Type: N/A
408+
Offset: 0, Length: 9, Score: 1.0
409+
Name: Bill Gates, Type: Person, Sub-Type: N/A
410+
Offset: 25, Length: 10, Score: 0.999847412109375
411+
Name: Paul Allen, Type: Person, Sub-Type: N/A
412+
Offset: 40, Length: 10, Score: 0.9988409876823425
413+
Name: April 4, Type: Other, Sub-Type: N/A
414+
Offset: 54, Length: 7, Score: 0.8
415+
Name: April 4, 1975, Type: DateTime, Sub-Type: Date
416+
Offset: 54, Length: 13, Score: 0.8
417+
Name: BASIC, Type: Other, Sub-Type: N/A
418+
Offset: 89, Length: 5, Score: 0.8
419+
Name: Altair 8800, Type: Other, Sub-Type: N/A
420+
Offset: 116, Length: 11, Score: 0.8
421+
422+
Document ID: 2
423+
Name: Microsoft, Type: Organization, Sub-Type: N/A
424+
Offset: 21, Length: 9, Score: 0.999755859375
425+
Name: Redmond (Washington), Type: Location, Sub-Type: N/A
426+
Offset: 60, Length: 7, Score: 0.9911284446716309
427+
Name: 21 kilómetros, Type: Quantity, Sub-Type: Dimension
428+
Offset: 71, Length: 13, Score: 0.8
429+
Name: Seattle, Type: Location, Sub-Type: N/A
430+
Offset: 88, Length: 7, Score: 0.9998779296875
431+
```
432+
433+
---
434+
342435
## Key phrase extraction
343436

437+
#### [Version 3.0-preview](#tab/version-3)
438+
344439
Create an array of strings containing the document you want to analyze. Call the client's `extractKeyPhrases()` method and get the returned `ExtractKeyPhrasesResult` object. Iterate through the results and print each document's ID, and any detected key phrases.
345440

346441
```javascript
@@ -370,6 +465,27 @@ ID: 0
370465
Document Key Phrases: cat,veterinarian
371466
```
372467

468+
#### [Version 2.1](#tab/version-2)
469+
470+
Create a list of objects, containing your documents. Call the client's [keyPhrases()](https://docs.microsoft.com/javascript/api/@azure/cognitiveservices-textanalytics/textanalyticsclient#keyphrases-models-textanalyticsclientkeyphrasesoptionalparams-) method and get the returned [KeyPhraseBatchResult](https://docs.microsoft.com/javascript/api/@azure/cognitiveservices-textanalytics/keyphrasebatchresult) object. Iterate through the results and print each document's ID, and any detected key phrases.
471+
472+
[!code-javascript[Key phrase extraction](~/cognitive-services-node-sdk-samples/Samples/textAnalytics.js?name=keyPhraseExtraction)]
473+
474+
Run your code with `node index.js` in your console window.
475+
476+
### Output
477+
478+
```console
479+
[
480+
{ id: '1', keyPhrases: [ '幸せ' ] }
481+
{ id: '2', keyPhrases: [ 'Stuttgart', "hotel", "Fahrt", "Fu" ] }
482+
{ id: '3', keyPhrases: [ 'cat', 'veterinarian' ] }
483+
{ id: '3', keyPhrases: [ 'fútbol' ] }
484+
]
485+
```
486+
487+
---
488+
373489
## Run the application
374490

375491
Run the application with the `node` command on your quickstart file.

0 commit comments

Comments
 (0)