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

Commit

Permalink
Merge pull request #40 from ccasbre27/master
Browse files Browse the repository at this point in the history
Function to get the expressions in a collection (ordered) - Android
  • Loading branch information
lightfrenzy committed May 17, 2016
2 parents 78a0a17 + 437515f commit 3615923
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public enum Order {
ASCENDING,DESCENDING
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
//
package com.microsoft.projectoxford.emotion.contract;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Scores {
public double anger;
public double contempt;
Expand All @@ -41,4 +49,54 @@ public class Scores {
public double neutral;
public double sadness;
public double surprise;

public List<Map.Entry<String, Double>> ToRankedList(Order order)
{

// create a Map to store each entry
Map<String, Double> collection = new HashMap<String, Double>() ;

// add each entry with its own key and value
collection.put("ANGER",anger);
collection.put("CONTEMPT",contempt);
collection.put("DISGUST",disgust);
collection.put("FEAR",fear);
collection.put("HAPPINESS",happiness);
collection.put("NEUTRAL",neutral);
collection.put("SADNESS",sadness);
collection.put("SURPRISE",surprise);

// create a list with the entries
List<Map.Entry<String, Double>> list = new ArrayList<Map.Entry<String, Double>>(collection.entrySet());

// we are going to create a comparator according to the value of the enum order
switch (order)
{
case ASCENDING:
Collections.sort(list, new Comparator<Map.Entry<String, Double>>() {
@Override
public int compare(Entry<String, Double> first, Entry<String, Double> second) {
// we should compare the value of the first entry and the value of the second entry
return first.getValue().compareTo(second.getValue());
}
});
break;

case DESCENDING:
// for ordering descending we should create a reverse order comparator
Collections.sort(list, Collections.reverseOrder(new Comparator<Map.Entry<String, Double>>() {
@Override
public int compare(Entry<String, Double> first, Entry<String, Double> second) {
return first.getValue().compareTo(second.getValue());
}
}));
break;

default:
break;
}

return list;

}
}
16 changes: 16 additions & 0 deletions Emotion/Android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,22 @@ To do add the client library dependency from Android Studio:
6. Type "com.microsoft.projectoxford" and hit the search icon from "Choose Library Dependency" dialog
7. Pick the Project Oxford client library that you intend to use.
8. Click "OK" to add the new dependency

Order expressions
============

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

ASCENDING
```
List<Map.Entry<String, Double>> collection = scores.ToRankedList(Order.ASCENDING);
```

DESCENDING
```
List<Map.Entry<String, Double>> collection = scores.ToRankedList(Order.DESCENDING);
```

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

If you want to know what is the name of the expression with more value then you might call getExpressionName() from the Score class

Contributing
============
We welcome contributions and are always looking for new SDKs, input, and
Expand Down
9 changes: 9 additions & 0 deletions Emotion/Windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ The easiest way to use this client library is to get microsoft.projectoxford.emo

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

Order expressions
============

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

```
IEnumerable<KeyValuePair<string, float>> collection = myScores.ToRankedList();
```

The sample
==========

Expand Down

0 comments on commit 3615923

Please sign in to comment.