SlideShare a Scribd company logo
1 of 124
Download to read offline
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

More Related Content

Viewers also liked

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
 

Viewers also liked (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
 

Recently uploaded

Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxfirstjob4
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 

Recently uploaded (20)

Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptx
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 

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