Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bugs with UserStats and excitement reporting. Much, much better…

… now.
  • Loading branch information...
commit 3c3c263fda16ab12eb1b87cd62bdb11b828ee7b2 1 parent 20d6ffd
Jake McGinty authored
7 app.rb
View
@@ -53,10 +53,11 @@ def initialize
# Since UserStats and TextMood can both use the same TextMood instance, we can send it the same
# one and avoid double the generation.
textmood_global = TwitterSentiment::Parser::TextMood.new(:afinn_emo)
+ facerecon_global = TwitterSentiment::Parser::FaceRecon.new
@parsers = {
:text_mood => { :instance => textmood_global },
- :user_image => { :instance => TwitterSentiment::Parser::FaceRecon.new },
- :user_stats => { :instance => textmood_global },
+ :user_image => { :instance => facerecon_global },
+ :user_stats => { :instance => TwitterSentiment::Parser::UserStats.new(textmood_global, facerecon_global) },
:randomness => { :instance => TwitterSentiment::Parser::Randomness.new },
}
@@ -79,7 +80,7 @@ def initialize
:happiness => happiness,
# excitement = follows per tweet
# TODO: make this actually excitement of post
- :excitement => limit_score(@parsers[:user_stats][:result][:follows_per_tweet]),
+ :excitement => limit_score(@parsers[:user_stats][:result][:follows_per_tweet]+@parsers[:randomness][:result][:exclamations]*2),
# confusion = number of question marks and a hint of randomness
:randomness => limit_score(@parsers[:randomness][:result][:questions] + rand(5) * 2),
}
4 lib/twitter-sentiment/input/twitter.rb
View
@@ -31,11 +31,11 @@ def initialize options
begin
# raw debug tweet output
pp :debug, "#{Paint['['+status.user.screen_name+']', :yellow]} #{status.text}", :high
- @fibers << Thread.new do
+ @fibers << Fiber.new do
# call the status-received callback
options[:status_callback].call(status)
end
- @fibers.last.run
+ @fibers.last.resume
rescue Interrupt
raise
rescue Exception => e
17 lib/twitter-sentiment/parser/text_mood.rb
View
@@ -123,15 +123,20 @@ def sentence_to_stripped_array sentence
# @param [String] string to score
# @return [Hash,nil] the score and stripped text string that was used for scoring
def gather status
- sentence = status.text
- words = sentence_to_stripped_array sentence
- score = 0
+ text = status.text
+ words = sentence_to_stripped_array text
+ sentence_score = score text
+ return {:score => ((sentence_score.to_f/words.length)*20), :stripped_text => words.join(" ")}
+ end
+
+ def score text
+ words = sentence_to_stripped_array text
+ total = 0
words.each do |word|
- score += @dict[symbolize(word)] if @dict.member? symbolize(word)
+ total += @dict[symbolize(word)] if @dict.member? symbolize(word)
end
- return {:score => ((score.to_f/words.length)*10), :stripped_text => words.join(" ")}
+ return total
end
-
end # TextMood
end # Parser
end # TwitterSentiment
5 lib/twitter-sentiment/parser/user_stats.rb
View
@@ -5,9 +5,10 @@
module TwitterSentiment
module Parser
class UserStats
- def initialize textmood=nil
+ def initialize textmood=nil, facerecon=nil
pp :info, "User info parser initialized successfully.", :high
@textmood = textmood.nil? ? TwitterSentiment::Parser::TextMood.new(:afinn_emo) : textmood
+ @facerecon = facerecon.nil? ? TwitterSentiment::Parser::FaceRecon.new : facerecon
end
def generate_score results
@@ -21,7 +22,7 @@ def gather status
user = status.user
#Call all of the included methods
return nil if user.nil?
- boringImages = default_imgs(user.profile_background_image_url, user.profile_image_url) #int
+ boringImages = @facerecon.default_imgs(user.profile_background_image_url, user.profile_image_url) #int
followPerTweet = user.followers_count.to_f / user.statuses_count.to_f #float, 0...
descriptionScore = @textmood.score(user.description) #int
Please sign in to comment.
Something went wrong with that request. Please try again.