SlideShare a Scribd company logo
Realtime Tweet Analysis with 
PubNub Data Stream 
Tomomi Imura
"How is America feeling now?" 
Visualized cartographic data of the emotional "state" of each state at 
any given moment 
2
http://pubnub.github.io/tweet-emotion/ 
3
Pseudo-analysis 
Positive or negative sentiments are loosely determined based on an 
analysis of keywords used in tweets 
positiveWords = [ 
'excellent', 'amazing', 'marvelous', 'magnificent', 
'fabulous', 'astonishing', 'fantastic', 'peaceful', 
'brilliant', 'glorious', 'cheerful', 'gracious', 
... 
]; 
4
Process 
1. using TopoJSON to display a US state map using d3.js 
2. using PubNub JavaScript API to consume Twitter stream 
3. colorizing the map by moods 
5
GeoJSON 
• Open standard format for encoding geographical features 
• Written in JavaScript Object Notation 
• Typically large file size 
6
TopoJSON 
• Extension of GeoJSON that encodes geospatial topology 
• Compressed / Smaller size 
• Tailored for only what you need 
7
TopoJSON 
8
Render TopoJSON with D3.js 
var svg = d3.select('#map').append('svg') 
.attr('width', 900).attr('height', 550); 
var path = d3.geo.path().projection(d3.geo.albersUsa()); 
9
Render TopoJSON with D3.js 
var g = svg.append('g'); 
d3.json('us-states.json', function(error, topology) { 
g.selectAll('path') 
.data(topojson.feature(topology, 
topology.objects.usStates).features) 
.enter().append('path') 
.attr('class', function(d){ 
return 'states ' + d.properties.STATE_ABBR;} ) 
.attr('d', path) 
.attr('fill', 'gray') 
}); 10
Getting Realtime Tweets from 
PubNub Stream 
11
Getting Started with PubNub APIs 
01. 
<script src="//cdn.pubnub.com/pubnub.min.js"></script> 
02. 
var channel = 'pubnub-twitter'; 
var pubnub = PUBNUB.init({ 
subscribe_key:'sub-c-78806dd4-42a6-11e4-aed8-02ee2ddab7fe' 
}); 
12
Receiving Live JSON Data 
To retrieve the live tweets, you simply use PubNub subscribe() 
API. 
pubnub.subscribe({ 
channel: channel, 
callback: processData 
}); 
13
Pseudoanalyze Tweets 
Create a mini dictionary that describes moods 
var positiveWords = [ 
'excellent', 'amazing', 'happy', 'magnificent', ':)', 
... 
]; 
var negativeWords = [ 
'unhappy', 'sorry', 'annoyed', 'dislike', 'anxious', ':(', 
... 
]; 
14
Pseudoanalyze Tweets 
See if these words are used in each tweet, in the callback function 
function processData(data) { 
// looking for US data only for this demo 
if(data.place.country_code !== 'US') return; 
// Check if emotional words are used in the tweet 
if (positiveWords.some(function(v) { 
return data.text.toLowerCase().indexOf(v) > 0; })) { 
displayData(data, positive); 
} else if 
... 
15 
}
Pseudoanalyze Tweets 
Create a mini dictionary that describes moods 
var positiveWords = [ 
'excellent', 'amazing', 'happy', 'magnificent', ':)', 
... 
]; 
var negativeWords = [ 
'unhappy', 'sorry', 'annoyed', 'dislike', 'anxious', ':(', 
... 
]; 
16
Display Data on Map 
function displayData(data, emotion) { 
var state = data.place.full_name.substring( 
city.lastIndexOf(',')+1).trim(); 
if(document.querySelector('.'+state)) { 
var stateEl = document.querySelector('.'+state); 
// count 
tally[state] = (tally[state] || {positive:0, negative:0}); 
tally[state][emotion] = (tally[state][emotion] || 0) + 1; 
... 
17
...cont'd 
// colorize svg path 
stateEl.style.fill = ( 
tally[state].positive > tally[state].negative) 
? 'pink' : 
((tally[state].positive < tally[state].negative) 
? 'turquoise' : 'beige'); 
} 
} 
} 
18
19
Full Article 
 blog.twitter.com 
20
Thank you! 
Tomomi Imura @ PubNub 
 pubnub.com 
 @pubnub 
 @girlie_mac 
 github.com/pubnub 
21
Photo Credit 
• Cover: https://flic.kr/p/9id7d9 by Kate Ter Haar b 
22

More Related Content

More from Tomomi Imura

ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
Tomomi Imura
 
[POST.Dev Japan] VS Code で試みる開発体験の向上
[POST.Dev Japan] VS Code で試みる開発体験の向上[POST.Dev Japan] VS Code で試みる開発体験の向上
[POST.Dev Japan] VS Code で試みる開発体験の向上
Tomomi Imura
 
[Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう!
[Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう![Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう!
[Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう!
Tomomi Imura
 
[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience
[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience
[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience
Tomomi Imura
 
Engineering career is not a single ladder! - Alternative pathway to develope...
Engineering career is not a single ladder!  - Alternative pathway to develope...Engineering career is not a single ladder!  - Alternative pathway to develope...
Engineering career is not a single ladder! - Alternative pathway to develope...
Tomomi Imura
 
Being a Tech Speaker with Global Mindset
Being a Tech Speaker with Global MindsetBeing a Tech Speaker with Global Mindset
Being a Tech Speaker with Global Mindset
Tomomi Imura
 
#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)
#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)
#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)
Tomomi Imura
 
Slack × Twilio - Uniquely Powering Communication
Slack × Twilio - Uniquely Powering CommunicationSlack × Twilio - Uniquely Powering Communication
Slack × Twilio - Uniquely Powering Communication
Tomomi Imura
 
[2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func...
 [2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func... [2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func...
[2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func...
Tomomi Imura
 
[2019 south bay meetup] Building more contextual message with Block Kit
[2019 south bay meetup] Building more contextual message with Block Kit[2019 south bay meetup] Building more contextual message with Block Kit
[2019 south bay meetup] Building more contextual message with Block Kit
Tomomi Imura
 
[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...
[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...
[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...
Tomomi Imura
 
Building a Bot with Slack Platform and IBM Watson
Building a Bot with Slack Platform and IBM WatsonBuilding a Bot with Slack Platform and IBM Watson
Building a Bot with Slack Platform and IBM Watson
Tomomi Imura
 
[日本語] Slack Bot Workshop + Intro Block Kit
[日本語] Slack Bot Workshop + Intro Block Kit[日本語] Slack Bot Workshop + Intro Block Kit
[日本語] Slack Bot Workshop + Intro Block Kit
Tomomi Imura
 
[DevRelCon Tokyo 2019] Developer Experience Matters
[DevRelCon Tokyo 2019] Developer Experience Matters [DevRelCon Tokyo 2019] Developer Experience Matters
[DevRelCon Tokyo 2019] Developer Experience Matters
Tomomi Imura
 
[DevRel Summit 2018] Because we all learn things differently
[DevRel Summit 2018] Because we all learn things differently[DevRel Summit 2018] Because we all learn things differently
[DevRel Summit 2018] Because we all learn things differently
Tomomi Imura
 
[DevRelCon July 2018] Because we all learn things differently
[DevRelCon July 2018] Because we all learn things differently[DevRelCon July 2018] Because we all learn things differently
[DevRelCon July 2018] Because we all learn things differently
Tomomi Imura
 
[Japanese] Developing a bot for your workspace 翻訳ボットを作る!
[Japanese] Developing a bot for your workspace 翻訳ボットを作る![Japanese] Developing a bot for your workspace 翻訳ボットを作る!
[Japanese] Developing a bot for your workspace 翻訳ボットを作る!
Tomomi Imura
 
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi [Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
Tomomi Imura
 
Future of the Web with Conversational Interface
Future of the Web with Conversational InterfaceFuture of the Web with Conversational Interface
Future of the Web with Conversational Interface
Tomomi Imura
 
[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...
[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...
[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...
Tomomi Imura
 

More from Tomomi Imura (20)

ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
 
[POST.Dev Japan] VS Code で試みる開発体験の向上
[POST.Dev Japan] VS Code で試みる開発体験の向上[POST.Dev Japan] VS Code で試みる開発体験の向上
[POST.Dev Japan] VS Code で試みる開発体験の向上
 
[Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう!
[Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう![Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう!
[Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう!
 
[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience
[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience
[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience
 
Engineering career is not a single ladder! - Alternative pathway to develope...
Engineering career is not a single ladder!  - Alternative pathway to develope...Engineering career is not a single ladder!  - Alternative pathway to develope...
Engineering career is not a single ladder! - Alternative pathway to develope...
 
Being a Tech Speaker with Global Mindset
Being a Tech Speaker with Global MindsetBeing a Tech Speaker with Global Mindset
Being a Tech Speaker with Global Mindset
 
#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)
#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)
#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)
 
Slack × Twilio - Uniquely Powering Communication
Slack × Twilio - Uniquely Powering CommunicationSlack × Twilio - Uniquely Powering Communication
Slack × Twilio - Uniquely Powering Communication
 
[2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func...
 [2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func... [2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func...
[2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func...
 
[2019 south bay meetup] Building more contextual message with Block Kit
[2019 south bay meetup] Building more contextual message with Block Kit[2019 south bay meetup] Building more contextual message with Block Kit
[2019 south bay meetup] Building more contextual message with Block Kit
 
[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...
[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...
[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...
 
Building a Bot with Slack Platform and IBM Watson
Building a Bot with Slack Platform and IBM WatsonBuilding a Bot with Slack Platform and IBM Watson
Building a Bot with Slack Platform and IBM Watson
 
[日本語] Slack Bot Workshop + Intro Block Kit
[日本語] Slack Bot Workshop + Intro Block Kit[日本語] Slack Bot Workshop + Intro Block Kit
[日本語] Slack Bot Workshop + Intro Block Kit
 
[DevRelCon Tokyo 2019] Developer Experience Matters
[DevRelCon Tokyo 2019] Developer Experience Matters [DevRelCon Tokyo 2019] Developer Experience Matters
[DevRelCon Tokyo 2019] Developer Experience Matters
 
[DevRel Summit 2018] Because we all learn things differently
[DevRel Summit 2018] Because we all learn things differently[DevRel Summit 2018] Because we all learn things differently
[DevRel Summit 2018] Because we all learn things differently
 
[DevRelCon July 2018] Because we all learn things differently
[DevRelCon July 2018] Because we all learn things differently[DevRelCon July 2018] Because we all learn things differently
[DevRelCon July 2018] Because we all learn things differently
 
[Japanese] Developing a bot for your workspace 翻訳ボットを作る!
[Japanese] Developing a bot for your workspace 翻訳ボットを作る![Japanese] Developing a bot for your workspace 翻訳ボットを作る!
[Japanese] Developing a bot for your workspace 翻訳ボットを作る!
 
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi [Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
 
Future of the Web with Conversational Interface
Future of the Web with Conversational InterfaceFuture of the Web with Conversational Interface
Future of the Web with Conversational Interface
 
[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...
[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...
[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...
 

Recently uploaded

06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
vikram sood
 
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
GetInData
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
74nqk8xf
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
haila53
 
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Subhajit Sahu
 
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdfUnleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Enterprise Wired
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptxData_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
AnirbanRoy608946
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
Roger Valdez
 
Adjusting OpenMP PageRank : SHORT REPORT / NOTES
Adjusting OpenMP PageRank : SHORT REPORT / NOTESAdjusting OpenMP PageRank : SHORT REPORT / NOTES
Adjusting OpenMP PageRank : SHORT REPORT / NOTES
Subhajit Sahu
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
jerlynmaetalle
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Subhajit Sahu
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
roli9797
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
Subhajit Sahu
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
u86oixdj
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
manishkhaire30
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
v3tuleee
 

Recently uploaded (20)

06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
 
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdfEnhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
Enhanced Enterprise Intelligence with your personal AI Data Copilot.pdf
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
 
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
Levelwise PageRank with Loop-Based Dead End Handling Strategy : SHORT REPORT ...
 
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdfUnleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
Unleashing the Power of Data_ Choosing a Trusted Analytics Platform.pdf
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptxData_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
 
Adjusting OpenMP PageRank : SHORT REPORT / NOTES
Adjusting OpenMP PageRank : SHORT REPORT / NOTESAdjusting OpenMP PageRank : SHORT REPORT / NOTES
Adjusting OpenMP PageRank : SHORT REPORT / NOTES
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
 

Tweet emotion: real-time Tweet analysis with PubNub Data Stream

  • 1. Realtime Tweet Analysis with PubNub Data Stream Tomomi Imura
  • 2. "How is America feeling now?" Visualized cartographic data of the emotional "state" of each state at any given moment 2
  • 4. Pseudo-analysis Positive or negative sentiments are loosely determined based on an analysis of keywords used in tweets positiveWords = [ 'excellent', 'amazing', 'marvelous', 'magnificent', 'fabulous', 'astonishing', 'fantastic', 'peaceful', 'brilliant', 'glorious', 'cheerful', 'gracious', ... ]; 4
  • 5. Process 1. using TopoJSON to display a US state map using d3.js 2. using PubNub JavaScript API to consume Twitter stream 3. colorizing the map by moods 5
  • 6. GeoJSON • Open standard format for encoding geographical features • Written in JavaScript Object Notation • Typically large file size 6
  • 7. TopoJSON • Extension of GeoJSON that encodes geospatial topology • Compressed / Smaller size • Tailored for only what you need 7
  • 9. Render TopoJSON with D3.js var svg = d3.select('#map').append('svg') .attr('width', 900).attr('height', 550); var path = d3.geo.path().projection(d3.geo.albersUsa()); 9
  • 10. Render TopoJSON with D3.js var g = svg.append('g'); d3.json('us-states.json', function(error, topology) { g.selectAll('path') .data(topojson.feature(topology, topology.objects.usStates).features) .enter().append('path') .attr('class', function(d){ return 'states ' + d.properties.STATE_ABBR;} ) .attr('d', path) .attr('fill', 'gray') }); 10
  • 11. Getting Realtime Tweets from PubNub Stream 11
  • 12. Getting Started with PubNub APIs 01. <script src="//cdn.pubnub.com/pubnub.min.js"></script> 02. var channel = 'pubnub-twitter'; var pubnub = PUBNUB.init({ subscribe_key:'sub-c-78806dd4-42a6-11e4-aed8-02ee2ddab7fe' }); 12
  • 13. Receiving Live JSON Data To retrieve the live tweets, you simply use PubNub subscribe() API. pubnub.subscribe({ channel: channel, callback: processData }); 13
  • 14. Pseudoanalyze Tweets Create a mini dictionary that describes moods var positiveWords = [ 'excellent', 'amazing', 'happy', 'magnificent', ':)', ... ]; var negativeWords = [ 'unhappy', 'sorry', 'annoyed', 'dislike', 'anxious', ':(', ... ]; 14
  • 15. Pseudoanalyze Tweets See if these words are used in each tweet, in the callback function function processData(data) { // looking for US data only for this demo if(data.place.country_code !== 'US') return; // Check if emotional words are used in the tweet if (positiveWords.some(function(v) { return data.text.toLowerCase().indexOf(v) > 0; })) { displayData(data, positive); } else if ... 15 }
  • 16. Pseudoanalyze Tweets Create a mini dictionary that describes moods var positiveWords = [ 'excellent', 'amazing', 'happy', 'magnificent', ':)', ... ]; var negativeWords = [ 'unhappy', 'sorry', 'annoyed', 'dislike', 'anxious', ':(', ... ]; 16
  • 17. Display Data on Map function displayData(data, emotion) { var state = data.place.full_name.substring( city.lastIndexOf(',')+1).trim(); if(document.querySelector('.'+state)) { var stateEl = document.querySelector('.'+state); // count tally[state] = (tally[state] || {positive:0, negative:0}); tally[state][emotion] = (tally[state][emotion] || 0) + 1; ... 17
  • 18. ...cont'd // colorize svg path stateEl.style.fill = ( tally[state].positive > tally[state].negative) ? 'pink' : ((tally[state].positive < tally[state].negative) ? 'turquoise' : 'beige'); } } } 18
  • 19. 19
  • 20. Full Article  blog.twitter.com 20
  • 21. Thank you! Tomomi Imura @ PubNub  pubnub.com  @pubnub  @girlie_mac  github.com/pubnub 21
  • 22. Photo Credit • Cover: https://flic.kr/p/9id7d9 by Kate Ter Haar b 22