Skip to content

Commit

Permalink
Merge pull request #1 from theverything/get_score
Browse files Browse the repository at this point in the history
Refactor #get_score
  • Loading branch information
jemminger committed Mar 30, 2013
2 parents 0983690 + 4488165 commit d19f853
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
12 changes: 2 additions & 10 deletions lib/sentimental.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,10 @@ def get_score(string)
#tokenize the string, also throw away some punctuation
tokens = string.to_s.downcase.split(/[\s\!\?\.]+/)

for token in tokens do
tokens.each do |token|
sentiment_value = @@sentihash[token]

if sentiment_value

# for debugging purposes
#puts "#{token} => #{sentiment_value}"

sentiment_total += sentiment_value
end
sentiment_total += sentiment_value if sentiment_value
end

sentiment_total
end

Expand Down
27 changes: 27 additions & 0 deletions spec/sentimental_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require_relative "../lib/sentimental"

describe Sentimental do

before :each do
Sentimental.load_defaults
Sentimental.threshold = 0.1
@analyzer = Sentimental.new
end

describe "#get_score" do

it "returns a score of 0.925 when passed 'I love ruby'" do
@analyzer.get_score('I love ruby').should eq(0.925)
end

it "returns a score of 0.0 when passed 'I like ruby'" do
@analyzer.get_score('I like ruby').should eq(0.0)
end

it "returns a score of -0.4375 when passed 'I hate ruby'" do
@analyzer.get_score('I hate ruby').should eq(-0.4375)
end

end

end

0 comments on commit d19f853

Please sign in to comment.