@@ -15,15 +15,15 @@ class Program
15
15
{
16
16
// <vars>
17
17
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 ) ;
19
19
20
20
private const string endpoint_var = "TEXT_ANALYTICS_ENDPOINT" ;
21
21
private static readonly string endpoint = Environment . GetEnvironmentVariable ( endpoint_var ) ;
22
22
// </vars>
23
23
24
24
static Program ( )
25
25
{
26
- if ( null == subscriptionKey )
26
+ if ( null == key )
27
27
{
28
28
throw new Exception ( "Please set/export the environment variable: " + key_var ) ;
29
29
}
@@ -33,27 +33,34 @@ static Program()
33
33
}
34
34
}
35
35
36
- // <main >
37
- static void Main ( string [ ] args )
36
+ // <authentication >
37
+ static TextAnalyticsClient authenticateClient ( )
38
38
{
39
- Console . OutputEncoding = System . Text . Encoding . UTF8 ;
40
- var credentials = new ApiKeyServiceClientCredentials ( subscriptionKey ) ;
39
+ ApiKeyServiceClientCredentials credentials = new ApiKeyServiceClientCredentials ( key ) ;
41
40
TextAnalyticsClient client = new TextAnalyticsClient ( credentials )
42
41
{
43
42
Endpoint = endpoint
44
43
} ;
44
+ return client ;
45
+ }
46
+ // </authentication>
47
+
48
+ // <main>
49
+ static void Main ( string [ ] args )
50
+ {
51
+ var client = authenticateClient ( ) ;
45
52
46
- SentimentAnalysisExample ( client ) ;
53
+ sentimentAnalysisExample ( client ) ;
47
54
languageDetectionExample ( client ) ;
48
55
entityRecognitionExample ( client ) ;
49
- KeyPhraseExtractionExample ( client ) ;
56
+ keyPhraseExtractionExample ( client ) ;
50
57
Console . Write ( "Press any key to exit." ) ;
51
58
Console . ReadKey ( ) ;
52
59
}
53
60
// </main>
54
61
55
62
// <sentiment>
56
- static void SentimentAnalysisExample ( ITextAnalyticsClient client )
63
+ static void sentimentAnalysisExample ( ITextAnalyticsClient client )
57
64
{
58
65
var result = client . Sentiment ( "I had the best day of my life." , "en" ) ;
59
66
Console . WriteLine ( $ "Sentiment Score: { result . Score : 0.00} ") ;
@@ -86,7 +93,7 @@ static void entityRecognitionExample(ITextAnalyticsClient client)
86
93
// </entityRecognition>
87
94
88
95
// <keyPhraseExtraction>
89
- static void KeyPhraseExtractionExample ( TextAnalyticsClient client )
96
+ static void keyPhraseExtractionExample ( TextAnalyticsClient client )
90
97
{
91
98
var result = client . KeyPhrases ( "My cat might need to see a veterinarian." ) ;
92
99
0 commit comments