Emotive Text (EmoTe) API
The EmoTe API is a web service which calculates the various types and levels of emotions in a given passage of text. It is a partial PHP port of the Synesketch Java API, focusing on the synesketch.emotion package. It is currently a little rough around the edges and could use some refactoring, but it works. If you'd like to help out, head on over to EmoTe on GitHub.
Usage
To use the API, simply POST to this web page, with a parameter named text containing
the text you'd like to analyze. The server will return you a JSON-encoded response of the form:
{
"generalWeight": weight //number between zero and one
, "valence": valence //-1, 0, or 1
, "previous": null //always null (artifact from synsesketch)
, "emotions": [ //an array of emotion objects
{
"weight": emotionWeight //number between zero and one
,"type": emotionType //the emotion type (see list below)
}
, {
"weight": emotionWeight //number between zero and one
,"type": emotionType //the emotion type (see below)
}
]
,"text": originalTextProcessed
}
If you're planning on making heavy use of the API, please set it up on your own server. You can find the source code on GitHub.
How it works
The phrase, sentence, or passage will have a general valence (ie., is it positive or negative?) and a general weight as to how strong the overall emotion is. The phrase will also have a series of emotions associated with it, each with their own weights.
Weights are on a 0-1 scale. A weight closer to zero means that the emotion is very weak, whereas a weight of one indicates that the emotion is very strong in that text. Weights are assigned to the general valence of the text, as well as to each individual emotion present in the text.
The codes for the emotions are as follows:
- -1
- Neutral
- 0
- Happiness
- 1
- Sadness
- 2
- Fear
- 3
- Anger
- 4
- Disgust
- 5
- Surprise
Test it out
- The lyrics to Nine Inch Nails' song "Hurt" (happiness, fear, and anger with a strong negative valence)
- Excerpt from Martin Luther King Jr.'s "I Have a Dream" speech (happiness, anger, and surprise)
- Excerpt from Hamlet (slight happiness, slight sadness, weak general negative valence)
- A brief explanation of Derivatives (very weak fear, very weak general negative valence)
- Twinkle Twinkle Little Star (surprise, strong positive general valence)