Analysing emojis can uncover meaning and sentiment in ways regular text analytics cannot. So this was the main idea to introduce sentiment data into the Emoji-Heatmapper app. LokLak Search API has features such as classification and categorization of tweets. The emotions, for instance, can be joy, anticipation, sad etc.
So, in the Emoji-heatmapper app, I am displaying the occurrence of emojis on the map according to the location traced and also the sentiment related to the emoji i.e., search query as follows:
How to get the sentiment data:
One should simply enter the emoji into the search box for the results. The following code shows part of the LokLak Search API results (JSONObject):
"hashtags_count": 0, "classifier_emotion": "anger", "classifier_emotion_probability": 1.2842921170985733E-9, "classifier_language": "english", "classifier_language_probability": 1.4594549568869297E-8, "without_l_len": 49, "without_lu_len": 49, "without_luh_len": 49,
I am using the above field name ”classifier_emotion” to display the results.
Till here getting the data relevant to query part is done. Next, the classifier_emotion of each tweet containing the query is collected into an array and sorted to get a unique list.
var emotion = []; var emotions_array = []; for (var i = 0; i < tweets.statuses.length; i++) { if (tweets.statuses[i].classifier_emotion) { emotion = tweets.statuses[i].classifier_emotion; emotions_array.push(emotion); } emotions_array.sort(); emotion_array = jQuery.unique( emotions_array );
Loading the Sentiment data onto the Screen
When the query has a single emotion, or if multiple emotions or no emotions. These use cases/situations are displayed as follows:
Fig: Single Emotion
Fig: Multiple Emotions
Fig: No Emotions data
The code which creates the data dynamically on the output screen is as follows:
//Loading the sentiment $(document).ready(function() { var listItems= ""; if (emotions_array.length == 0) { listItems = "No Sentiment data is available for " + query } if (emotion_array.length == 1) { listItems += "<h3> Sentiment of " + query + " is "; } else if (emotion_array.length > 1) { listItems += "<h3> Sentiments of " + query + " are "; } var emotion_data = emotion_array.join(", ") + "." listItems += emotion_data + "</h3>" $("#sentiment").html(listItems); });
Conclusion
The Emoji-Heatmapper app displays the sentiment data of the query being searched for which populates data dynamically using LokLak Search API.
Resources
- Emoji-Heatmapper App, try it out here: http://apps.loklak.org/emojiHeatmapper/
- Source Code: https://github.com/fossasia/apps.loklak.org/tree/master/emojiHeatmapper
- Search API: http://api.loklak.org/