aloha_analyzer 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -7
- data/aloha_analyzer.gemspec +2 -2
- data/lib/aloha_analyzer/{user.rb → base.rb} +38 -33
- data/lib/aloha_analyzer/facebook.rb +11 -0
- data/lib/aloha_analyzer/facebook_page.rb +39 -0
- data/lib/aloha_analyzer/language.rb +3 -3
- data/lib/aloha_analyzer/twitter.rb +11 -0
- data/lib/aloha_analyzer/version.rb +1 -1
- data/lib/aloha_analyzer/yaml/aliases.yml +83 -83
- data/lib/aloha_analyzer.rb +6 -3
- data/spec/aloha_analyzer/facebook_page_spec.rb +310 -0
- data/spec/aloha_analyzer/facebook_spec.rb +354 -0
- data/spec/aloha_analyzer/language_spec.rb +14 -14
- data/spec/aloha_analyzer/{user_spec.rb → twitter_spec.rb} +46 -46
- metadata +15 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36b2f48d7da6a71e6ee989066f3ecdd0cf52415c
|
4
|
+
data.tar.gz: 13836892ac1a676e5c86e9115f0b638e88e7a2f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eea341593848177dd6e5aa52696f2fc0cddedf4ac7979075172ba9e4d1c76cc593c831a342b39d4b2043a4be5ace24324ddfa0784159dce95f95fd752b0df7e7
|
7
|
+
data.tar.gz: 248eec547e964eea2e6f603fae70343e4f88028a8c996495a71a9036cc63d1db05c9edb0834e4f82a08626b4191f3dba6a5dce7e656ea86ab6eac7d69a92da80
|
data/README.md
CHANGED
data/aloha_analyzer.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency 'twitter_cldr', '~> 3.0'
|
21
|
+
spec.add_development_dependency 'twitter_cldr', '~> 3.0.0'
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
23
23
|
spec.add_development_dependency 'rake', '~> 10.3'
|
24
|
-
spec.add_development_dependency 'rspec', '~>
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
25
|
spec.add_development_dependency 'byebug', '~> 3.1'
|
26
26
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module AlohaAnalyzer
|
2
|
-
class
|
3
|
-
|
2
|
+
class Base
|
4
3
|
attr_reader :language, :analysis
|
5
4
|
|
6
5
|
def initialize(options)
|
@@ -11,7 +10,7 @@ module AlohaAnalyzer
|
|
11
10
|
|
12
11
|
def analyze(users)
|
13
12
|
clean_users(users).each do |user|
|
14
|
-
if user[
|
13
|
+
if user[language_key] == @language
|
15
14
|
add_account_language_user(user)
|
16
15
|
@analysis['account_language']['count'] += 1
|
17
16
|
else
|
@@ -27,7 +26,7 @@ module AlohaAnalyzer
|
|
27
26
|
{
|
28
27
|
'account_language' => {
|
29
28
|
'count' => 0,
|
30
|
-
'language' => Language.find_by_abbreviation(@language),
|
29
|
+
'language' => Language.find_by_abbreviation(@language, network_name),
|
31
30
|
'users' => []
|
32
31
|
},
|
33
32
|
'foreign_languages_count' => 0,
|
@@ -36,30 +35,29 @@ module AlohaAnalyzer
|
|
36
35
|
}
|
37
36
|
end
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
def clean_language(language)
|
39
|
+
if Language.aliases.keys.include?(language)
|
40
|
+
Language.aliases[language]
|
41
|
+
else
|
42
|
+
language
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
def clean_users(users)
|
47
|
+
users.map do |user|
|
48
|
+
if Language.aliases.keys.include?(user[language_key].downcase)
|
49
|
+
user[language_key] = Language.aliases[user[language_key].downcase]
|
50
|
+
end
|
51
|
+
user
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
}
|
62
|
-
end
|
55
|
+
def network_name
|
56
|
+
self.class.network_name
|
57
|
+
end
|
58
|
+
|
59
|
+
def language_key
|
60
|
+
self.class.language_key
|
63
61
|
end
|
64
62
|
|
65
63
|
def too_many_users?(users)
|
@@ -70,20 +68,27 @@ module AlohaAnalyzer
|
|
70
68
|
end
|
71
69
|
end
|
72
70
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
else
|
77
|
-
language
|
71
|
+
def add_account_language_user(user)
|
72
|
+
unless too_many_users?(@analysis['account_language']['users'])
|
73
|
+
@analysis['account_language']['users'].push(user)
|
78
74
|
end
|
79
75
|
end
|
80
76
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
77
|
+
def add_foreign_language_user(user)
|
78
|
+
prepare_foreign_language(user[language_key])
|
79
|
+
@analysis['foreign_languages'][user[language_key]]['count'] += 1
|
80
|
+
unless too_many_users?(@analysis['foreign_languages'][user[language_key]]['users'])
|
81
|
+
@analysis['foreign_languages'][user[language_key]]['users'].push(user)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def prepare_foreign_language(abbreviation)
|
86
|
+
if @analysis['foreign_languages'][abbreviation].nil?
|
87
|
+
@analysis['foreign_languages'][abbreviation] = {
|
88
|
+
'count' => 0,
|
89
|
+
'language' => Language.find_by_abbreviation(abbreviation, network_name),
|
90
|
+
'users' => []
|
91
|
+
}
|
87
92
|
end
|
88
93
|
end
|
89
94
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module AlohaAnalyzer
|
2
|
+
class FacebookPage < Base
|
3
|
+
def self.network_name
|
4
|
+
'facebook'
|
5
|
+
end
|
6
|
+
|
7
|
+
def analyze(languages)
|
8
|
+
clean_languages(languages).each do |language_key, count|
|
9
|
+
if language_key == @language
|
10
|
+
@analysis['account_language']['count'] += count
|
11
|
+
else
|
12
|
+
add_foreign_language_user(language_key, count)
|
13
|
+
@analysis['foreign_languages_count'] += count
|
14
|
+
end
|
15
|
+
@analysis['count'] += count
|
16
|
+
end
|
17
|
+
@analysis
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_foreign_language_user(abbreviation, count)
|
21
|
+
prepare_foreign_language(abbreviation)
|
22
|
+
@analysis['foreign_languages'][abbreviation]['count'] += count
|
23
|
+
end
|
24
|
+
|
25
|
+
def clean_languages(languages)
|
26
|
+
languages.each do |language_key, count|
|
27
|
+
if Language.aliases.keys.include?(language_key.downcase)
|
28
|
+
if languages[Language.aliases[language_key.downcase]]
|
29
|
+
languages[Language.aliases[language_key.downcase]] = languages[Language.aliases[language_key.downcase]] + count
|
30
|
+
languages.delete language_key
|
31
|
+
else
|
32
|
+
languages[Language.aliases[language_key.downcase]] = languages.delete language_key
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -14,11 +14,11 @@ module AlohaAnalyzer
|
|
14
14
|
ALIASES['aliases']
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.find_by_abbreviation(abbreviation)
|
17
|
+
def self.find_by_abbreviation(abbreviation, network)
|
18
18
|
if LANGUAGES['languages'][abbreviation]
|
19
|
-
format(LANGUAGES['languages'][abbreviation],
|
19
|
+
format(LANGUAGES['languages'][abbreviation], network)
|
20
20
|
else
|
21
|
-
format(LANGUAGES['languages']['other'],
|
21
|
+
format(LANGUAGES['languages']['other'], network)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -52,89 +52,89 @@ aliases:
|
|
52
52
|
'zh-hk': 'zh'
|
53
53
|
'zh-tw': 'zh'
|
54
54
|
'lolc': 'en'
|
55
|
-
'
|
56
|
-
'
|
57
|
-
'
|
58
|
-
'
|
59
|
-
'
|
60
|
-
'
|
61
|
-
'
|
62
|
-
'
|
63
|
-
'
|
64
|
-
'
|
65
|
-
'
|
66
|
-
'
|
67
|
-
'
|
68
|
-
'
|
69
|
-
'
|
70
|
-
'
|
71
|
-
'
|
72
|
-
'
|
73
|
-
'
|
74
|
-
'
|
75
|
-
'
|
76
|
-
'
|
77
|
-
'
|
78
|
-
'
|
79
|
-
'
|
80
|
-
'
|
81
|
-
'
|
82
|
-
'
|
83
|
-
'
|
84
|
-
'
|
85
|
-
'
|
86
|
-
'
|
87
|
-
'
|
88
|
-
'
|
89
|
-
'
|
90
|
-
'
|
91
|
-
'
|
92
|
-
'
|
93
|
-
'
|
94
|
-
'
|
95
|
-
'
|
96
|
-
'
|
97
|
-
'
|
98
|
-
'
|
99
|
-
'
|
100
|
-
'
|
101
|
-
'
|
102
|
-
'
|
103
|
-
'
|
104
|
-
'
|
105
|
-
'
|
106
|
-
'
|
107
|
-
'
|
108
|
-
'
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
#
|
136
|
-
#
|
137
|
-
#
|
55
|
+
'ar_ar': 'ar'
|
56
|
+
'bg_bg': 'bg'
|
57
|
+
'cs_cz': 'cs'
|
58
|
+
'da_dk': 'da'
|
59
|
+
'de_de': 'de'
|
60
|
+
'el_gr': 'el'
|
61
|
+
'en_gb': 'en'
|
62
|
+
'en_pi': 'en'
|
63
|
+
'en_ud': 'en'
|
64
|
+
'en_us': 'en'
|
65
|
+
'es_es': 'es'
|
66
|
+
'es_la': 'es'
|
67
|
+
'eu_es': 'es'
|
68
|
+
'fi_fi': 'fi'
|
69
|
+
'fr_ca': 'fr'
|
70
|
+
'fr_fr': 'fr'
|
71
|
+
'ga_ie': 'en'
|
72
|
+
'he_il': 'he'
|
73
|
+
'hi_in': 'hi'
|
74
|
+
'hr_hr': 'hr'
|
75
|
+
'hu_hu': 'hu'
|
76
|
+
'id_id': 'id'
|
77
|
+
'is_is': 'is'
|
78
|
+
'it_it': 'it'
|
79
|
+
'ja_jp': 'ja'
|
80
|
+
'jv_id': 'id'
|
81
|
+
'km_kh': 'km'
|
82
|
+
'ko_kr': 'ko'
|
83
|
+
'lt_lt': 'lt'
|
84
|
+
'lv_lv': 'lv'
|
85
|
+
'mk_mk': 'mk'
|
86
|
+
'ml_in': 'ms'
|
87
|
+
'ms_my': 'ms'
|
88
|
+
'nb_no': 'no'
|
89
|
+
'nl_nl': 'nl'
|
90
|
+
'nn_no': 'no'
|
91
|
+
'pa_in': 'hi'
|
92
|
+
'pl_pl': 'pl'
|
93
|
+
'pt_br': 'pt'
|
94
|
+
'pt_pt': 'pt'
|
95
|
+
'ro_ro': 'ro'
|
96
|
+
'ru_ru': 'ru'
|
97
|
+
'sl_si': 'sl'
|
98
|
+
'sr_rs': 'sr'
|
99
|
+
'sv_se': 'sv'
|
100
|
+
'th_th': 'th'
|
101
|
+
'tl_ph': 'fil'
|
102
|
+
'tr_tr': 'tr'
|
103
|
+
'uk_ua': 'uk'
|
104
|
+
'ur_pk': 'ur'
|
105
|
+
'vi_vn': 'vi'
|
106
|
+
'zh_cn': 'zh'
|
107
|
+
'zh_hk': 'zh'
|
108
|
+
'zh_tw': 'zh'
|
109
|
+
# af_za: 'afrikaans'
|
110
|
+
# az_az: 'azerbaijani'
|
111
|
+
# be_by: 'belarusian'
|
112
|
+
# bn_in: 'bengali'
|
113
|
+
# bs_ba: 'bosnian'
|
114
|
+
# ca_es: 'catalan'
|
115
|
+
# cx_ph: 'cebuano'
|
116
|
+
# cy_gb: 'welsh'
|
117
|
+
# eo_eo: 'esperanto'
|
118
|
+
# et_ee: 'estonian'
|
119
|
+
# fa_ir: 'persian'
|
120
|
+
# fb_lt: 'leet speak'
|
121
|
+
# fo_fo: 'faroese'
|
122
|
+
# fy_nl: 'frisian'
|
123
|
+
# gl_es: 'galician'
|
124
|
+
# gn_py: 'guarani'
|
125
|
+
# hy_am: 'armenian'
|
126
|
+
# ka_ge: 'georgian'
|
127
|
+
# kn_in: 'kannada'
|
128
|
+
# ku_tr: 'kurdish'
|
129
|
+
# la_va: 'latin'
|
130
|
+
# ne_np: 'nepali'
|
131
|
+
# ps_af: 'pashto'
|
132
|
+
# si_lk: 'sinhala'
|
133
|
+
# sk_sk: 'slovak'
|
134
|
+
# sq_al: 'albanian'
|
135
|
+
# sw_ke: 'swahili'
|
136
|
+
# ta_in: 'tamil'
|
137
|
+
# te_in: 'telugu'
|
138
138
|
# 'aa': 'afar'
|
139
139
|
# 'ab': 'abkhazian'
|
140
140
|
# 'ach': 'acoli'
|
data/lib/aloha_analyzer.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'aloha_analyzer/version'
|
2
|
+
require 'aloha_analyzer/language'
|
3
|
+
require 'aloha_analyzer/base'
|
4
|
+
require 'aloha_analyzer/twitter'
|
5
|
+
require 'aloha_analyzer/facebook'
|
6
|
+
require 'aloha_analyzer/facebook_page'
|
4
7
|
|
5
8
|
module AlohaAnalyzer
|
6
9
|
end
|