| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Linq; |
| | 3 | | using Microsoft.Azure.CognitiveServices.Vision.Face.Models; |
| | 4 | |
|
| | 5 | | namespace Microsoft.Azure.CognitiveServices.Vision.Face |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// Extension methods for Emotion. |
| | 9 | | /// </summary> |
| | 10 | | public static partial class EmotionExtensions |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Create a sorted key-value pair of emotions and the corresponding scores, sorted from highest score on down. |
| | 14 | | /// Sorting criteria: Score is the primary key sorted descending, and the name is the secondary key sorted alpha |
| | 15 | | /// </summary> |
| | 16 | | public static IEnumerable<KeyValuePair<string, double>> ToRankedList(this Emotion emotionScores) |
| | 17 | | { |
| 4 | 18 | | return new Dictionary<string, double>() |
| 4 | 19 | | { |
| 4 | 20 | | { "Anger", emotionScores.Anger }, |
| 4 | 21 | | { "Contempt", emotionScores.Contempt }, |
| 4 | 22 | | { "Disgust", emotionScores.Disgust }, |
| 4 | 23 | | { "Fear", emotionScores.Fear }, |
| 4 | 24 | | { "Happiness", emotionScores.Happiness }, |
| 4 | 25 | | { "Neutral", emotionScores.Neutral }, |
| 4 | 26 | | { "Sadness", emotionScores.Sadness }, |
| 4 | 27 | | { "Surprise", emotionScores.Surprise } |
| 4 | 28 | | } |
| 36 | 29 | | .OrderByDescending(emotion => emotion.Value) |
| 32 | 30 | | .ThenBy(emotion => emotion.Key); |
| | 31 | | } |
| | 32 | | } |
| | 33 | | } |