Created
February 18, 2014 12:53
-
-
Save Najaf/9070413 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'csv' | |
tweet = "Chocolate makes me happy, it makes my life wonderful" | |
tweetsplit = tweet.downcase.split(/\W+/) | |
valences = [] | |
tweetsplit.each do |i| | |
#Look through each row in the CSV file to see if any words in the tweet match | |
#the words in the 2nd element of the csv array(the word) | |
CSV.foreach("./ratings.csv") do |row| | |
#For each line if the word matches words in the tweet then create a new | |
#array and put the valence mean value (3rd array element) in it. | |
if row[1]==(i) | |
valences << row[2] | |
end | |
end | |
end | |
puts valences.inspect | |
#Find the average of the valence array to be ordered later | |
total = 0.0 | |
valences.each do |val| | |
total += val.to_f | |
end | |
average = total/valences.size | |
puts average |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment