Skip to content

Instantly share code, notes, and snippets.

@Najaf
Created February 18, 2014 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Najaf/9071089 to your computer and use it in GitHub Desktop.
Save Najaf/9071089 to your computer and use it in GitHub Desktop.
#! /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