Skip to content

Commit 96d8fa2

Browse files
authored
Merge pull request #176 from aahill/ta-fix
[TextAnalytics] Minor formatting updates
2 parents 0e62f64 + 490ef49 commit 96d8fa2

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

samples/TextAnalytics/synchronous/Program.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class Program
1515
{
1616
// <vars>
1717
private const string key_var = "TEXT_ANALYTICS_SUBSCRIPTION_KEY";
18-
private static readonly string subscriptionKey = Environment.GetEnvironmentVariable(key_var);
18+
private static readonly string key = Environment.GetEnvironmentVariable(key_var);
1919

2020
private const string endpoint_var = "TEXT_ANALYTICS_ENDPOINT";
2121
private static readonly string endpoint = Environment.GetEnvironmentVariable(endpoint_var);
2222
// </vars>
2323

2424
static Program()
2525
{
26-
if (null == subscriptionKey)
26+
if (null == key)
2727
{
2828
throw new Exception("Please set/export the environment variable: " + key_var);
2929
}
@@ -33,27 +33,34 @@ static Program()
3333
}
3434
}
3535

36-
// <main>
37-
static void Main(string[] args)
36+
// <authentication>
37+
static TextAnalyticsClient authenticateClient()
3838
{
39-
Console.OutputEncoding = System.Text.Encoding.UTF8;
40-
var credentials = new ApiKeyServiceClientCredentials(subscriptionKey);
39+
ApiKeyServiceClientCredentials credentials = new ApiKeyServiceClientCredentials(key);
4140
TextAnalyticsClient client = new TextAnalyticsClient(credentials)
4241
{
4342
Endpoint = endpoint
4443
};
44+
return client;
45+
}
46+
// </authentication>
47+
48+
// <main>
49+
static void Main(string[] args)
50+
{
51+
var client = authenticateClient();
4552

46-
SentimentAnalysisExample(client);
53+
sentimentAnalysisExample(client);
4754
languageDetectionExample(client);
4855
entityRecognitionExample(client);
49-
KeyPhraseExtractionExample(client);
56+
keyPhraseExtractionExample(client);
5057
Console.Write("Press any key to exit.");
5158
Console.ReadKey();
5259
}
5360
// </main>
5461

5562
// <sentiment>
56-
static void SentimentAnalysisExample(ITextAnalyticsClient client)
63+
static void sentimentAnalysisExample(ITextAnalyticsClient client)
5764
{
5865
var result = client.Sentiment("I had the best day of my life.", "en");
5966
Console.WriteLine($"Sentiment Score: {result.Score:0.00}");
@@ -86,7 +93,7 @@ static void entityRecognitionExample(ITextAnalyticsClient client)
8693
// </entityRecognition>
8794

8895
// <keyPhraseExtraction>
89-
static void KeyPhraseExtractionExample(TextAnalyticsClient client)
96+
static void keyPhraseExtractionExample(TextAnalyticsClient client)
9097
{
9198
var result = client.KeyPhrases("My cat might need to see a veterinarian.");
9299

0 commit comments

Comments
 (0)