/Contextual-Twit

A React web application designed to provide insights using sentimental analysis of Tweets.

Primary LanguageJavaScript

Contextual Twit

Summary

Contextual Twit is a tool that can get the most recent tweets by any topic and help you find insight with sentiment analysis. With this app, the user can see trending topics on Twitter. Users can also search Tweets by query and the app will display an visualized sentiment analysis powered by IBM Watson and VADER Sentiment. This app can help companies and individuals for marketing research, development, etc. Visit the application HERE.

Site

Technologies Used

  • CSS - used to style an HTML document
  • Javascript - adds special effects on pages
  • Node.js - an open source server environment that uses JavaScript on the server
  • Express - a Node.js web application framework that provides a robust set of features for web and mobile applications.
  • MongoDB - stores data in JSON-like documents.
  • Mongoose - Used with MongoDB
  • dotenv - used for hidding API keys
  • bcrypt - Used for encrypting passwords
  • React - a JavaScript library for building user interfaces
  • React Promise tracker - Used to track a promise and wait until it is resolved
  • React-Loader-Spinner - Used on the client side to render a loading icon while a promise is resolved
  • React-flexible-sliding-menu - Used to create the toggle menu
  • Chart.js - allows you to easily make graphs to display data
  • Twitter API v1.1 - returns a collection of relevant Tweets matching a specified query
  • VADER Setiment - sentiment analysis tool that is specifically attuned to sentiments expressed in social media
  • Watson Tone Analyzer - IBM's AI powered linguistic analysis tool for detecting emotional and language tones in written text
  • GitBash - for cloning repository and pushing code to GitHub
  • GitHub - holds repository that deploys to GitHub Pages

Code Snippet

The following diagram and code snippet show how tweets are fetched and analyized for sentiment data.

API DIAGRAM

// Get Tweets
getTwits: function (req, res) {
    client.get('search/tweets', { q: `${req.body.thekey}`, lang: 'en', count: 50 }, function (error, tweets, response) {

        const data = [];
        const toneChatParams = { utterances: [] };

        tweets.statuses.forEach(function (tweet) {
            toneChatParams.utterances.push({
                text: tweet.text.replace(/(\r\n|\n|\r)/gm, " "),
            });
        });

        // Watson-Sentiment
        toneAnalyzer.toneChat(toneChatParams)
        .then(utteranceAnalyses => {
            for (let i = 0; i < tweets.statuses.length; i++) {

            // Vader-Sentiment
            let intensity = vader.SentimentIntensityAnalyzer.polarity_scores(toneChatParams.utterances[i].text);

            if (toneChatParams.utterances[i].text === utteranceAnalyses.result.utterances_tone[i].utterance_text) {
                data.push({
                id: i,
                created_at: tweets.statuses[i].created_at,
                id_str: tweets.statuses[i].id_str,
                screen_name: tweets.statuses[i].user.screen_name,
                followers_count: tweets.statuses[i].user.followers_count,
                user_verified: tweets.statuses[i].user.verified,
                is_quote_status: tweets.statuses[i].is_quote_status,
                retweet_count: tweets.statuses[i].retweet_count,
                favorite_count: tweets.statuses[i].favorite_count,
                hashtags: tweets.statuses[i].entities.hashtags,
                lang: tweets.statuses[i].lang,
                text: utteranceAnalyses.result.utterances_tone[i].utterance_text,
                watson_tones: utteranceAnalyses.result.utterances_tone[i].tones,
                vader_intensity: intensity
                });
            } else {
                data.push({
                id: i,
                created_at: tweets.statuses[i].created_at,
                id_str: tweets.statuses[i].id_str,
                screen_name: tweets.statuses[i].user.screen_name,
                followers_count: tweets.statuses[i].user.followers_count,
                user_verified: tweets.statuses[i].user.verified,
                is_quote_status: tweets.statuses[i].is_quote_status,
                retweet_count: tweets.statuses[i].retweet_count,
                favorite_count: tweets.statuses[i].favorite_count,
                hashtags: tweets.statuses[i].entities.hashtags,
                lang: tweets.statuses[i].lang,
                text: toneChatParams.utterances[i].text,
                watson_tones: [],
                vader_intensity: intensity
                });
            };
            };
            res.json(data)// <=== Data to deliver here!
        })
        .catch(err => {
            console.log('error:', err);
        });
    })
}

Author Links

Mark Khoo
Linkedin
Github

Javier Mondragon
Linkedin
Github

Manuel Villasenor
LinkedIn
GitHub

Rosario Miranda
LinkedIn
GitHub