Created
February 18, 2014 13:35
-
-
Save Najaf/9071089 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' | |
#Initialised the hash to store the valence values | |
valence_index = {} | |
CSV.foreach("./ratings.csv") do |row| | |
valence_index[row[1]] = row[2] | |
end | |
tweet = "Chocolate makes me happy, it makes my life wonderful" | |
tweetsplit = tweet.downcase.split(/\W+/) | |
valences = [] | |
tweetsplit.each do |i| | |
if valence_index[i] | |
valences << valence_index[i] | |
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