Emotion

emotion.predict(data, [params])
Predicts the emotion expressed by an author in a sample of text.

Current Version: 1

Arguments

data – String | List – required – text to be analyzed
[api_key] – String – optional – your indico API key
[cloud] – String – optional – your private cloud subdomain
[v or version] – Integer – optional (defaults to 1) – specify model version
[top_n] – Integer – optional (defaults to 3) – only return this many of the most likely topics
[threshold] – Float – optional (defaults to .0) – only return topics with likelihood greater than this number

Output

This function returns a dictionary that maps from 5 emotions (anger, fear, joy, sadness, surprise) to the probability that the author is expressing the respective emotion.

# single output
{
    'anger': 0.007581704296171665,
    'joy': 0.07016665488481522,
    'fear': 0.8000516295433044,
    'sadness': 0.02512381225824356,
    'surprise': 0.06534374748375202
}

# batch output
[
    {
        'anger': 0.007581704296171665,
        'joy': 0.07016665488481522,
        'fear': 0.8000516295433044,
        'sadness': 0.02512381225824356,
        'surprise': 0.06534374748375202
    },
    {
        'anger': 0.0886223167181015,
        'joy': 0.10006538033485413,
        'fear': 0.1751064658164978,
        'sadness': 0.5425705313682556,
        'surprise': 0.09363535046577454
    }
]

Example

import java.io.File;
import java.util.List;
import java.util.Map;
import io.indico.Indico;
import io.indico.api.text.Emotion;
import java.util.HashMap;

Map params = new HashMap();
params.put("threshold", 0.25)

// single example
Indico indico = new Indico("YOUR_API_KEY");
Map results = indico.emotion.predict("I did it. I got into Grad School. Not just any program, but a GREAT program. :-)", params).getEmotion();
System.out.println(results);

// batch example
String[] example = {
    "I did it. I got into Grad School. Not just any program, but a GREAT program. :-)",
    "Like seriously my life is bleak, I have been unemployed for almost a year."
};
List> batchResults = indico.emotion.predict(example, params).getEmotion();
System.out.println(batchResults);