Emotion

emotion(data, {[api_key]: String, [cloud]: String, [top_n]: Integer, [threshold]: Float})
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

require 'indico'
Indico.api_key =  'YOUR_API_KEY'

# single example
Indico.emotion("I did it. I got into Grad School. Not just any program, but a GREAT program. :-)")

# batch example
Indico.emotion([
    "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."
])