twitter_with_auto_pagination 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd60b96ff2d1620518b5f6c8e16799c477b0f76a
4
- data.tar.gz: 4352f612659aa199a647eb340d5bc00b32ae4341
3
+ metadata.gz: 35aa309dc97a81e62812edb59c1fe61c62da69b9
4
+ data.tar.gz: 9c3a07ab41c467685e144edadda32c3c399b1b47
5
5
  SHA512:
6
- metadata.gz: 750f168e791c3241961a106946052471b062ea11702e16906f281e9a8673e34b2d32d216be8671229164ff0ad8a51463efd3a21505c1cfdcd006a32b722f6499
7
- data.tar.gz: e4fb48382befa9b581f1e2eee34636fcd5d2203af823777b2f69ba96b5d91780935ba1d94bfc33ce0229601efe4b726d392e36107b6f2d91fa90f7a7db21d32a
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
- def clusters_belong_to(text)
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
- exclude_words = JSON.parse(File.read(Rails.configuration.x.constants['cluster_bad_words_path']))
13
- special_words = JSON.parse(File.read(Rails.configuration.x.constants['cluster_good_words_path']))
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
- cluster_word_counter =
25
+ frequency =
17
26
  special_words.map { |sw| [sw, text.scan(sw)] }
18
- .delete_if { |item| item[1].empty? }
19
- .each_with_object(Hash.new(1)) { |item, memo| memo[item[0]] = item[1].size }
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(/[一-龠〆ヵヶ々]+|[ぁ-んー~]+|[ァ-ヴー~]+|[a-zA-Z0-9]+|[、。!!??]+/).
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 <= 1 || (w.length <= 2 && w =~ /^[ぁ-んー~]+$/) || exclude_words.include?(w) }.
36
+ # 文字数の少なすぎる単語、除外単語を除去する
37
+ delete_if { |w| w.length <= 2 || exclude_words.include?(w) }.
29
38
 
30
39
  # 出現回数を記録
31
- each { |w| cluster_word_counter[w] += 1 }
40
+ each { |w| frequency[w] += 1 }
32
41
 
33
42
  # 複数個以上見付かった単語のみを残し、出現頻度順にソート
34
- cluster_word_counter.select { |_, v| v > 3 }.sort_by { |_, v| -v }.to_h
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 = namespaced_key(method_name, user, options)
178
+ key = file_cache_key(method_name, user, options)
183
179
 
184
180
  fetch_result =
185
181
  if options[:cache] == :read
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.required_ruby_version = '>= 2.3'
23
23
  spec.summary = spec.description
24
24
  spec.test_files = Dir.glob('spec/**/*')
25
- spec.version = '0.8.1'
25
+ spec.version = '0.8.2'
26
26
  end
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.1
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-07-23 00:00:00.000000000 Z
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