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.
Usage
To use the API, simply
POST to this web page, with a parameter named text containing
the text you'd like to analyze...
If you're planning on making heavy use of the API, please set it up on your own server.
Contact me for the source code or with any other questions.
Well, sure enough, somebody (more specificaly, someone working for Joyent on a site at yhtidebo.joyent.us) decided to make heavy use of my hosted version of this API without contacting me, so in order to use the EmoTe API from now on, you must download it from GitHub and install it on your own server. If you try to use my hosted version, you will always get the same response back, warning you to stop hogging resources as Joyent did.
After installing, analyzing text will return 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
}
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)