-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrintData.rb
43 lines (40 loc) · 1.11 KB
/
PrintData.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
require 'DataPoint'
require 'csv'
class PrintData
#Printing csv to the files.
def self.print_csv(datapoints,filename,user_tweets_list)
CSV.open(filename, "wb",{:force_quotes => true}) do |csv|
temp = Array.new
temp << "original_tweet"
temp << "total_words"
temp << "total_sentiment"
temp << "total_nouns"
temp << "total_users"
csv << temp
datapoints.each do |dp|
temp = Array.new
temp << dp.original_tweet.gsub(/"*/,"")
temp << dp.original_tweet.split(/\s+/).length
total_sentiment = dp.word_array.inject(0) {|result,word| result + word.sentiment.abs }
temp << total_sentiment
total_nouns = dp.word_array.inject(0) do |result,word|
if word.pos.match(/^NN.*/)
result + 1
else
result + 0
end
end
temp << total_nouns
total_users = user_tweets_list.inject(0) do |result,tweets|
if tweets.index(dp.original_tweet)
result + 1
else
result + 0
end
end
temp << total_users
csv << temp
end
end
end
end