Code Monkey home page Code Monkey logo

spark-twitter-sentiment-analysis's Introduction

Twitter Sentiment Analysis

This project is about Sentiment Analysis of a desired Twitter topic with Apache Spark Structured Streaming, Apache Kafka, Python and AFINN Module. You can learn sentiment status of a topic that is desired.

For example; you might be curious about Game of Thrones’s new episode and you might get someone’s opinions about this new episode previously. Answer can be NEGATIVE, NEUTRAL or POSITIVE according to opinions.

Code Explanation

  1. Authentication operations were completed with Tweepy module of Python. You must take keys from Twitter API.
  2. StreamListener named TweetListener was create for Twitter Streaming. StreamListener produces data for Kafka Topic named 'twitter'.
  3. StreamListener also calculates Tweets' sentiment value with AFINN module and sends this value to 'twitter' topic.
  4. Producing data was filtered about including desired topic.
  5. Kafka Consumer that consumes data from 'twitter' topic was created.
  6. Also, it converts streaming data to structured data. This structured data is placed into a SQL table named 'data'.
  7. Data table has 2 columns named 'text' and 'senti_val'.
  8. Average of sentiment values of senti_val column is calculated by pyspark.sql.functions.
  9. Also, user defined function named fun is created for status column.
  10. Status column has POSITIVE, NEUTRAL or NEGATIVE that change according to avg(senti_val) column in real-time.

Running

  1. Create Twitter API account and get keys for twitter_config.py
  2. Start Apache Kafka
/bin/kafka-server-start.sh /config/server.properties
  1. Run tweet_listener.py with Python version 3 and desired topic name.
PYSPARK_PYTHON=python3 bin/spark-submit tweet_listener.py "Game of Thrones"
  1. Run twitter_topic_avg_sentiment_val.py with Python version 3.
PYSPARK_PYTHON=python3 bin/spark-submit --packages org.apache.spark:spark-sql-kafka-0-10_2.11:2.1.1 twitter_topic_avg_sentiment_val.py

spark-twitter-sentiment-analysis's People

Contributors

kaantas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spark-twitter-sentiment-analysis's Issues

PYTHON_PYSPARK problem

Run tweet_listener.py with Python version 3 and desired topic name.
PYSPARK_PYTHON=python3 bin/spark-submit tweet_listener.py "Game of Thrones"

Run twitter_topic_avg_sentiment_val.py with Python version 3.
PYSPARK_PYTHON=python3 bin/spark-submit --packages org.apache.spark:spark-sql-kafka-0-10_2.11:2.1.1 twitter_topic_avg_sentiment_val.py

I am new about spark, when i will write PYSPARK_PYTHON=python3 bin/spark-submit tweet_listener.py "Game of Thrones" to command window it isays;

'PYSPARK_PYTHON' is not recognized as an internal or external command,
operable program or batch file.

what should i do about this problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.