-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
DocumentSentiment.cs
76 lines (68 loc) · 3 KB
/
DocumentSentiment.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Xml.Linq;
using Azure.AI.TextAnalytics.Models;
namespace Azure.AI.TextAnalytics
{
/// <summary>
/// Overall predicted sentiment and confidence scores for the document.
/// It also includes per-sentence sentiment prediction.
/// <para>For more information regarding text sentiment, see
/// <see href="https://docs.microsoft.com/azure/cognitive-services/Text-Analytics/how-tos/text-analytics-how-to-sentiment-analysis"/>.</para>
/// </summary>
public class DocumentSentiment
{
internal DocumentSentiment(
TextSentiment sentiment,
double positiveScore,
double neutralScore,
double negativeScore,
List<SentenceSentiment> sentenceSentiments,
IList<TextAnalyticsWarning> warnings)
{
Sentiment = sentiment;
ConfidenceScores = new SentimentConfidenceScores(positiveScore, neutralScore, negativeScore);
Sentences = new ReadOnlyCollection<SentenceSentiment>(sentenceSentiments);
Warnings = (warnings is not null)
? new ReadOnlyCollection<TextAnalyticsWarning>(warnings)
: new List<TextAnalyticsWarning>();
}
internal DocumentSentiment(SentimentResponseDocumentsItem documentSentiment)
{
Sentiment = documentSentiment.Sentiment;
ConfidenceScores = documentSentiment.ConfidenceScores;
Sentences = ConvertToSentences(documentSentiment.Sentences);
Warnings = Transforms.ConvertToWarnings(documentSentiment.Warnings);
}
/// <summary>
/// Gets the predicted sentiment for the analyzed document.
/// </summary>
public TextSentiment Sentiment { get; }
/// <summary>
/// Gets the sentiment confidence score (Softmax score) between 0 and 1,
/// for each sentiment. Higher values signify higher confidence.
/// </summary>
public SentimentConfidenceScores ConfidenceScores { get; }
/// <summary>
/// Gets the predicted sentiment and other analysis like Opinion mining
/// for each sentence in the corresponding document.
/// </summary>
public IReadOnlyCollection<SentenceSentiment> Sentences { get; }
/// <summary>
/// Gets the warnings encountered while processing the document.
/// </summary>
public IReadOnlyCollection<TextAnalyticsWarning> Warnings { get; }
private static List<SentenceSentiment> ConvertToSentences(IList<SentenceSentimentInternal> internalSentences)
{
var sentences = new List<SentenceSentiment>();
foreach (var sentence in internalSentences)
{
sentences.Add(new SentenceSentiment(sentence, internalSentences));
}
return sentences;
}
}
}