-
Notifications
You must be signed in to change notification settings - Fork 1
/
analyze.rb
52 lines (42 loc) · 1.35 KB
/
analyze.rb
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'paralleldots'
require 'awesome_print'
require 'elasticsearch'
require 'json'
class MoodAnalyzer
def initialize
@client = Elasticsearch::Client.new log: true
file = File.read('input.json')
videos = JSON.parse(file)
@videos2 = videos
end
def convert_videos
converted_hash = Hash.new { |hash,key| hash[key] = Hash.new }
@videos2.first(10).each do |video|
name = video["Title"]
# print
# ap "New video available: #{name}"
# ap "Link: #{video["VideoUrl"]}"
# video["CommentList"].each do |comment|
# ap "#{name} comment: #{comment}"
# end
# ap emotion(comment)
next if video["CommentList"].nil?
converted_hash[name][:link] = video["VideoUrl"]
# converted_hash[name][:input] = video["CommentList"].first(5)
emotion = emotion(video["CommentList"].first(5).join(","))
converted_hash[name][:mood] = emotion["emotion"]["emotion"]
# converted_hash[name][:mood] = "test"
end
converted_hash
end
def elastic_insert
mood_hash = convert_videos
mood_hash.each do |video_name,video_info|
puts video_name
puts video_info
# @client.index index: 'mood-analyzer', type: 'my-video-mood', body: { title: video_name, link: video_info[:link], mood: video_info[:mood] }
end
end
end
analyzer = MoodAnalyzer.new
analyzer.elastic_insert