Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit 3615923

Browse files
committed
Merge pull request #40 from ccasbre27/master
Function to get the expressions in a collection (ordered) - Android
2 parents 78a0a17 + 437515f commit 3615923

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public enum Order {
2+
ASCENDING,DESCENDING
3+
}

Emotion/Android/ClientLibrary/lib/src/main/java/com/microsoft/projectoxford/emotion/contract/Scores.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
//
3333
package com.microsoft.projectoxford.emotion.contract;
3434

35+
import java.util.ArrayList;
36+
import java.util.Collections;
37+
import java.util.Comparator;
38+
import java.util.HashMap;
39+
import java.util.List;
40+
import java.util.Map;
41+
import java.util.Map.Entry;
42+
3543
public class Scores {
3644
public double anger;
3745
public double contempt;
@@ -41,4 +49,54 @@ public class Scores {
4149
public double neutral;
4250
public double sadness;
4351
public double surprise;
52+
53+
public List<Map.Entry<String, Double>> ToRankedList(Order order)
54+
{
55+
56+
// create a Map to store each entry
57+
Map<String, Double> collection = new HashMap<String, Double>() ;
58+
59+
// add each entry with its own key and value
60+
collection.put("ANGER",anger);
61+
collection.put("CONTEMPT",contempt);
62+
collection.put("DISGUST",disgust);
63+
collection.put("FEAR",fear);
64+
collection.put("HAPPINESS",happiness);
65+
collection.put("NEUTRAL",neutral);
66+
collection.put("SADNESS",sadness);
67+
collection.put("SURPRISE",surprise);
68+
69+
// create a list with the entries
70+
List<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(collection.entrySet());
71+
72+
// we are going to create a comparator according to the value of the enum order
73+
switch (order)
74+
{
75+
case ASCENDING:
76+
Collections.sort(list, new Comparator<Map.Entry<String, Double>>() {
77+
@Override
78+
public int compare(Entry<String, Double> first, Entry<String, Double> second) {
79+
// we should compare the value of the first entry and the value of the second entry
80+
return first.getValue().compareTo(second.getValue());
81+
}
82+
});
83+
break;
84+
85+
case DESCENDING:
86+
// for ordering descending we should create a reverse order comparator
87+
Collections.sort(list, Collections.reverseOrder(new Comparator<Map.Entry<String, Double>>() {
88+
@Override
89+
public int compare(Entry<String, Double> first, Entry<String, Double> second) {
90+
return first.getValue().compareTo(second.getValue());
91+
}
92+
}));
93+
break;
94+
95+
default:
96+
break;
97+
}
98+
99+
return list;
100+
101+
}
44102
}

Emotion/Android/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,22 @@ To do add the client library dependency from Android Studio:
3131
6. Type "com.microsoft.projectoxford" and hit the search icon from "Choose Library Dependency" dialog
3232
7. Pick the Project Oxford client library that you intend to use.
3333
8. Click "OK" to add the new dependency
34+
35+
Order expressions
36+
============
3437

38+
You can call the function ToRankedList from the Scores class, for example:
3539

40+
ASCENDING
41+
```
42+
List<Map.Entry<String, Double>> collection = scores.ToRankedList(Order.ASCENDING);
43+
```
44+
45+
DESCENDING
46+
```
47+
List<Map.Entry<String, Double>> collection = scores.ToRankedList(Order.DESCENDING);
48+
49+
```
3650

3751
The sample
3852
==========
@@ -79,6 +93,8 @@ Microsoft will receive the images you upload and may use them to improve Emotion
7993
API and related services. By submitting an image, you confirm you have consent
8094
from everyone in it.
8195

96+
If you want to know what is the name of the expression with more value then you might call getExpressionName() from the Score class
97+
8298
Contributing
8399
============
84100
We welcome contributions and are always looking for new SDKs, input, and

Emotion/Windows/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ The easiest way to use this client library is to get microsoft.projectoxford.emo
88

99
Please go to [Emotion API Package in nuget](https://www.nuget.org/packages/Microsoft.ProjectOxford.Emotion/) for more details.
1010

11+
Order expressions
12+
============
13+
14+
You can call the function ToRankedList from the Scores class, for example:
15+
16+
```
17+
IEnumerable<KeyValuePair<string, float>> collection = myScores.ToRankedList();
18+
```
19+
1120
The sample
1221
==========
1322

0 commit comments

Comments
 (0)