@@ -55,37 +55,20 @@ namespace Example
55
55
{
56
56
private static readonly AzureKeyCredential credentials = new AzureKeyCredential (" replace-with-your-key-here" );
57
57
private static readonly Uri endpoint = new Uri (" replace-with-your-endpoint-here" );
58
-
59
- // Example method for detecting sentiment from text.
60
- static void SentimentAnalysisExample (TextAnalyticsClient client )
61
- {
62
- string inputText = " I had the best day of my life. I wish you were there with me." ;
63
- DocumentSentiment documentSentiment = client .AnalyzeSentiment (inputText );
64
- Console .WriteLine ($" Document sentiment: {documentSentiment .Sentiment }\n " );
65
-
66
- foreach (var sentence in documentSentiment .Sentences )
67
- {
68
- Console .WriteLine ($" \t Text: \" {sentence .Text }\" " );
69
- Console .WriteLine ($" \t Sentence sentiment: {sentence .Sentiment }" );
70
- Console .WriteLine ($" \t Positive score: {sentence .ConfidenceScores .Positive : 0 . 00 }" );
71
- Console .WriteLine ($" \t Negative score: {sentence .ConfidenceScores .Negative : 0 . 00 }" );
72
- Console .WriteLine ($" \t Neutral score: {sentence .ConfidenceScores .Neutral : 0 . 00 }\n " );
73
- }
74
- }
75
58
76
59
// Example method for detecting opinions text.
77
60
static void SentimentAnalysisWithOpinionMiningExample (TextAnalyticsClient client )
78
61
{
79
62
var documents = new List <string >
80
63
{
81
- " The food and service were unacceptable, but the concierge were nice."
64
+ " The food and service were unacceptable. The concierge was nice, however ."
82
65
};
83
-
66
+
84
67
AnalyzeSentimentResultCollection reviews = client .AnalyzeSentimentBatch (documents , options : new AnalyzeSentimentOptions ()
85
68
{
86
69
IncludeOpinionMining = true
87
70
});
88
-
71
+
89
72
foreach (AnalyzeSentimentResult review in reviews )
90
73
{
91
74
Console .WriteLine ($" Document sentiment: {review .DocumentSentiment .Sentiment }\n " );
@@ -99,7 +82,7 @@ namespace Example
99
82
Console .WriteLine ($" \t Sentence positive score: {sentence .ConfidenceScores .Positive : 0 . 00 }" );
100
83
Console .WriteLine ($" \t Sentence negative score: {sentence .ConfidenceScores .Negative : 0 . 00 }" );
101
84
Console .WriteLine ($" \t Sentence neutral score: {sentence .ConfidenceScores .Neutral : 0 . 00 }\n " );
102
-
85
+
103
86
foreach (SentenceOpinion sentenceOpinion in sentence .Opinions )
104
87
{
105
88
Console .WriteLine ($" \t Target: {sentenceOpinion .Target .Text }, Value: {sentenceOpinion .Target .Sentiment }" );
@@ -120,7 +103,6 @@ namespace Example
120
103
static void Main (string [] args )
121
104
{
122
105
var client = new TextAnalyticsClient (endpoint , credentials );
123
- SentimentAnalysisExample (client );
124
106
SentimentAnalysisWithOpinionMiningExample (client );
125
107
126
108
Console .Write (" Press any key to exit." );
@@ -138,50 +120,40 @@ namespace Example
138
120
## Output
139
121
140
122
``` console
141
- Document sentiment: Positive
142
-
143
- Text: "I had the best day of my life. "
144
- Sentence sentiment: Positive
145
- Positive score: 0.99
146
- Negative score: 0.00
147
- Neutral score: 0.00
148
-
149
- Text: "I wish you were there with me."
150
- Sentence sentiment: Neutral
151
- Positive score: 0.25
152
- Negative score: 0.03
153
- Neutral score: 0.72
154
-
155
- Document sentiment: Positive
156
-
157
- Positive score: 0.76
158
- Negative score: 0.23
159
- Neutral score: 0.00
160
-
161
- Text: "The food and service were unacceptable, but the concierge were nice."
162
- Sentence sentiment: Positive
163
- Sentence positive score: 0.76
164
- Sentence negative score: 0.23
165
- Sentence neutral score: 0.00
166
-
167
- Target: food, Value: Negative
168
- Target positive score: 0.00
169
- Target negative score: 1.00
170
- Related Assessment: unacceptable, Value: Negative
171
- Related Assessment positive score: 0.00
172
- Related Assessment negative score: 1.00
173
- Target: service, Value: Negative
174
- Target positive score: 0.00
175
- Target negative score: 1.00
176
- Related Assessment: unacceptable, Value: Negative
177
- Related Assessment positive score: 0.00
178
- Related Assessment negative score: 1.00
179
- Target: concierge, Value: Positive
180
- Target positive score: 1.00
181
- Target negative score: 0.00
182
- Related Assessment: nice, Value: Positive
183
- Related Assessment positive score: 1.00
184
- Related Assessment negative score: 0.00
185
-
186
- Press any key to exit.
123
+ Document sentiment: Mixed
124
+
125
+ Positive score: 0.47
126
+ Negative score: 0.52
127
+ Neutral score: 0.00
128
+
129
+ Text: "The food and service were unacceptable. "
130
+ Sentence sentiment: Negative
131
+ Sentence positive score: 0.00
132
+ Sentence negative score: 0.99
133
+ Sentence neutral score: 0.00
134
+
135
+ Target: food, Value: Negative
136
+ Target positive score: 0.00
137
+ Target negative score: 1.00
138
+ Related Assessment: unacceptable, Value: Negative
139
+ Related Assessment positive score: 0.00
140
+ Related Assessment negative score: 1.00
141
+ Target: service, Value: Negative
142
+ Target positive score: 0.00
143
+ Target negative score: 1.00
144
+ Related Assessment: unacceptable, Value: Negative
145
+ Related Assessment positive score: 0.00
146
+ Related Assessment negative score: 1.00
147
+ Text: "The concierge was nice, however."
148
+ Sentence sentiment: Positive
149
+ Sentence positive score: 0.94
150
+ Sentence negative score: 0.05
151
+ Sentence neutral score: 0.01
152
+
153
+ Target: concierge, Value: Positive
154
+ Target positive score: 1.00
155
+ Target negative score: 0.00
156
+ Related Assessment: nice, Value: Positive
157
+ Related Assessment positive score: 1.00
158
+ Related Assessment negative score: 0.00
187
159
```
0 commit comments