class SentimentParser
Constants
- VERSION
Attributes
words[RW]
Public Class Methods
new(words)
click to toggle source
# File lib/sentiment_parser.rb, line 13 def initialize(words) @words = words end
parse(words)
click to toggle source
# File lib/sentiment_parser.rb, line 8 def parse(words) new(words).parse end
Public Instance Methods
load(data)
click to toggle source
# File lib/sentiment_parser.rb, line 17 def load(data) hash = {} CSV.parse(data, :col_sep => "\t") do |row| hash[row[1]] = row[0] end hash end
parse()
click to toggle source
# File lib/sentiment_parser.rb, line 25 def parse total = 0.0 words.split(' ').each do |word| total += sentiment_data[word].to_f end total end
Private Instance Methods
sentiment_data()
click to toggle source
# File lib/sentiment_parser.rb, line 43 def sentiment_data @sentiment_data ||= sentiment_files.map {|f| load(File.read(f)) }.reduce({}, :merge) end
sentiment_files()
click to toggle source
# File lib/sentiment_parser.rb, line 37 def sentiment_files @files ||= ['vendor/sentiments/words.txt', 'vendor/sentiments/emotes.txt'].map do |file| File.expand_path(File.join(__FILE__, '../..', file)) end end