SlideShare ist ein Scribd-Unternehmen logo
1 von 124
Downloaden Sie, um offline zu lesen
Sentiment Analysis of
the Twittersphere
Leiningen Versus the Ants!
Clojure Versus Java!
FP Versus OOP
Leiningen Versus the Ants!
Clojure Versus Java!
FP Versus OOP
Apache Ant
Leiningen Versus the Ants
Clojure Versus Java!
FP Versus OOP
Apache Ant
Leiningen Versus the Ants
Clojure Versus Java
Functional Versus Object Oriented
Apache Ant
Blood aches pain
sick shivers spasm
vomit dizzy fainting
colic and in a
coma!
1 FAVORITE
Blood aches pain
sick shivers spasm
vomit dizzy fainting
colic and in a
coma!
1 FAVORITE
Scores HIGH for flu symptoms
Blood aches pain
sick shivers spasm
vomit dizzy fainting
colic and in a
coma!
1 FAVORITE
Who is Catalina Rubottom?
Blood aches pain
sick shivers spasm
vomit dizzy fainting
colic and in a
coma!
1 FAVORITE
HDFS/Hadoop
Mongo/Aggregation
Mongo/MapReduce
Postgres
30 million geo-tagged
tweets sent from UK
How can we do fast, real time analytics of
social media?
Store this!
Not this!
ptaoussanis/carmine
(:require
[taoensso.carmine :as car])
!
!
(defn create-tweet-id []
(first
(wcar*
(car/incr "global:tweet.id"))))
!
!
(defn set-values [sentiment location created-at]
(let [tweed-id (create-tweet-id)]
(wcar*
(car/setbit sentiment tweet-id 1)
(car/setbit location tweet-id 1)
(car/setbit created-at tweet-id 1))))
(:require
[taoensso.carmine :as car])
!
!
(defn create-tweet-id []
(first
(wcar*
(car/incr "global:tweet.id"))))
!
!
(defn set-values [sentiment location created-at]
(let [tweed-id (create-tweet-id)]
(wcar*
(car/setbit sentiment tweet-id 1)
(car/setbit location tweet-id 1)
(car/setbit created-at tweet-id 1))))
(:require
[taoensso.carmine :as car])
!
!
(defn create-tweet-id []
(first
(wcar*
(car/incr "global:tweet.id"))))
!
!
(defn set-values [sentiment location created-at]
(let [tweed-id (create-tweet-id)]
(wcar*
(car/setbit sentiment tweet-id 1)
(car/setbit location tweet-id 1)
(car/setbit created-at tweet-id 1))))
(:require
[taoensso.carmine :as car])
!
!
(defn create-tweet-id []
(first
(wcar*
(car/incr "global:tweet.id"))))
!
!
(defn set-values [sentiment location created-at]
(let [tweed-id (create-tweet-id)]
(wcar*
(car/setbit sentiment tweet-id 1)
(car/setbit location tweet-id 1)
(car/setbit created-at tweet-id 1))))
(:require
[taoensso.carmine :as car])
!
!
(defn create-tweet-id []
(first
(wcar*
(car/incr "global:tweet.id"))))
!
!
(defn set-values [sentiment location created-at]
(let [tweed-id (create-tweet-id)]
(wcar*
(car/setbit sentiment tweet-id 1)
(car/setbit location tweet-id 1)
(car/setbit created-at tweet-id 1))))
find value for key
find bit of index
set bit to 1
(wcar*
(car/bitcount "SCOTLAND")
(car/bitcount "JOVIALITY")
(car/bitcount "26062014114532"))
ENG
SCT
WAL
NIR
valuekey
ENG 1
SCT 0
WAL 0
NIR 0
(car/setbit “ENG” 0 1)
tweet-idkey
valuekey
ENG 0 1
SCT 1 0
WAL 0 0
NIR 0 0
(car/setbit “SCT” 1 1)
tweet-idkey
valuekey
ENG 1 0 1
SCT 0 1 0
WAL 0 0 0
NIR 0 0 0
(car/setbit “ENG” 2 1)
tweet-idkey
valuekey
ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1
SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0
WAL 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0
NIR 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
(car/setbit “SCT” 15 1)
tweet-idkey
valuekey
ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1
SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0
WAL 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0
NIR 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
(car/bitcount "ENG")
8
valuekey
ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1
SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0
WAL 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0
NIR 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
(car/bitcount "SCT")
8
4
valuekey
ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1
SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0
WAL 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0
NIR 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
(car/bitcount "WAL")
8
4
3
valuekey
ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1
SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0
WAL 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0
NIR 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
(car/bitcount "NIR")
8
4
3
1
valuekey
JOVIAL
SHY
HOSTILE
FATIGUE
valuekey
JOVIAL 1
SHY 0
HOSTILE 0
FATIGUE 0
(car/setbit “JOVIAL” 0 1)
tweet-idkey
valuekey
JOVIAL 0 1
SHY 0 0
HOSTILE 1 0
FATIGUE 0 0
(car/setbit “HOSTILE” 1 1)
tweet-idkey
valuekey
JOVIAL 0 0 1
SHY 1 0 0
HOSTILE 0 1 0
FATIGUE 0 0 0
(car/setbit “SHY” 2 1)
tweet-idkey
valuekey
JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1
SHY 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0
(car/setbit “JOVIAL” 15 1)
tweet-idkey
valuekey
JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1
SHY 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0
(car/bitcount [*])
8
1
3
4
valuekey
(wcar*
(car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY")
(car/expire “ENGLAND&JOVIALITY" 10)
(car/bitcount “ENGLAND&JOVIALITY"))
How many people in England are Happy?
(wcar*
(car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY")
(car/expire “ENGLAND&JOVIALITY" 10)
(car/bitcount “ENGLAND&JOVIALITY"))
How many people in England are Happy?
(wcar*
(car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY")
(car/expire “ENGLAND&JOVIALITY" 10)
(car/bitcount “ENGLAND&JOVIALITY"))
How many people in England are Happy?
(wcar*
(car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY")
(car/expire “ENGLAND&JOVIALITY" 10)
(car/bitcount “ENGLAND&JOVIALITY"))
How many people in England are Happy?
How many people in England are Happy?
ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1
How many people in England are Happy?
ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1
JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1
How many people in England are Happy?
ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1
JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1
1
AND
How many people in England are Happy?
(car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY")
ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1
JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1
0 1
AND
How many people in England are Happy?
(car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY")
ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1
JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1
0 0 1
AND
How many people in England are Happy?
(car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY")
ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1
JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1
0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1
AND
How many people in England are Happy?
(car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY")
ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1
JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1
0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1
How many people in England are Happy?
(car/bitcount “ENGLAND&JOVIALITY")
4
(wcar*
(car/bitop "OR" "FATIGUE|HOSTILITY" "FATIGUE" “HOSTILITY")
(car/expire "FATIGUE|HOSTILITY" 10)
(car/bitop "AND" "SCOTLAND&(FATIGUE|HOSTILITY)"
"SCOTLAND" "FATIGUE|HOSTILITY")
(car/expire "SCOTLAND&(FATIGUE|HOSTILITY)" 10)
(car/bitcount "SCOTLAND&(FATIGUE|HOSTILITY)"))
How many people in Scotland are Tired
and Grumpy?
(wcar*
(car/bitop "OR" "FATIGUE|HOSTILITY" "FATIGUE" “HOSTILITY")
(car/expire "FATIGUE|HOSTILITY" 10)
(car/bitop "AND" "SCOTLAND&(FATIGUE|HOSTILITY)"
"SCOTLAND" "FATIGUE|HOSTILITY")
(car/expire "SCOTLAND&(FATIGUE|HOSTILITY)" 10)
(car/bitcount "SCOTLAND&(FATIGUE|HOSTILITY)"))
How many people in Scotland are Tired
and Grumpy?
(wcar*
(car/bitop "OR" "FATIGUE|HOSTILITY" "FATIGUE" “HOSTILITY")
(car/expire "FATIGUE|HOSTILITY" 10)
(car/bitop "AND" "SCOTLAND&(FATIGUE|HOSTILITY)"
"SCOTLAND" "FATIGUE|HOSTILITY")
(car/expire "SCOTLAND&(FATIGUE|HOSTILITY)" 10)
(car/bitcount "SCOTLAND&(FATIGUE|HOSTILITY)"))
How many people in Scotland are Tired
and Grumpy?
(wcar*
(car/bitop "OR" "FATIGUE|HOSTILITY" "FATIGUE" “HOSTILITY")
(car/expire "FATIGUE|HOSTILITY" 10)
(car/bitop "AND" "SCOTLAND&(FATIGUE|HOSTILITY)"
"SCOTLAND" "FATIGUE|HOSTILITY")
(car/expire "SCOTLAND&(FATIGUE|HOSTILITY)" 10)
(car/bitcount "SCOTLAND&(FATIGUE|HOSTILITY)"))
How many people in Scotland are Tired
and Grumpy?
How many people in Scotland are Tired
and Grumpy?
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
How many people in Scotland are Tired
and Grumpy?
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0
How many people in Scotland are Tired
and Grumpy?
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0
BOTH
OR
How many people in Scotland are Tired
and Grumpy?
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0
BOTH 0
OR
How many people in Scotland are Tired
and Grumpy?
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0
BOTH 1 0
OR
How many people in Scotland are Tired
and Grumpy?
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0
BOTH 0 1 0
How many people in Scotland are Tired
and Grumpy?
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0
BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0
OR
How many people in Scotland are Tired
and Grumpy?
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0
BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0
OR
How many people in Scotland are Tired
and Grumpy?
SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0
BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0
How many people in Scotland are Tired
and Grumpy?
SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0
BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0
BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0
AND
How many people in Scotland are Tired
and Grumpy?
SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0
BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0
HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0
FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0
BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0
How many people in Scotland are Tired
and Grumpy?
2
RING
Syncing
Journaling
Business logic
What
Where
When
Memory
WebAPI
Incoming Data
RING
Syncing
Journaling
Business logic
What
Where
When
Memory
WebAPI
Incoming Data
adamwynne/twitter-api
RING
Syncing
Journaling
Business logic
What
Where
When
Memory
WebAPI
Incoming Data
clojurewerkz/meltdown
LMAX-Exchange/disruptor
RING
Syncing
Journaling
Business logic
What
Where
When
Memory
WebAPI
Incoming Data
dakrone/clojure-opennlp
“I’m loving #EuroClojure! ”
Positive Affect: enthusiastic, active, alert
!
Negative Affect: subjective distress
!
Emerged as distinctive, orthogonal dimensions
PANAS
1
2
3
4
5
1
3
1
5
3
2
3
3
5
3
4
5
2
2
1
PANAS
1
2
3
4
5
1
3
1
5
3
2
3
3
5
3
4
5
2
2
1
1
3
5
9
10
12
14
16
17
19
2
4
6
7
8
11
13
15
18
20
PANAS
1
23
4
5
1
3
1
5
3
23
35
34
5 2
2 1
1
3
5
9
10
12
14
16
17
19
2
4
6
7
8
11
13
15
18
20
39 19
positive affect! negative affect
PANAS-x
General Dimension Scales!
Negative Affect (10)
Positive Affect (10)
Basic Positive Emotions Scales!
Joviality (8)
Self-assurance (6)
Attentiveness (4)
Basic Negative Emotions Scales!
Fear (6)
Hostility (6)
Guilt (6)
Sadness (5)
Other Affective States!
Shyness (4)
Fatigue (4)
Serenity (3)
Surprise (3)
PANAS-t
Accounts for bias on social media!
Outlines sanitisation
Validate against 10 real events
Sanitisation
• Exclude media/advertising/spam
• Account for text speak
• Account for smileys & emoj’s
• Word stemming (or lemmatisation)
• Part of Speech Tagging (POS)
LMAO
GetRichQuick.com
dakrone/clojure-opennlp
SHYNESS
FATIGUE
SERENITY
SURPRISE
FEAR
HOSTILITY
GUILT
SADNESS
JOVIALITY
SELF ASSURANCE
ATTENTIVENESS
We have sentiment keys!
RING
Syncing
Journaling
Business logic
What
Where
When
Memory
WebAPI
Incoming Data
mbostock/d3
[-75.14310264, 40.05701649]
Reverse Geocoding Issues
• Don’t want external services
• Don’t want heavy IO
• Don’t want round trips to the database
• Accuracy not too much of a concern
Equirectangular Projection
Courtesy of Eric Gaba (Wikimedia Commons User: Sting)
x = λcosφ1
y = φ
Tissot's indicatrix of deformation
Courtesy of Eric Gaba (Wikimedia Commons User: Sting)
x (px)
y (px)
x (px)
y (px)
[lon, lat] = [55.86140, -4.26477]
[x, y] = [329, 601]
[x, y] = = Scotland!
x (px)
y (px)
[lon, lat] = [55.86140, -4.26477]
[x, y] = [329, 601]
[x, y] = = Scotland!
x (px)
y (px)
[lon, lat] = [55.86140, -4.26477]
[x, y] = [329, 601]
[x, y] = = Scotland!
x (px)
y (px)
[lon, lat] = [55.86140, -4.26477]
[x, y] = [329, 601]
[x, y] = = Scotland!
x (px)
y (px)
[lon, lat] = [55.86140, -4.26477]
[x, y] = [329, 601]
[x, y] = = Scotland!
x (px)
y (px)
[lon, lat] = [55.86140, -4.26477]
[x, y] = [329, 601]
[x, y] = = Scotland!
Server side!
(JavaFX)
Mike Bostock & Nick Rabinowitz
(:require
[hiccup.page :as hiccup])
(:import
(javafx.scene.web WebView))
!
(def scripts ["uk-data.js" "topojson.v1.min.js" "d3.v3.min.js" "geocoder.js"])
!
(defn create-browser [html]
(-> WebView.
.getEngine
(.loadContent html)))
!
(defn build-page [script-paths]
(hiccup/html5
[:head
(for [path script-paths]
[:script (slurp (io/resource path))])]))
!
(defn coordinates->name [longitude latitude]
(let [browser (-> scripts build-page create-browser)]
(.executeScript browser
(str "geo.decode([" longitude "," latitude "])"))))
JavaFX
(:require
[hiccup.page :as hiccup])
(:import
(javafx.scene.web WebView))
!
(def scripts ["uk-data.js" "topojson.v1.min.js" "d3.v3.min.js" "geocoder.js"])
!
(defn create-browser [html]
(-> WebView.
.getEngine
(.loadContent html)))
!
(defn build-page [script-paths]
(hiccup/html5
[:head
(for [path script-paths]
[:script (slurp (io/resource path))])]))
!
(defn coordinates->name [longitude latitude]
(let [browser (-> scripts build-page create-browser)]
(.executeScript browser
(str "geo.decode([" longitude "," latitude "])"))))
JavaFX
(:require
[hiccup.page :as hiccup])
(:import
(javafx.scene.web WebView))
!
(def scripts ["uk-data.js" "topojson.v1.min.js" "d3.v3.min.js" "geocoder.js"])
!
(defn create-browser [html]
(-> WebView.
.getEngine
(.loadContent html)))
!
(defn build-page [script-paths]
(hiccup/html5
[:head
(for [path script-paths]
[:script (slurp (io/resource path))])]))
!
(defn coordinates->name [longitude latitude]
(let [browser (-> scripts build-page create-browser)]
(.executeScript browser
(str "geo.decode([" longitude "," latitude "])"))))
JavaFX
(:require
[hiccup.page :as hiccup])
(:import
(javafx.scene.web WebView))
!
(def scripts ["uk-data.js" "topojson.v1.min.js" "d3.v3.min.js" "geocoder.js"])
!
(defn create-browser [html]
(-> WebView.
.getEngine
(.loadContent html)))
!
(defn build-page [script-paths]
(hiccup/html5
[:head
(for [path script-paths]
[:script (slurp (io/resource path))])]))
!
(defn coordinates->name [longitude latitude]
(let [browser (-> scripts build-page create-browser)]
(.executeScript browser
(str "geo.decode([" longitude "," latitude "])"))))
JavaFX
(:require
[hiccup.page :as hiccup])
(:import
(javafx.scene.web WebView))
!
(def scripts ["uk-data.js" "topojson.v1.min.js" "d3.v3.min.js" "geocoder.js"])
!
(defn create-browser [html]
(-> WebView.
.getEngine
(.loadContent html)))
!
(defn build-page [script-paths]
(hiccup/html5
[:head
(for [path script-paths]
[:script (slurp (io/resource path))])]))
!
(defn coordinates->name [longitude latitude]
(let [browser (-> scripts build-page create-browser)]
(.executeScript browser
(str "geo.decode([" longitude "," latitude "])"))))
Stuart Sierras
Component lib!!
JavaFX
RING
Syncing
Journaling
Business logic
What
Where
When
Memory
WebAPI
Incoming Data
KirinDave/clj-time
“Thu Jun 26 14:35:57 +0000 2014”
over 86 thousand seconds in a day
over 31 million seconds in a year
mm:260620141435
HH:260620141400
Monday Tuesday Wednesday Thursday Friday Saturday Sunday
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 27 28 29
30 31
dd:260620140000
JAN FEB MAR APR
MAY JUL AUG
SEP OCT NOV DEC
MM:010620140000
2013
2015
yy:010120140000
(:require
[clj-time.format :as time])
!
!
(def input-formatter "EE MMM d HH:mm:ss Z yyyy")
(def formats { "mm:" "ddMMyyHHmm" "HH:" "ddMMyyHH00" ... })
!
!
(defn create-key [date [prefix formatter]]
(let [out-date (time/unparse formatter date)]
(str prefix out-date)))
!
!
(defn date->keys [created_at]
(let [date (time/parse input-formatter created_at)]
(map #(create-key date %) formats)))
(:require
[clj-time.format :as time])
!
!
(def input-formatter "EE MMM d HH:mm:ss Z yyyy")
(def formats { "mm:" "ddMMyyHHmm" "HH:" "ddMMyyHH00" ... })
!
!
(defn create-key [date [prefix formatter]]
(let [out-date (time/unparse formatter date)]
(str prefix out-date)))
!
!
(defn date->keys [created_at]
(let [date (time/parse input-formatter created_at)]
(map #(create-key date %) formats)))
(:require
[clj-time.format :as time])
!
!
(def input-formatter "EE MMM d HH:mm:ss Z yyyy")
(def formats { "mm:" "ddMMyyHHmm" "HH:" "ddMMyyHH00" ... })
!
!
(defn create-key [date [prefix formatter]]
(let [out-date (time/unparse formatter date)]
(str prefix out-date)))
!
!
(defn date->keys [created_at]
(let [date (time/parse input-formatter created_at)]
(map #(create-key date %) formats)))
RING
Syncing
Journaling
Business logic
What
Where
When
Memory
WebAPI
Incoming Data
ptaoussanis/carmine
SENTIMENT
!
LOCATION
!
mm:date-time
HH:date-time
dd:date-time
MM:date-time
yy:date-time
We have 11 keys in total!
What
Where
When
(:require
[taoensso.carmine :as redis])
!
!
(defn create-tweet-id []
(redis/incr "global:tweet.id"))
!
!
(defn set-bits [data-keys tweet-id]
(doseq [data-key data-keys]
(redis/setbit data-key tweet-id 1)))
!
!
(defn data->analytics [data-keys]
(let [tweet-id (create-tweet-id)]
(set-bits data-keys tweet-id)))
(:require
[taoensso.carmine :as redis])
!
!
(defn create-tweet-id []
(redis/incr "global:tweet.id"))
!
!
(defn set-bits [data-keys tweet-id]
(doseq [data-key data-keys]
(redis/setbit data-key tweet-id 1)))
!
!
(defn data->analytics [data-keys]
(let [tweet-id (create-tweet-id)]
(set-bits data-keys tweet-id)))
(:require
[taoensso.carmine :as redis])
!
!
(defn create-tweet-id []
(redis/incr "global:tweet.id"))
!
!
(defn set-bits [data-keys tweet-id]
(doseq [data-key data-keys]
(redis/setbit data-key tweet-id 1)))
!
!
(defn data->analytics [data-keys]
(let [tweet-id (create-tweet-id)]
(set-bits data-keys tweet-id)))
{
'query-type': 'count',
'params': {
'sentiments': [
'FATIGUE',
'HOSTILITY'
],
'locations': [
'SCT'
]
}
}
weavejester/compojure
JSON query
{
'query-type': 'count',
'params': {
'sentiments': [
'FATIGUE',
'HOSTILITY'
],
'locations': [
'SCT'
]
}
}
weavejester/compojure
JSON query
/api?_query={json}
(defmulti execute :query-type)
!
!
(defmethod execute “count" []
… logic here)
!
!
(defmethod execute “p-affect“ []
… logic here)
!
!
(defmethod execute “n-affect“ []
… logic here)
{
'query-type': 'count',
'params': {
'sentiments': [
'FATIGUE',
'HOSTILITY'
],
'locations': [
'SCT'
]
}
}
weavejester/compojure
JSON query
/api?_query={json}
(defmulti execute :query-type)
!
!
(defmethod execute “count" []
… logic here)
!
!
(defmethod execute “p-affect“ []
… logic here)
!
!
(defmethod execute “n-affect“ []
… logic here)
{
'query-type': 'count',
'params': {
'sentiments': [
'FATIGUE',
'HOSTILITY'
],
'locations': [
'SCT'
]
}
}
weavejester/compojure
JSON query
/api?_query={json}
(defmulti execute :query-type)
!
!
(defmethod execute “count" []
… logic here)
!
!
(defmethod execute “p-affect“ []
… logic here)
!
!
(defmethod execute “n-affect“ []
… logic here)
weavejester/compojure
JSON query
/api?_query={json}
{
'query-type': 'count',
'params': {
'sentiments': [
'FATIGUE',
'HOSTILITY'
],
'locations': [
'SCT'
]
}
}
(defmulti execute :query-type)
!
!
(defmethod execute “count" []
… logic here)
!
!
(defmethod execute “p-affect“ []
… logic here)
!
!
(defmethod execute “n-affect“ []
… logic here)
weavejester/compojure
JSON query
/api?_query={json}
{
'query-type': ‘p-affect',
'params': {
'sentiments': [
'FATIGUE',
'HOSTILITY'
],
'locations': [
'SCT'
]
}
}
(defmulti execute :query-type)
!
!
(defmethod execute “count" []
… logic here)
!
!
(defmethod execute “p-affect“ []
… logic here)
!
!
(defmethod execute “n-affect“ []
… logic here)
weavejester/compojure
JSON query
/api?_query={json}
{
'query-type': ‘p-affect',
'params': {
'sentiments': [
'FATIGUE',
'HOSTILITY'
],
'locations': [
'SCT'
]
}
}
The code for this project is
about to be open sourced
!
We would love to have more contributors!
!
To find out more, follow:
#APassionForCode

Weitere ähnliche Inhalte

Andere mochten auch

Lisanslı Depoculuk Yönetmeliği
Lisanslı Depoculuk YönetmeliğiLisanslı Depoculuk Yönetmeliği
Lisanslı Depoculuk Yönetmeliğilidasder
 
день самоуправления
день самоуправлениядень самоуправления
день самоуправленияhalaeva
 
4 things top brand do differently.pptx
4 things top brand do differently.pptx4 things top brand do differently.pptx
4 things top brand do differently.pptxSymbicore Inc.
 
Tazmin fonu yönetmeliği
Tazmin fonu yönetmeliğiTazmin fonu yönetmeliği
Tazmin fonu yönetmeliğilidasder
 
Prezentacja1 (1)
Prezentacja1 (1)Prezentacja1 (1)
Prezentacja1 (1)dusia20
 
дух. нрав. для доу
дух. нрав. для доудух. нрав. для доу
дух. нрав. для доуhalaeva
 
Lisanslı depoculuk yönetmeliği
Lisanslı depoculuk yönetmeliğiLisanslı depoculuk yönetmeliği
Lisanslı depoculuk yönetmeliğilidasder
 
вопросы семейного воспитания
вопросы семейного воспитаниявопросы семейного воспитания
вопросы семейного воспитанияhalaeva
 
фгос доу
фгос доуфгос доу
фгос доуhalaeva
 
Визитная карточка ДОУ
Визитная карточка ДОУВизитная карточка ДОУ
Визитная карточка ДОУhalaeva
 
игры, развивающие чувтво ритма
игры, развивающие чувтво ритмаигры, развивающие чувтво ритма
игры, развивающие чувтво ритмаhalaeva
 
10 заповедей родителей
10 заповедей родителей10 заповедей родителей
10 заповедей родителейhalaeva
 
Fındık Tebliği
Fındık  TebliğiFındık  Tebliği
Fındık Tebliğilidasder
 
Pamuk tebliği
Pamuk tebliğiPamuk tebliği
Pamuk tebliğilidasder
 
Hububat, baklagiller ve yağli tohumlar tebliği
Hububat, baklagiller ve yağli tohumlar tebliğiHububat, baklagiller ve yağli tohumlar tebliği
Hububat, baklagiller ve yağli tohumlar tebliğilidasder
 
Омское прииртышье
Омское прииртышьеОмское прииртышье
Омское прииртышьеhalaeva
 
Zeytin tebliği
Zeytin tebliğiZeytin tebliği
Zeytin tebliğilidasder
 

Andere mochten auch (17)

Lisanslı Depoculuk Yönetmeliği
Lisanslı Depoculuk YönetmeliğiLisanslı Depoculuk Yönetmeliği
Lisanslı Depoculuk Yönetmeliği
 
день самоуправления
день самоуправлениядень самоуправления
день самоуправления
 
4 things top brand do differently.pptx
4 things top brand do differently.pptx4 things top brand do differently.pptx
4 things top brand do differently.pptx
 
Tazmin fonu yönetmeliği
Tazmin fonu yönetmeliğiTazmin fonu yönetmeliği
Tazmin fonu yönetmeliği
 
Prezentacja1 (1)
Prezentacja1 (1)Prezentacja1 (1)
Prezentacja1 (1)
 
дух. нрав. для доу
дух. нрав. для доудух. нрав. для доу
дух. нрав. для доу
 
Lisanslı depoculuk yönetmeliği
Lisanslı depoculuk yönetmeliğiLisanslı depoculuk yönetmeliği
Lisanslı depoculuk yönetmeliği
 
вопросы семейного воспитания
вопросы семейного воспитаниявопросы семейного воспитания
вопросы семейного воспитания
 
фгос доу
фгос доуфгос доу
фгос доу
 
Визитная карточка ДОУ
Визитная карточка ДОУВизитная карточка ДОУ
Визитная карточка ДОУ
 
игры, развивающие чувтво ритма
игры, развивающие чувтво ритмаигры, развивающие чувтво ритма
игры, развивающие чувтво ритма
 
10 заповедей родителей
10 заповедей родителей10 заповедей родителей
10 заповедей родителей
 
Fındık Tebliği
Fındık  TebliğiFındık  Tebliği
Fındık Tebliği
 
Pamuk tebliği
Pamuk tebliğiPamuk tebliği
Pamuk tebliği
 
Hububat, baklagiller ve yağli tohumlar tebliği
Hububat, baklagiller ve yağli tohumlar tebliğiHububat, baklagiller ve yağli tohumlar tebliği
Hububat, baklagiller ve yağli tohumlar tebliği
 
Омское прииртышье
Омское прииртышьеОмское прииртышье
Омское прииртышье
 
Zeytin tebliği
Zeytin tebliğiZeytin tebliği
Zeytin tebliği
 

Kürzlich hochgeladen

Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectBoston Institute of Analytics
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...Amil Baba Dawood bangali
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Seán Kennedy
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our WorldEduminds Learning
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanMYRABACSAFRA2
 
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...ssuserf63bd7
 
Top 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In QueensTop 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In Queensdataanalyticsqueen03
 
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSINGmarianagonzalez07
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhijennyeacort
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.natarajan8993
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 217djon017
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 

Kürzlich hochgeladen (20)

Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis Project
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our World
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population Mean
 
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
 
Top 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In QueensTop 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In Queens
 
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 

Using Clojure for Sentiment Analysis of the Twittersphere (EuroClojure 2014)

  • 2.
  • 3.
  • 4. Leiningen Versus the Ants! Clojure Versus Java! FP Versus OOP
  • 5. Leiningen Versus the Ants! Clojure Versus Java! FP Versus OOP Apache Ant
  • 6. Leiningen Versus the Ants Clojure Versus Java! FP Versus OOP Apache Ant
  • 7. Leiningen Versus the Ants Clojure Versus Java Functional Versus Object Oriented Apache Ant
  • 8. Blood aches pain sick shivers spasm vomit dizzy fainting colic and in a coma! 1 FAVORITE
  • 9. Blood aches pain sick shivers spasm vomit dizzy fainting colic and in a coma! 1 FAVORITE Scores HIGH for flu symptoms
  • 10. Blood aches pain sick shivers spasm vomit dizzy fainting colic and in a coma! 1 FAVORITE Who is Catalina Rubottom?
  • 11. Blood aches pain sick shivers spasm vomit dizzy fainting colic and in a coma! 1 FAVORITE HDFS/Hadoop Mongo/Aggregation Mongo/MapReduce Postgres 30 million geo-tagged tweets sent from UK
  • 12. How can we do fast, real time analytics of social media?
  • 15. (:require [taoensso.carmine :as car]) ! ! (defn create-tweet-id [] (first (wcar* (car/incr "global:tweet.id")))) ! ! (defn set-values [sentiment location created-at] (let [tweed-id (create-tweet-id)] (wcar* (car/setbit sentiment tweet-id 1) (car/setbit location tweet-id 1) (car/setbit created-at tweet-id 1))))
  • 16. (:require [taoensso.carmine :as car]) ! ! (defn create-tweet-id [] (first (wcar* (car/incr "global:tweet.id")))) ! ! (defn set-values [sentiment location created-at] (let [tweed-id (create-tweet-id)] (wcar* (car/setbit sentiment tweet-id 1) (car/setbit location tweet-id 1) (car/setbit created-at tweet-id 1))))
  • 17. (:require [taoensso.carmine :as car]) ! ! (defn create-tweet-id [] (first (wcar* (car/incr "global:tweet.id")))) ! ! (defn set-values [sentiment location created-at] (let [tweed-id (create-tweet-id)] (wcar* (car/setbit sentiment tweet-id 1) (car/setbit location tweet-id 1) (car/setbit created-at tweet-id 1))))
  • 18. (:require [taoensso.carmine :as car]) ! ! (defn create-tweet-id [] (first (wcar* (car/incr "global:tweet.id")))) ! ! (defn set-values [sentiment location created-at] (let [tweed-id (create-tweet-id)] (wcar* (car/setbit sentiment tweet-id 1) (car/setbit location tweet-id 1) (car/setbit created-at tweet-id 1))))
  • 19. (:require [taoensso.carmine :as car]) ! ! (defn create-tweet-id [] (first (wcar* (car/incr "global:tweet.id")))) ! ! (defn set-values [sentiment location created-at] (let [tweed-id (create-tweet-id)] (wcar* (car/setbit sentiment tweet-id 1) (car/setbit location tweet-id 1) (car/setbit created-at tweet-id 1)))) find value for key find bit of index set bit to 1
  • 22. ENG 1 SCT 0 WAL 0 NIR 0 (car/setbit “ENG” 0 1) tweet-idkey valuekey
  • 23. ENG 0 1 SCT 1 0 WAL 0 0 NIR 0 0 (car/setbit “SCT” 1 1) tweet-idkey valuekey
  • 24. ENG 1 0 1 SCT 0 1 0 WAL 0 0 0 NIR 0 0 0 (car/setbit “ENG” 2 1) tweet-idkey valuekey
  • 25. ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 WAL 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 NIR 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 (car/setbit “SCT” 15 1) tweet-idkey valuekey
  • 26. ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 WAL 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 NIR 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 (car/bitcount "ENG") 8 valuekey
  • 27. ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 WAL 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 NIR 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 (car/bitcount "SCT") 8 4 valuekey
  • 28. ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 WAL 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 NIR 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 (car/bitcount "WAL") 8 4 3 valuekey
  • 29. ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 WAL 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 NIR 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 (car/bitcount "NIR") 8 4 3 1 valuekey
  • 31. JOVIAL 1 SHY 0 HOSTILE 0 FATIGUE 0 (car/setbit “JOVIAL” 0 1) tweet-idkey valuekey
  • 32. JOVIAL 0 1 SHY 0 0 HOSTILE 1 0 FATIGUE 0 0 (car/setbit “HOSTILE” 1 1) tweet-idkey valuekey
  • 33. JOVIAL 0 0 1 SHY 1 0 0 HOSTILE 0 1 0 FATIGUE 0 0 0 (car/setbit “SHY” 2 1) tweet-idkey valuekey
  • 34. JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1 SHY 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 (car/setbit “JOVIAL” 15 1) tweet-idkey valuekey
  • 35. JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1 SHY 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 (car/bitcount [*]) 8 1 3 4 valuekey
  • 36. (wcar* (car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY") (car/expire “ENGLAND&JOVIALITY" 10) (car/bitcount “ENGLAND&JOVIALITY")) How many people in England are Happy?
  • 37. (wcar* (car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY") (car/expire “ENGLAND&JOVIALITY" 10) (car/bitcount “ENGLAND&JOVIALITY")) How many people in England are Happy?
  • 38. (wcar* (car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY") (car/expire “ENGLAND&JOVIALITY" 10) (car/bitcount “ENGLAND&JOVIALITY")) How many people in England are Happy?
  • 39. (wcar* (car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY") (car/expire “ENGLAND&JOVIALITY" 10) (car/bitcount “ENGLAND&JOVIALITY")) How many people in England are Happy?
  • 40. How many people in England are Happy?
  • 41. ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 How many people in England are Happy?
  • 42. ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1 How many people in England are Happy?
  • 43. ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1 1 AND How many people in England are Happy? (car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY")
  • 44. ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1 0 1 AND How many people in England are Happy? (car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY")
  • 45. ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1 0 0 1 AND How many people in England are Happy? (car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY")
  • 46. ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 AND How many people in England are Happy? (car/bitop "AND" “ENGLAND&JOVIALITY" "ENGLAND" "JOVIALITY")
  • 47. ENG 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 1 JOVIAL 1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 1 How many people in England are Happy? (car/bitcount “ENGLAND&JOVIALITY") 4
  • 48. (wcar* (car/bitop "OR" "FATIGUE|HOSTILITY" "FATIGUE" “HOSTILITY") (car/expire "FATIGUE|HOSTILITY" 10) (car/bitop "AND" "SCOTLAND&(FATIGUE|HOSTILITY)" "SCOTLAND" "FATIGUE|HOSTILITY") (car/expire "SCOTLAND&(FATIGUE|HOSTILITY)" 10) (car/bitcount "SCOTLAND&(FATIGUE|HOSTILITY)")) How many people in Scotland are Tired and Grumpy?
  • 49. (wcar* (car/bitop "OR" "FATIGUE|HOSTILITY" "FATIGUE" “HOSTILITY") (car/expire "FATIGUE|HOSTILITY" 10) (car/bitop "AND" "SCOTLAND&(FATIGUE|HOSTILITY)" "SCOTLAND" "FATIGUE|HOSTILITY") (car/expire "SCOTLAND&(FATIGUE|HOSTILITY)" 10) (car/bitcount "SCOTLAND&(FATIGUE|HOSTILITY)")) How many people in Scotland are Tired and Grumpy?
  • 50. (wcar* (car/bitop "OR" "FATIGUE|HOSTILITY" "FATIGUE" “HOSTILITY") (car/expire "FATIGUE|HOSTILITY" 10) (car/bitop "AND" "SCOTLAND&(FATIGUE|HOSTILITY)" "SCOTLAND" "FATIGUE|HOSTILITY") (car/expire "SCOTLAND&(FATIGUE|HOSTILITY)" 10) (car/bitcount "SCOTLAND&(FATIGUE|HOSTILITY)")) How many people in Scotland are Tired and Grumpy?
  • 51. (wcar* (car/bitop "OR" "FATIGUE|HOSTILITY" "FATIGUE" “HOSTILITY") (car/expire "FATIGUE|HOSTILITY" 10) (car/bitop "AND" "SCOTLAND&(FATIGUE|HOSTILITY)" "SCOTLAND" "FATIGUE|HOSTILITY") (car/expire "SCOTLAND&(FATIGUE|HOSTILITY)" 10) (car/bitcount "SCOTLAND&(FATIGUE|HOSTILITY)")) How many people in Scotland are Tired and Grumpy?
  • 52. How many people in Scotland are Tired and Grumpy?
  • 53. HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 How many people in Scotland are Tired and Grumpy?
  • 54. HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 How many people in Scotland are Tired and Grumpy?
  • 55. HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 BOTH OR How many people in Scotland are Tired and Grumpy?
  • 56. HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 BOTH 0 OR How many people in Scotland are Tired and Grumpy?
  • 57. HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 BOTH 1 0 OR How many people in Scotland are Tired and Grumpy?
  • 58. HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 BOTH 0 1 0 How many people in Scotland are Tired and Grumpy?
  • 59. HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 OR How many people in Scotland are Tired and Grumpy?
  • 60. HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 OR How many people in Scotland are Tired and Grumpy?
  • 61. SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 How many people in Scotland are Tired and Grumpy?
  • 62. SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 AND How many people in Scotland are Tired and Grumpy?
  • 63. SCT 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 HOSTILE 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 FATIGUE 0 1 0 1 0 0 0 0 1 0 0 0 1 0 0 0 BOTH 0 1 0 1 0 0 0 1 1 0 1 0 1 0 1 0 How many people in Scotland are Tired and Grumpy? 2
  • 69. Positive Affect: enthusiastic, active, alert ! Negative Affect: subjective distress ! Emerged as distinctive, orthogonal dimensions
  • 73. PANAS-x General Dimension Scales! Negative Affect (10) Positive Affect (10) Basic Positive Emotions Scales! Joviality (8) Self-assurance (6) Attentiveness (4) Basic Negative Emotions Scales! Fear (6) Hostility (6) Guilt (6) Sadness (5) Other Affective States! Shyness (4) Fatigue (4) Serenity (3) Surprise (3)
  • 74. PANAS-t Accounts for bias on social media! Outlines sanitisation Validate against 10 real events
  • 75. Sanitisation • Exclude media/advertising/spam • Account for text speak • Account for smileys & emoj’s • Word stemming (or lemmatisation) • Part of Speech Tagging (POS) LMAO GetRichQuick.com dakrone/clojure-opennlp
  • 79. Reverse Geocoding Issues • Don’t want external services • Don’t want heavy IO • Don’t want round trips to the database • Accuracy not too much of a concern
  • 80.
  • 81.
  • 83. Courtesy of Eric Gaba (Wikimedia Commons User: Sting)
  • 84. x = λcosφ1 y = φ Tissot's indicatrix of deformation Courtesy of Eric Gaba (Wikimedia Commons User: Sting)
  • 85.
  • 87. x (px) y (px) [lon, lat] = [55.86140, -4.26477] [x, y] = [329, 601] [x, y] = = Scotland!
  • 88. x (px) y (px) [lon, lat] = [55.86140, -4.26477] [x, y] = [329, 601] [x, y] = = Scotland!
  • 89. x (px) y (px) [lon, lat] = [55.86140, -4.26477] [x, y] = [329, 601] [x, y] = = Scotland!
  • 90. x (px) y (px) [lon, lat] = [55.86140, -4.26477] [x, y] = [329, 601] [x, y] = = Scotland!
  • 91. x (px) y (px) [lon, lat] = [55.86140, -4.26477] [x, y] = [329, 601] [x, y] = = Scotland!
  • 92. x (px) y (px) [lon, lat] = [55.86140, -4.26477] [x, y] = [329, 601] [x, y] = = Scotland!
  • 94. (:require [hiccup.page :as hiccup]) (:import (javafx.scene.web WebView)) ! (def scripts ["uk-data.js" "topojson.v1.min.js" "d3.v3.min.js" "geocoder.js"]) ! (defn create-browser [html] (-> WebView. .getEngine (.loadContent html))) ! (defn build-page [script-paths] (hiccup/html5 [:head (for [path script-paths] [:script (slurp (io/resource path))])])) ! (defn coordinates->name [longitude latitude] (let [browser (-> scripts build-page create-browser)] (.executeScript browser (str "geo.decode([" longitude "," latitude "])")))) JavaFX
  • 95. (:require [hiccup.page :as hiccup]) (:import (javafx.scene.web WebView)) ! (def scripts ["uk-data.js" "topojson.v1.min.js" "d3.v3.min.js" "geocoder.js"]) ! (defn create-browser [html] (-> WebView. .getEngine (.loadContent html))) ! (defn build-page [script-paths] (hiccup/html5 [:head (for [path script-paths] [:script (slurp (io/resource path))])])) ! (defn coordinates->name [longitude latitude] (let [browser (-> scripts build-page create-browser)] (.executeScript browser (str "geo.decode([" longitude "," latitude "])")))) JavaFX
  • 96. (:require [hiccup.page :as hiccup]) (:import (javafx.scene.web WebView)) ! (def scripts ["uk-data.js" "topojson.v1.min.js" "d3.v3.min.js" "geocoder.js"]) ! (defn create-browser [html] (-> WebView. .getEngine (.loadContent html))) ! (defn build-page [script-paths] (hiccup/html5 [:head (for [path script-paths] [:script (slurp (io/resource path))])])) ! (defn coordinates->name [longitude latitude] (let [browser (-> scripts build-page create-browser)] (.executeScript browser (str "geo.decode([" longitude "," latitude "])")))) JavaFX
  • 97. (:require [hiccup.page :as hiccup]) (:import (javafx.scene.web WebView)) ! (def scripts ["uk-data.js" "topojson.v1.min.js" "d3.v3.min.js" "geocoder.js"]) ! (defn create-browser [html] (-> WebView. .getEngine (.loadContent html))) ! (defn build-page [script-paths] (hiccup/html5 [:head (for [path script-paths] [:script (slurp (io/resource path))])])) ! (defn coordinates->name [longitude latitude] (let [browser (-> scripts build-page create-browser)] (.executeScript browser (str "geo.decode([" longitude "," latitude "])")))) JavaFX
  • 98. (:require [hiccup.page :as hiccup]) (:import (javafx.scene.web WebView)) ! (def scripts ["uk-data.js" "topojson.v1.min.js" "d3.v3.min.js" "geocoder.js"]) ! (defn create-browser [html] (-> WebView. .getEngine (.loadContent html))) ! (defn build-page [script-paths] (hiccup/html5 [:head (for [path script-paths] [:script (slurp (io/resource path))])])) ! (defn coordinates->name [longitude latitude] (let [browser (-> scripts build-page create-browser)] (.executeScript browser (str "geo.decode([" longitude "," latitude "])")))) Stuart Sierras Component lib!! JavaFX
  • 100. “Thu Jun 26 14:35:57 +0000 2014” over 86 thousand seconds in a day over 31 million seconds in a year
  • 101.
  • 102.
  • 105. Monday Tuesday Wednesday Thursday Friday Saturday Sunday 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 dd:260620140000
  • 106. JAN FEB MAR APR MAY JUL AUG SEP OCT NOV DEC MM:010620140000
  • 108. (:require [clj-time.format :as time]) ! ! (def input-formatter "EE MMM d HH:mm:ss Z yyyy") (def formats { "mm:" "ddMMyyHHmm" "HH:" "ddMMyyHH00" ... }) ! ! (defn create-key [date [prefix formatter]] (let [out-date (time/unparse formatter date)] (str prefix out-date))) ! ! (defn date->keys [created_at] (let [date (time/parse input-formatter created_at)] (map #(create-key date %) formats)))
  • 109. (:require [clj-time.format :as time]) ! ! (def input-formatter "EE MMM d HH:mm:ss Z yyyy") (def formats { "mm:" "ddMMyyHHmm" "HH:" "ddMMyyHH00" ... }) ! ! (defn create-key [date [prefix formatter]] (let [out-date (time/unparse formatter date)] (str prefix out-date))) ! ! (defn date->keys [created_at] (let [date (time/parse input-formatter created_at)] (map #(create-key date %) formats)))
  • 110. (:require [clj-time.format :as time]) ! ! (def input-formatter "EE MMM d HH:mm:ss Z yyyy") (def formats { "mm:" "ddMMyyHHmm" "HH:" "ddMMyyHH00" ... }) ! ! (defn create-key [date [prefix formatter]] (let [out-date (time/unparse formatter date)] (str prefix out-date))) ! ! (defn date->keys [created_at] (let [date (time/parse input-formatter created_at)] (map #(create-key date %) formats)))
  • 113. (:require [taoensso.carmine :as redis]) ! ! (defn create-tweet-id [] (redis/incr "global:tweet.id")) ! ! (defn set-bits [data-keys tweet-id] (doseq [data-key data-keys] (redis/setbit data-key tweet-id 1))) ! ! (defn data->analytics [data-keys] (let [tweet-id (create-tweet-id)] (set-bits data-keys tweet-id)))
  • 114. (:require [taoensso.carmine :as redis]) ! ! (defn create-tweet-id [] (redis/incr "global:tweet.id")) ! ! (defn set-bits [data-keys tweet-id] (doseq [data-key data-keys] (redis/setbit data-key tweet-id 1))) ! ! (defn data->analytics [data-keys] (let [tweet-id (create-tweet-id)] (set-bits data-keys tweet-id)))
  • 115. (:require [taoensso.carmine :as redis]) ! ! (defn create-tweet-id [] (redis/incr "global:tweet.id")) ! ! (defn set-bits [data-keys tweet-id] (doseq [data-key data-keys] (redis/setbit data-key tweet-id 1))) ! ! (defn data->analytics [data-keys] (let [tweet-id (create-tweet-id)] (set-bits data-keys tweet-id)))
  • 116. { 'query-type': 'count', 'params': { 'sentiments': [ 'FATIGUE', 'HOSTILITY' ], 'locations': [ 'SCT' ] } } weavejester/compojure JSON query
  • 117. { 'query-type': 'count', 'params': { 'sentiments': [ 'FATIGUE', 'HOSTILITY' ], 'locations': [ 'SCT' ] } } weavejester/compojure JSON query /api?_query={json}
  • 118. (defmulti execute :query-type) ! ! (defmethod execute “count" [] … logic here) ! ! (defmethod execute “p-affect“ [] … logic here) ! ! (defmethod execute “n-affect“ [] … logic here) { 'query-type': 'count', 'params': { 'sentiments': [ 'FATIGUE', 'HOSTILITY' ], 'locations': [ 'SCT' ] } } weavejester/compojure JSON query /api?_query={json}
  • 119. (defmulti execute :query-type) ! ! (defmethod execute “count" [] … logic here) ! ! (defmethod execute “p-affect“ [] … logic here) ! ! (defmethod execute “n-affect“ [] … logic here) { 'query-type': 'count', 'params': { 'sentiments': [ 'FATIGUE', 'HOSTILITY' ], 'locations': [ 'SCT' ] } } weavejester/compojure JSON query /api?_query={json}
  • 120. (defmulti execute :query-type) ! ! (defmethod execute “count" [] … logic here) ! ! (defmethod execute “p-affect“ [] … logic here) ! ! (defmethod execute “n-affect“ [] … logic here) weavejester/compojure JSON query /api?_query={json} { 'query-type': 'count', 'params': { 'sentiments': [ 'FATIGUE', 'HOSTILITY' ], 'locations': [ 'SCT' ] } }
  • 121. (defmulti execute :query-type) ! ! (defmethod execute “count" [] … logic here) ! ! (defmethod execute “p-affect“ [] … logic here) ! ! (defmethod execute “n-affect“ [] … logic here) weavejester/compojure JSON query /api?_query={json} { 'query-type': ‘p-affect', 'params': { 'sentiments': [ 'FATIGUE', 'HOSTILITY' ], 'locations': [ 'SCT' ] } }
  • 122. (defmulti execute :query-type) ! ! (defmethod execute “count" [] … logic here) ! ! (defmethod execute “p-affect“ [] … logic here) ! ! (defmethod execute “n-affect“ [] … logic here) weavejester/compojure JSON query /api?_query={json} { 'query-type': ‘p-affect', 'params': { 'sentiments': [ 'FATIGUE', 'HOSTILITY' ], 'locations': [ 'SCT' ] } }
  • 123.
  • 124. The code for this project is about to be open sourced ! We would love to have more contributors! ! To find out more, follow: #APassionForCode