Skip to content

Lambda architecture code for tweets' sentiment analysis.

Notifications You must be signed in to change notification settings

rickie95/sentimental-lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sentimental-lambda

Lambda architecture code for tweets' sentiment analysis.

In collaboration with Davide Nesi.

Overview

This code is designed to work with Hadoop 2.9.2, Storm 1.2.2, Cassandra 3.11 and LingPipe.

Architecture schema

Insights

Hadoop code

Map (Filter tweets by keyword) -> Map (Assign a sentiment value to each tweet) -> Reduce (count each sentiment).

Usage: Generate the .jar archive, then

hadoop jar artifact-name.jar /input/dir/path /output/dir/path /path/to/lingpipe/classifier.lpc cassandra_ip:port [keyword]

If keyword is entered, only tweets that contains keyword will be counted.

Storm code

  1. HdfsSpout (Read files from HDFS)
  2. TweetRecorder (Classifies tweets)
  3. CassandaBolt (Counts sentiments and save them in Cassandra DB)

Usage: Generate the .jar archive, then start the topology:

storm jar artifact-name.jar org.apache.storm.TweetTopology /path/to/lingpipe/classifier.lpc cassandra.db.ip.address:port [keyword]

If keyword is entered, only tweets that contains keyword will be counted.

Cassandra details

Below the code for create the schemas in the database.

DDL First, create the workspace:

CREATE KEYSPACE SentimentAnalysis WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 3 }; USE SentimentAnalysis;

Then proceed to create Hadoop tables

CREATE TABLE positives ( timestmp timestamp, keyword varchar, count bigint, PRIMARY KEY (keyword, timestmp) ) WITH CLUSTERING ORDER BY (timestmp DESC);

CREATE TABLE negatives ( timestmp timestamp, keyword varchar, count bigint, PRIMARY KEY (keyword, timestmp) ) WITH CLUSTERING ORDER BY (timestmp DESC);

CREATE TABLE neutrals ( timestmp timestamp, keyword varchar, count bigint, PRIMARY KEY (keyword, timestmp) ) WITH CLUSTERING ORDER BY (timestmp DESC);

Last, Storm tables:

CREATE TABLE storm_queries ( timestmp timestamp, keyword varchar, positive bigint, negative bigint, neutral bigint, PRIMARY KEY (keyword, timestmp) ) WITH CLUSTERING ORDER BY (timestmp DESC);

Use CassandraDriver's methods for insert.

Credits

About

Lambda architecture code for tweets' sentiment analysis.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages