sad_panda 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/sad_panda.rb +44 -43
  2. data/lib/sad_panda/version.rb +1 -1
  3. metadata +4 -4
@@ -29,8 +29,9 @@ module SadPanda
29
29
  end
30
30
 
31
31
  message_text = @message.gsub(/[^a-z ]/i, '').downcase
32
- message_text.gsub!(/(?=\w*h)(?=\w*t)(?=\w*t)(?=\w*p)\w*/, '')
33
- message_text.gsub!(/\s\s+/,' ')
32
+ message_text.gsub!(/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/, '')
33
+ message_text.gsub!(/(?=\w*h)(?=\w*t)(?=\w*t)(?=\w*p)\w*/, '')
34
+ message_text.gsub!(/\s\s+/,' ')
34
35
  words = message_text.split(" ")
35
36
 
36
37
  #filter for english stopwords
@@ -79,33 +80,33 @@ module SadPanda
79
80
  puts "SCORE: "+emotion_score[key].to_s
80
81
  end
81
82
  end
82
- # return an emotion_score_hash to be processed by emotion
83
- # get clue from any emoticons present
84
- if (@happy_que && @sad_que)
83
+ # return an emotion_score_hash to be processed by emotion
84
+ # get clue from any emoticons present
85
+ if (@happy_que && @sad_que)
86
+ return "ambiguous"
87
+ elsif @happy_que
88
+ return "joy"
89
+ elsif @sad_que
90
+ return "sadness"
91
+ else
92
+ ## 0 if unable to detect emotion
93
+ if emotion_score == {}
85
94
  return "ambiguous"
86
- elsif @happy_que
87
- return "joy"
88
- elsif @sad_que
89
- return "sadness"
90
95
  else
91
- ## 0 if unable to detect emotion
92
- if emotion_score == {}
93
- return "ambiguous"
94
- else
95
- score = emotion_score.max_by{|k, v| v}[0]
96
- end
97
- score
96
+ score = emotion_score.max_by{|k, v| v}[0]
98
97
  end
98
+ score
99
+ end
99
100
  end
100
101
 
101
102
  # this method returns the best-fit emotion for the status message
102
103
  def self.emotion message
103
- # get the emotion for which the emotion score value is highest
104
- if @emotions
105
- SadPanda.get_emotion_score(@emotions, SadPanda.build_term_frequencies(message))
106
- else
107
- SadPanda.get_emotion_score(EmotionBank.get_term_emotions, build_term_frequencies(message))
108
- end
104
+ # get the emotion for which the emotion score value is highest
105
+ if @emotions
106
+ SadPanda.get_emotion_score(@emotions, SadPanda.build_term_frequencies(message))
107
+ else
108
+ SadPanda.get_emotion_score(EmotionBank.get_term_emotions, build_term_frequencies(message))
109
+ end
109
110
  end
110
111
 
111
112
  # this method gives the status method a normalized polarity
@@ -120,28 +121,28 @@ module SadPanda
120
121
  end
121
122
  end
122
123
 
123
- # return an polarity_score_hash to be processed by polarity method
124
- # return an emotion_score_hash to be processed by emotion
125
- # get clue from any emoticons present
126
- if (@happy_que && @sad_que)
127
- score = 5
128
- elsif @happy_que
129
- score = 8
130
- elsif @sad_que
131
- score = 2
132
- else
133
- if polarity_scores == []
134
- # polarity unreadable; return a neutral score of zero
135
- score = 5
136
- else
137
- score = polarity_scores.inject(0.0){ |sum, el| sum + el}/polarity_scores.length
138
- polarity_scores = []
139
- end
140
- if @verbose
141
- puts "POLARITY: " + score.to_s
142
- end
143
- score
124
+ # return an polarity_score_hash to be processed by polarity method
125
+ # return an emotion_score_hash to be processed by emotion
126
+ # get clue from any emoticons present
127
+ if (@happy_que && @sad_que)
128
+ score = 5
129
+ elsif @happy_que
130
+ score = 8
131
+ elsif @sad_que
132
+ score = 2
133
+ else
134
+ if polarity_scores == []
135
+ # polarity unreadable; return a neutral score of zero
136
+ score = 5
137
+ else
138
+ score = polarity_scores.inject(0.0){ |sum, el| sum + el}/polarity_scores.length
139
+ polarity_scores = []
144
140
  end
141
+ if @verbose
142
+ puts "POLARITY: " + score.to_s
143
+ end
144
+ score
145
+ end
145
146
  end
146
147
 
147
148
  # this method returns the polarity value for the status message
@@ -1,3 +1,3 @@
1
1
  module SadPanda
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sad_panda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-25 00:00:00.000000000 Z
12
+ date: 2013-06-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  segments:
118
118
  - 0
119
- hash: 1579113864349454449
119
+ hash: -1400782450660875033
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  segments:
127
127
  - 0
128
- hash: 1579113864349454449
128
+ hash: -1400782450660875033
129
129
  requirements: []
130
130
  rubyforge_project:
131
131
  rubygems_version: 1.8.25