Skip to content

Commit a1155f6

Browse files
authored
Merge pull request #205382 from aahill/sentiment-qs
quickstart updates
2 parents 482a6a8 + 8b051ee commit a1155f6

File tree

5 files changed

+171
-242
lines changed

5 files changed

+171
-242
lines changed

articles/cognitive-services/language-service/sentiment-opinion-mining/includes/quickstarts/csharp-sdk.md

Lines changed: 40 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,20 @@ namespace Example
5555
{
5656
private static readonly AzureKeyCredential credentials = new AzureKeyCredential("replace-with-your-key-here");
5757
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($"\tText: \"{sentence.Text}\"");
69-
Console.WriteLine($"\tSentence sentiment: {sentence.Sentiment}");
70-
Console.WriteLine($"\tPositive score: {sentence.ConfidenceScores.Positive:0.00}");
71-
Console.WriteLine($"\tNegative score: {sentence.ConfidenceScores.Negative:0.00}");
72-
Console.WriteLine($"\tNeutral score: {sentence.ConfidenceScores.Neutral:0.00}\n");
73-
}
74-
}
7558

7659
// Example method for detecting opinions text.
7760
static void SentimentAnalysisWithOpinionMiningExample(TextAnalyticsClient client)
7861
{
7962
var documents = new List<string>
8063
{
81-
"The food and service were unacceptable, but the concierge were nice."
64+
"The food and service were unacceptable. The concierge was nice, however."
8265
};
83-
66+
8467
AnalyzeSentimentResultCollection reviews = client.AnalyzeSentimentBatch(documents, options: new AnalyzeSentimentOptions()
8568
{
8669
IncludeOpinionMining = true
8770
});
88-
71+
8972
foreach (AnalyzeSentimentResult review in reviews)
9073
{
9174
Console.WriteLine($"Document sentiment: {review.DocumentSentiment.Sentiment}\n");
@@ -99,7 +82,7 @@ namespace Example
9982
Console.WriteLine($"\tSentence positive score: {sentence.ConfidenceScores.Positive:0.00}");
10083
Console.WriteLine($"\tSentence negative score: {sentence.ConfidenceScores.Negative:0.00}");
10184
Console.WriteLine($"\tSentence neutral score: {sentence.ConfidenceScores.Neutral:0.00}\n");
102-
85+
10386
foreach (SentenceOpinion sentenceOpinion in sentence.Opinions)
10487
{
10588
Console.WriteLine($"\tTarget: {sentenceOpinion.Target.Text}, Value: {sentenceOpinion.Target.Sentiment}");
@@ -120,7 +103,6 @@ namespace Example
120103
static void Main(string[] args)
121104
{
122105
var client = new TextAnalyticsClient(endpoint, credentials);
123-
SentimentAnalysisExample(client);
124106
SentimentAnalysisWithOpinionMiningExample(client);
125107

126108
Console.Write("Press any key to exit.");
@@ -138,50 +120,40 @@ namespace Example
138120
## Output
139121

140122
```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
187159
```

articles/cognitive-services/language-service/sentiment-opinion-mining/includes/quickstarts/java-sdk.md

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public class Example {
6565

6666
public static void main(String[] args) {
6767
TextAnalyticsClient client = authenticateClient(KEY, ENDPOINT);
68-
sentimentAnalysisExample(client);
6968
sentimentAnalysisWithOpinionMiningExample(client);
7069
}
7170
// Method to authenticate the client object with your key and endpoint.
@@ -75,34 +74,11 @@ public class Example {
7574
.endpoint(endpoint)
7675
.buildClient();
7776
}
78-
// Example method for sentiment in text.
79-
static void sentimentAnalysisExample(TextAnalyticsClient client)
80-
{
81-
// The text that need be analyzed.
82-
String text = "I had the best day of my life. I wish you were there with me.";
83-
84-
DocumentSentiment documentSentiment = client.analyzeSentiment(text);
85-
System.out.printf(
86-
"Recognized document sentiment: %s, positive score: %s, neutral score: %s, negative score: %s.%n",
87-
documentSentiment.getSentiment(),
88-
documentSentiment.getConfidenceScores().getPositive(),
89-
documentSentiment.getConfidenceScores().getNeutral(),
90-
documentSentiment.getConfidenceScores().getNegative());
91-
92-
for (SentenceSentiment sentenceSentiment : documentSentiment.getSentences()) {
93-
System.out.printf(
94-
"Recognized sentence sentiment: %s, positive score: %s, neutral score: %s, negative score: %s.%n",
95-
sentenceSentiment.getSentiment(),
96-
sentenceSentiment.getConfidenceScores().getPositive(),
97-
sentenceSentiment.getConfidenceScores().getNeutral(),
98-
sentenceSentiment.getConfidenceScores().getNegative());
99-
}
100-
}
101-
// Example method for detecting opinions in text.
77+
// Example method for detecting sentiment and opinions in text.
10278
static void sentimentAnalysisWithOpinionMiningExample(TextAnalyticsClient client)
10379
{
10480
// The document that needs be analyzed.
105-
String document = "Bad atmosphere. Not close to plenty of restaurants, hotels, and transit! Staff are not friendly and helpful.";
81+
String document = "The food and service were unacceptable. The concierge was nice, however.";
10682

10783
System.out.printf("Document = %s%n", document);
10884

@@ -130,7 +106,6 @@ public class Example {
130106
});
131107
}
132108
}
133-
134109
```
135110

136111
> [!div class="nextstepaction"]
@@ -139,18 +114,14 @@ public class Example {
139114
## Output
140115

141116
```console
142-
Recognized document sentiment: positive, positive score: 0.99, neutral score: 0.0, negative score: 0.0.
143-
Recognized sentence sentiment: positive, positive score: 0.99, neutral score: 0.0, negative score: 0.0.
144-
Recognized sentence sentiment: neutral, positive score: 0.25, neutral score: 0.72, negative score: 0.03.
145-
146-
Document = Bad atmosphere. Not close to plenty of restaurants, hotels, and transit! Staff are not friendly and helpful.
147-
Recognized document sentiment: negative, positive score: 0.050000, neutral score: 0.030000, negative score: 0.920000.
148-
Sentence sentiment: negative, positive score: 0.010000, neutral score: 0.000000, negative score: 0.990000.
149-
Target sentiment: negative, target text: atmosphere
150-
'negative' assessment sentiment because of "Bad". Is the assessment negated: false.
151-
Sentence sentiment: negative, positive score: 0.140000, neutral score: 0.080000, negative score: 0.780000.
152-
Sentence sentiment: negative, positive score: 0.010000, neutral score: 0.000000, negative score: 0.990000.
153-
Target sentiment: negative, target text: Staff
154-
'negative' assessment sentiment because of "friendly". Is the assessment negated: true.
155-
'negative' assessment sentiment because of "helpful". Is the assessment negated: true.
117+
Document = The food and service were unacceptable. The concierge was nice, however.
118+
Recognized document sentiment: mixed, positive score: 0.470000, neutral score: 0.000000, negative score: 0.520000.
119+
Sentence sentiment: negative, positive score: 0.000000, neutral score: 0.000000, negative score: 0.990000.
120+
Target sentiment: negative, target text: food
121+
'negative' assessment sentiment because of "unacceptable". Is the assessment negated: false.
122+
Target sentiment: negative, target text: service
123+
'negative' assessment sentiment because of "unacceptable". Is the assessment negated: false.
124+
Sentence sentiment: positive, positive score: 0.940000, neutral score: 0.010000, negative score: 0.050000.
125+
Target sentiment: positive, target text: concierge
126+
'positive' assessment sentiment because of "nice". Is the assessment negated: false.
156127
```

articles/cognitive-services/language-service/sentiment-opinion-mining/includes/quickstarts/nodejs-sdk.md

Lines changed: 30 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -69,35 +69,12 @@ const endpoint = '<paste-your-endpoint-here>';
6969
// Authenticate the client with your key and endpoint.
7070
const textAnalyticsClient = new TextAnalyticsClient(endpoint, new AzureKeyCredential(key));
7171

72-
// Example method for detecting sentiment in text.
73-
async function sentimentAnalysis(client){
74-
75-
const sentimentInput = [
76-
"I had the best day of my life. I wish you were there with me."
77-
];
78-
const sentimentResult = await client.analyzeSentiment(sentimentInput);
79-
80-
sentimentResult.forEach(document => {
81-
console.log(`ID: ${document.id}`);
82-
console.log(`\tDocument Sentiment: ${document.sentiment}`);
83-
console.log(`\tDocument Scores:`);
84-
console.log(`\t\tPositive: ${document.confidenceScores.positive.toFixed(2)} \tNegative: ${document.confidenceScores.negative.toFixed(2)} \tNeutral: ${document.confidenceScores.neutral.toFixed(2)}`);
85-
console.log(`\tSentences Sentiment(${document.sentences.length}):`);
86-
document.sentences.forEach(sentence => {
87-
console.log(`\t\tSentence sentiment: ${sentence.sentiment}`)
88-
console.log(`\t\tSentences Scores:`);
89-
console.log(`\t\tPositive: ${sentence.confidenceScores.positive.toFixed(2)} \tNegative: ${sentence.confidenceScores.negative.toFixed(2)} \tNeutral: ${sentence.confidenceScores.neutral.toFixed(2)}`);
90-
});
91-
});
92-
}
93-
sentimentAnalysis(textAnalyticsClient)
94-
95-
// Example method for detecting opinions in text.
72+
// Example method for detecting sentiment and opinions in text.
9673
async function sentimentAnalysisWithOpinionMining(client){
9774

9875
const sentimentInput = [
9976
{
100-
text: "The food and service were unacceptable, but the concierge were nice",
77+
text: "The food and service were unacceptable. The concierge was nice, however.",
10178
id: "0",
10279
language: "en"
10380
}
@@ -141,42 +118,33 @@ sentimentAnalysisWithOpinionMining(textAnalyticsClient);
141118
## Output
142119

143120
```console
144-
ID: 0
145-
Document Sentiment: positive
146-
Document Scores:
147-
Positive: 1.00 Negative: 0.00 Neutral: 0.00
148-
Sentences Sentiment(2):
149-
Sentence sentiment: positive
150-
Sentences Scores:
151-
Positive: 1.00 Negative: 0.00 Neutral: 0.00
152-
Sentence sentiment: neutral
153-
Sentences Scores:
154-
Positive: 0.21 Negative: 0.02 Neutral: 0.77
155-
156121
- Document 0
157-
Document text: The food and service were unacceptable, but the concierge were nice
158-
Overall Sentiment: positive
159-
Sentiment confidence scores: { positive: 0.84, neutral: 0, negative: 0.16 }
160-
Sentences
161-
- Sentence sentiment: positive
162-
Confidence scores: { positive: 0.84, neutral: 0, negative: 0.16 }
163-
Mined opinions
164-
- Target text: food
165-
Target sentiment: negative
166-
Target confidence scores: { positive: 0.01, negative: 0.99 }
167-
Target assessments
168-
- Text: unacceptable
169-
Sentiment: negative
170-
- Target text: service
171-
Target sentiment: negative
172-
Target confidence scores: { positive: 0.01, negative: 0.99 }
173-
Target assessments
174-
- Text: unacceptable
175-
Sentiment: negative
176-
- Target text: concierge
177-
Target sentiment: positive
178-
Target confidence scores: { positive: 1, negative: 0 }
179-
Target assessments
180-
- Text: nice
181-
Sentiment: positive
122+
Document text: The food and service were unacceptable. The concierge was nice, however.
123+
Overall Sentiment: mixed
124+
Sentiment confidence scores: { positive: 0.47, neutral: 0, negative: 0.52 }
125+
Sentences
126+
- Sentence sentiment: negative
127+
Confidence scores: { positive: 0, neutral: 0, negative: 0.99 }
128+
Mined opinions
129+
- Target text: food
130+
Target sentiment: negative
131+
Target confidence scores: { positive: 0, negative: 1 }
132+
Target assessments
133+
- Text: unacceptable
134+
Sentiment: negative
135+
- Target text: service
136+
Target sentiment: negative
137+
Target confidence scores: { positive: 0, negative: 1 }
138+
Target assessments
139+
- Text: unacceptable
140+
Sentiment: negative
141+
- Sentence sentiment: positive
142+
Confidence scores: { positive: 0.94, neutral: 0.01, negative: 0.05 }
143+
Mined opinions
144+
- Target text: concierge
145+
Target sentiment: positive
146+
Target confidence scores: { positive: 1, negative: 0 }
147+
Target assessments
148+
- Text: nice
149+
Sentiment: positive
182150
```

0 commit comments

Comments
 (0)