twitter_with_auto_pagination 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/twitter_with_auto_pagination/rest/api.rb +2 -0
- data/lib/twitter_with_auto_pagination/rest/extension/clusters.rb +20 -11
- data/lib/twitter_with_auto_pagination/rest/lists.rb +19 -0
- data/lib/twitter_with_auto_pagination/rest/utils.rb +2 -6
- data/twitter_with_auto_pagination.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35aa309dc97a81e62812edb59c1fe61c62da69b9
|
4
|
+
data.tar.gz: 9c3a07ab41c467685e144edadda32c3c399b1b47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55f1e531dc9dbaa174cff7f1a13dbec4a8e6ea85c920b58af0525048efcbbbee3746444790fb3120ea7e24fab647db4e2180a0a218811c0f0cf5421f59ca70b3
|
7
|
+
data.tar.gz: 52859557ffae6a65e7fc4c56900aab1d0dc234a4641a1ed22db744e6a2ea70a1e137de8fcddebb8239fe5a3cdaadde68d267387f5939ce5e111f35d38c6175aa
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'twitter_with_auto_pagination/rest/favorites'
|
2
2
|
require 'twitter_with_auto_pagination/rest/friends_and_followers'
|
3
|
+
require 'twitter_with_auto_pagination/rest/lists'
|
3
4
|
require 'twitter_with_auto_pagination/rest/search'
|
4
5
|
require 'twitter_with_auto_pagination/rest/timelines'
|
5
6
|
require 'twitter_with_auto_pagination/rest/users'
|
@@ -17,6 +18,7 @@ module TwitterWithAutoPagination
|
|
17
18
|
module API
|
18
19
|
include TwitterWithAutoPagination::REST::Favorites
|
19
20
|
include TwitterWithAutoPagination::REST::FriendsAndFollowers
|
21
|
+
include TwitterWithAutoPagination::REST::Lists
|
20
22
|
include TwitterWithAutoPagination::REST::Search
|
21
23
|
include TwitterWithAutoPagination::REST::Timelines
|
22
24
|
include TwitterWithAutoPagination::REST::Users
|
@@ -6,32 +6,41 @@ module TwitterWithAutoPagination
|
|
6
6
|
module Clusters
|
7
7
|
include TwitterWithAutoPagination::REST::Utils
|
8
8
|
|
9
|
-
|
9
|
+
# @param text [String] user_timeline.map(&:text).join(' ')
|
10
|
+
def clusters_belong_to(text, limit: 10)
|
10
11
|
return {} if text.blank?
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
if defined?(Rails)
|
14
|
+
exclude_words = JSON.parse(File.read(Rails.configuration.x.constants['cluster_bad_words_path']))
|
15
|
+
special_words = JSON.parse(File.read(Rails.configuration.x.constants['cluster_good_words_path']))
|
16
|
+
else
|
17
|
+
exclude_words = JSON.parse(File.read('./cluster_bad_words.json'))
|
18
|
+
special_words = JSON.parse(File.read('./cluster_good_words.json'))
|
19
|
+
end
|
20
|
+
|
21
|
+
%w(べたら それとも たしかに さそう そんなに ったことある してるの しそうな おやくま ってますか これをやってるよ のせいか).each { |w| exclude_words << w }
|
22
|
+
%w(面白い 可愛い 食べ物 宇多田ヒカル ご飯 面倒 体調悪くなる 空腹 頑張ってない 眼鏡 台風 沖縄 らんま1/2 女の子 怪我 足のむくみ 彼女欲しい 彼氏欲しい 吐き気 注射 海鮮チヂミ 出勤 価格ドットコム 幹事 雑談 パズドラ ビオフェルミン 餃子 お金 まんだらけ 結婚 焼肉 タッチペン).each { |w| special_words << w }
|
14
23
|
|
15
24
|
# クラスタ用の単語の出現回数を記録
|
16
|
-
|
25
|
+
frequency =
|
17
26
|
special_words.map { |sw| [sw, text.scan(sw)] }
|
18
|
-
.delete_if { |
|
19
|
-
.each_with_object(Hash.new(
|
27
|
+
.delete_if { |_, matched| matched.empty? }
|
28
|
+
.each_with_object(Hash.new(0)) { |(word, matched), memo| memo[word] = matched.size }
|
20
29
|
|
21
30
|
# 同一文字種の繰り返しを見付ける。漢字の繰り返し、ひらがなの繰り返し、カタカナの繰り返し、など
|
22
|
-
text.scan(/[一-龠〆ヵヶ々]+|[ぁ-んー~]+|[ァ-ヴー~]+|[
|
31
|
+
text.scan(/[一-龠〆ヵヶ々]+|[ぁ-んー~]+|[ァ-ヴー~]+|[a-zA-ZA-Z0-9]+|[、。!!??]+/).
|
23
32
|
|
24
33
|
# 複数回繰り返される文字を除去
|
25
34
|
map { |w| w.remove /[?!?!。、w]|(ー{2,})/ }.
|
26
35
|
|
27
|
-
#
|
28
|
-
delete_if { |w| w.length <=
|
36
|
+
# 文字数の少なすぎる単語、除外単語を除去する
|
37
|
+
delete_if { |w| w.length <= 2 || exclude_words.include?(w) }.
|
29
38
|
|
30
39
|
# 出現回数を記録
|
31
|
-
each { |w|
|
40
|
+
each { |w| frequency[w] += 1 }
|
32
41
|
|
33
42
|
# 複数個以上見付かった単語のみを残し、出現頻度順にソート
|
34
|
-
|
43
|
+
frequency.select { |_, v| 2 < v }.sort_by { |_, v| -v }.slice(0, limit).to_h
|
35
44
|
end
|
36
45
|
|
37
46
|
def clusters_assigned_to
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'twitter_with_auto_pagination/rest/utils'
|
2
|
+
|
3
|
+
module TwitterWithAutoPagination
|
4
|
+
module REST
|
5
|
+
module Lists
|
6
|
+
include TwitterWithAutoPagination::REST::Utils
|
7
|
+
|
8
|
+
def memberships(*args)
|
9
|
+
options = {count: 1000, cursor: -1}.merge(args.extract_options!)
|
10
|
+
args[0] = verify_credentials.id if args.empty?
|
11
|
+
instrument(__method__, nil, options) do
|
12
|
+
fetch_cache_or_call_api(__method__, args[0], options) do
|
13
|
+
collect_with_cursor(method(__method__).super_method, *args, options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -103,7 +103,7 @@ module TwitterWithAutoPagination
|
|
103
103
|
def collect_with_cursor(method_obj, *args)
|
104
104
|
options = args.extract_options!
|
105
105
|
last_response = call_api(method_obj, *args, options).attrs
|
106
|
-
return_data = (last_response[:users] || last_response[:ids])
|
106
|
+
return_data = (last_response[:users] || last_response[:ids] || last_response[:lists])
|
107
107
|
|
108
108
|
while (next_cursor = last_response[:next_cursor]) && next_cursor != 0
|
109
109
|
options[:cursor] = next_cursor
|
@@ -152,10 +152,6 @@ module TwitterWithAutoPagination
|
|
152
152
|
"#{method_name}#{delim}#{identifier}"
|
153
153
|
end
|
154
154
|
|
155
|
-
def namespaced_key(method_name, user, options = {})
|
156
|
-
file_cache_key(method_name, user, options)
|
157
|
-
end
|
158
|
-
|
159
155
|
CODER = JSON
|
160
156
|
|
161
157
|
def encode(obj)
|
@@ -179,7 +175,7 @@ module TwitterWithAutoPagination
|
|
179
175
|
end
|
180
176
|
|
181
177
|
def fetch_cache_or_call_api(method_name, user, options = {})
|
182
|
-
key =
|
178
|
+
key = file_cache_key(method_name, user, options)
|
183
179
|
|
184
180
|
fetch_result =
|
185
181
|
if options[:cache] == :read
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_with_auto_pagination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shinohara Teruki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twitter
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- lib/twitter_with_auto_pagination/rest/extension/users.rb
|
102
102
|
- lib/twitter_with_auto_pagination/rest/favorites.rb
|
103
103
|
- lib/twitter_with_auto_pagination/rest/friends_and_followers.rb
|
104
|
+
- lib/twitter_with_auto_pagination/rest/lists.rb
|
104
105
|
- lib/twitter_with_auto_pagination/rest/search.rb
|
105
106
|
- lib/twitter_with_auto_pagination/rest/timelines.rb
|
106
107
|
- lib/twitter_with_auto_pagination/rest/uncategorized.rb
|