-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
EmotionExtensions.cs
33 lines (32 loc) · 1.31 KB
/
EmotionExtensions.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
using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.CognitiveServices.Vision.Face.Models;
namespace Microsoft.Azure.CognitiveServices.Vision.Face
{
/// <summary>
/// Extension methods for Emotion.
/// </summary>
public static partial class EmotionExtensions
{
/// <summary>
/// Create a sorted key-value pair of emotions and the corresponding scores, sorted from highest score on down.
/// Sorting criteria: Score is the primary key sorted descending, and the name is the secondary key sorted alphabetically.
/// </summary>
public static IEnumerable<KeyValuePair<string, double>> ToRankedList(this Emotion emotionScores)
{
return new Dictionary<string, double>()
{
{ "Anger", emotionScores.Anger },
{ "Contempt", emotionScores.Contempt },
{ "Disgust", emotionScores.Disgust },
{ "Fear", emotionScores.Fear },
{ "Happiness", emotionScores.Happiness },
{ "Neutral", emotionScores.Neutral },
{ "Sadness", emotionScores.Sadness },
{ "Surprise", emotionScores.Surprise }
}
.OrderByDescending(emotion => emotion.Value)
.ThenBy(emotion => emotion.Key);
}
}
}