Skip to content

Commit ef92f65

Browse files
authored
Merge pull request #76192 from jborsecnik/text-an
Edit pass: Using C#
2 parents 601e182 + df6a8f2 commit ef92f65

File tree

1 file changed

+38
-36
lines changed
  • articles/cognitive-services/text-analytics/quickstarts

1 file changed

+38
-36
lines changed

articles/cognitive-services/text-analytics/quickstarts/csharp.md

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: 'Quickstart: Using C# to call the Text Analytics API'
2+
title: 'Quickstart: Call the Text Analytics service by using the Azure SDK for .NET and C#'
33
titleSuffix: Azure Cognitive Services
4-
description: Get information and code samples to help you quickly get started with using the Text Analytics API.
4+
description: Information and code samples to help you start using the Text Analytics service and C#.
55
services: cognitive-services
66
author: raymondl
77
manager: nitinme
@@ -13,35 +13,38 @@ ms.date: 04/29/2019
1313
ms.author: assafi
1414
---
1515

16-
# Quickstart: Using C# to call the Text Analytics Cognitive Service
16+
# Quickstart: Use the .NET SDK and C# to call the Text Analytics service
1717
<a name="HOLTop"></a>
1818

19-
Use this quickstart to begin analyzing language with the Text Analytics SDK for C#. While the [Text Analytics](//go.microsoft.com/fwlink/?LinkID=759711) REST API is compatible with most programming languages, the SDK provides an easy way to integrate the service into your applications. The source code for this sample can be found on [GitHub](https://github.com/Azure-Samples/cognitive-services-dotnet-sdk-samples/tree/master/samples/TextAnalytics).
19+
This quickstart helps you begin using the Azure SDK for .NET and C# to analyze language. Although the [Text Analytics](//go.microsoft.com/fwlink/?LinkID=759711) REST API is compatible with most programming languages, the SDK provides an easy way to integrate the service into your applications.
2020

21-
Refer to the [API definitions](https://westus.dev.cognitive.microsoft.com/docs/services/TextAnalytics-v2-1/operations/56f30ceeeda5650db055a3c7) for technical documentation for the APIs.
21+
> [!NOTE]
22+
> The source code for this sample is available on [GitHub](https://github.com/Azure-Samples/cognitive-services-dotnet-sdk-samples/tree/master/samples/TextAnalytics).
23+
24+
For technical details, refer to the SDK for .NET [Text Analytics reference](https://docs.microsoft.com/dotnet/api/overview/azure/cognitiveservices/client/textanalytics?view=azure-dotnet).
2225

2326
## Prerequisites
2427

2528
[!INCLUDE [cognitive-services-text-analytics-signup-requirements](../../../../includes/cognitive-services-text-analytics-signup-requirements.md)]
2629

27-
You must also have the [endpoint and access key](../How-tos/text-analytics-how-to-access-key.md) that was generated for you during sign-up.
30+
You also need the [endpoint and access key](../How-tos/text-analytics-how-to-access-key.md) that was generated for you during sign-up.
2831

2932
> [!Tip]
30-
> While you could call the [HTTP endpoints](https://westus.dev.cognitive.microsoft.com/docs/services/TextAnalytics-v2-1/operations/56f30ceeeda5650db055a3c9) directly from C#, the Microsoft.Azure.CognitiveServices.Language SDK makes it much easier to call the service without having to worry about serializing and deserializing JSON.
33+
> While you can call the [HTTP endpoints](https://westus.dev.cognitive.microsoft.com/docs/services/TextAnalytics-v2-1/operations/56f30ceeeda5650db055a3c9) directly from C#, the Microsoft.Azure.CognitiveServices.Language SDK makes it much easier to call the service without having to serialize and deserialize JSON.
3134
>
3235
> A few useful links:
33-
> - [SDK Nuget page](https://www.nuget.org/packages/Microsoft.Azure.CognitiveServices.Language.TextAnalytics)
36+
> - [SDK NuGet page](https://www.nuget.org/packages/Microsoft.Azure.CognitiveServices.Language.TextAnalytics)
3437
> - [SDK code](https://github.com/Azure/azure-sdk-for-net/tree/master/src/SDKs/CognitiveServices/dataPlane/Language/TextAnalytics)
3538
3639
## Create the Visual Studio solution and install the SDK
3740

38-
1. Create a new Console App (.NET Core) project [Visual Studio](https://visualstudio.microsoft.com/vs/).
39-
1. Right click on the solution and click **Manage NuGet Packages for Solution**
40-
1. Select the **Browse** tab, and Search for **Microsoft.Azure.CognitiveServices.Language.TextAnalytics**
41+
1. Create a new console app (.NET Core) project. [Access Visual Studio](https://visualstudio.microsoft.com/vs/).
42+
1. Right-click the solution and select **Manage NuGet Packages for Solution**.
43+
1. Select the **Browse** tab. Search for **Microsoft.Azure.CognitiveServices.Language.TextAnalytics**.
4144

4245
## Authenticate your credentials
4346

44-
1. Add the following `using` statements to the main class file (`Program.cs` by default).
47+
1. Add the following `using` statements to the main class file (which is Program.cs by default).
4548

4649
```csharp
4750
using System;
@@ -59,7 +62,7 @@ You must also have the [endpoint and access key](../How-tos/text-analytics-how-t
5962

6063
```csharp
6164
/// <summary>
62-
/// Allows authentication to the API using a basic apiKey mechanism
65+
/// Allows authentication to the API by using a basic apiKey mechanism
6366
/// </summary>
6467
class ApiKeyServiceClientCredentials : ServiceClientCredentials
6568
{
@@ -92,32 +95,32 @@ You must also have the [endpoint and access key](../How-tos/text-analytics-how-t
9295
}
9396
```
9497

95-
3. Update the `Program` class and add a constant member for your Text Analytics subscription key and another for the service endpoint. Remember to use the correct Azure region for your Text Analytics subscription.
98+
3. Update the `Program` class. Add a constant member for your Text Analytics subscription key, and another for the service endpoint. Remember to use the correct Azure region for your Text Analytics subscription.
9699

97100
```csharp
98101
private const string SubscriptionKey = "enter-your-key-here";
99102

100103
private const string Endpoint = "enter-your-service-endpoint-here"; // For example: "https://westus.api.cognitive.microsoft.com";
101104
```
102105
> [!Tip]
103-
> For secure deployment of secrets in production systems we recommend using [Azure Key Vault](https://docs.microsoft.com/azure/key-vault/quick-create-net)
106+
> To boost the security of secrets in production systems, we recommend that you use [Azure Key Vault](https://docs.microsoft.com/azure/key-vault/quick-create-net).
104107
>
105108

106109
## Create a Text Analytics client
107110

108-
In the `Main` function of your project, call the sample method you would like to invoke and pass the `Endpoint` and `SubscriptionKey` parameters you defined.
111+
In the `Main` function of your project, call the sample method that you want to invoke. Pass the `Endpoint` and `SubscriptionKey` parameters that you defined.
109112

110113
```csharp
111114
public static void Main(string[] args)
112115
{
113116
var credentials = new ApiKeyServiceClientCredentials(SubscriptionKey);
114117
var client = new TextAnalyticsClient(credentials)
115118
{
116-
//Replace 'westus' with the correct region for your Text Analytics subscription
119+
//Replace 'westus' with the correct region for your Text Analytics subscription.
117120
Endpoint = "https://westus.api.cognitive.microsoft.com"
118121
};
119122

120-
// Change console encoding to display non-ASCII characters
123+
// Change the console encoding to display non-ASCII characters.
121124
Console.OutputEncoding = System.Text.Encoding.UTF8;
122125
SentimentAnalysisExample(client).Wait();
123126
// DetectLanguageExample(client).Wait();
@@ -127,12 +130,12 @@ In the `Main` function of your project, call the sample method you would like to
127130
}
128131
```
129132

130-
Next sections describes how to call each of the API features.
133+
The following sections describe how to call each service feature.
131134

132-
## Sentiment analysis
135+
## Perform sentiment analysis
133136

134-
1. Create a new function called `SentimentAnalysisExample()` that takes the client created earlier.
135-
2. Generate a list of `MultiLanguageInput` objects, containing the documents you want to analyze.
137+
1. Create a new function `SentimentAnalysisExample()` that takes the client that you created earlier.
138+
2. Generate a list of `MultiLanguageInput` objects that contains the documents that you want to analyze.
136139

137140
```csharp
138141
public static async Task SentimentAnalysisExample(TextAnalyticsClient client)
@@ -150,7 +153,7 @@ Next sections describes how to call each of the API features.
150153
}
151154
```
152155

153-
3. In the same function, call `client.SentimentAsync()` and get the result. Then iterate through the 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.
156+
3. In the same function, call `client.SentimentAsync()` and get the result. Then iterate through the results. Print each document's ID and sentiment score. A score that's close to 0 indicates a negative sentiment, while a score that's closer to 1 indicates a positive sentiment.
154157

155158
```csharp
156159
var result = await client.SentimentAsync(false, inputDocuments);
@@ -171,10 +174,10 @@ Document ID: 3 , Sentiment Score: 0.44
171174
Document ID: 4 , Sentiment Score: 1.00
172175
```
173176

174-
## Language detection
177+
## Perform language detection
175178

176-
1. Create a new function called `DetectLanguageExample()` that takes the client created earlier.
177-
2. Generate a list of `LanguageInput` objects, containing your documents.
179+
1. Create a new function `DetectLanguageExample()` that takes the client that you created earlier.
180+
2. Generate a list of `LanguageInput` objects that contains your documents.
178181

179182
```csharp
180183
public static async Task DetectLanguageExample(TextAnalyticsClient client)
@@ -192,7 +195,7 @@ Document ID: 4 , Sentiment Score: 1.00
192195
}
193196
```
194197

195-
3. In the same function, call `client.DetectLanguageAsync()` and get the result. Then iterate through the results, and print each document's ID, and the first returned language.
198+
3. In the same function, call `client.DetectLanguageAsync()` and get the result. Then iterate through the results. Print each document's ID and the first returned language.
196199

197200
```csharp
198201
var langResults = await client.DetectLanguageAsync(false, inputDocuments);
@@ -213,10 +216,10 @@ Document ID: 2 , Language: Spanish
213216
Document ID: 3 , Language: Chinese_Simplified
214217
```
215218

216-
## Entity recognition
219+
## Perform entity recognition
217220

218-
1. Create a new function called `RecognizeEntitiesExample()` that takes the client created earlier.
219-
2. Generate a list of `MultiLanguageBatchInput` objects, containing your documents.
221+
1. Create a new function `RecognizeEntitiesExample()` that takes the client that you created earlier.
222+
2. Generate a list of `MultiLanguageBatchInput` objects that contains your documents.
220223

221224
```csharp
222225
public static async Task RecognizeEntitiesExample(TextAnalyticsClient client)
@@ -233,7 +236,7 @@ Document ID: 3 , Language: Chinese_Simplified
233236
}
234237
```
235238

236-
3. In the same function, call `client.EntitiesAsync()` and get the result. Then iterate through the results, and print each document's ID. For each detected entity, print it's wikipedia name, the type and sub-types (if exists) as well as the locations in the original text.
239+
3. In the same function, call `client.EntitiesAsync()` and get the result. Then iterate through the results. Print each document's ID. For each detected entity, print its Wikipedia name and the type and subtypes (if they exist) as well as the locations in the original text.
237240

238241
```csharp
239242
var entitiesResult = await client.EntitiesAsync(false, inputDocuments);
@@ -286,10 +289,10 @@ Document ID: 2
286289
Offset: 88, Length: 7, Score: 1.000
287290
```
288291

289-
## Key phrase extraction
292+
## Perform key phrase extraction
290293

291-
1. Create a new function called `KeyPhraseExtractionExample()` that takes the client created earlier.
292-
2. Generate a list of `MultiLanguageBatchInput` objects, containing your documents.
294+
1. Create a new function `KeyPhraseExtractionExample()` that takes the client that you created earlier.
295+
2. Generate a list of `MultiLanguageBatchInput` objects that contains your documents.
293296

294297
```csharp
295298
public static async Task KeyPhraseExtractionExample(TextAnalyticsClient client)
@@ -306,7 +309,7 @@ Document ID: 2
306309
}
307310
```
308311

309-
3. In the same function, call `client.KeyPhrasesAsync()` and get the result. Then iterate through the results, and print each document's ID, and any detected key phrases.
312+
3. In the same function, call `client.KeyPhrasesAsync()` and get the result. Then iterate through the results. Print each document's ID and any detected key phrases.
310313

311314
```csharp
312315
var kpResults = await client.KeyPhrasesAsync(false, inputDocuments);
@@ -354,4 +357,3 @@ Document ID: 4
354357

355358
* [Text Analytics overview](../overview.md)
356359
* [Frequently asked questions (FAQ)](../text-analytics-resource-faq.md)
357-

0 commit comments

Comments
 (0)