chime 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +1 -1
- data/VERSION +1 -1
- data/chime.gemspec +4 -2
- data/lib/chime/emotions/emotion_bank.rb +93 -88
- data/lib/chime/emotions/emotion_bank_phrases.rb +1564 -0
- data/lib/chime/emotions/term_categories.rb +1811 -0
- data/lib/chime/version.rb +1 -1
- data/lib/chime.rb +81 -1
- metadata +4 -2
data/lib/chime/version.rb
CHANGED
data/lib/chime.rb
CHANGED
@@ -2,6 +2,9 @@ require_relative "./chime/version"
|
|
2
2
|
require_relative './chime/emotions/emotion_bank.rb'
|
3
3
|
require_relative './chime/emotions/term_polarities.rb'
|
4
4
|
require_relative './chime/emotions/stopwords.rb'
|
5
|
+
require_relative './chime/emotions/term_categories.rb'
|
6
|
+
require_relative './chime/emotions/emotion_bank_phrases.rb'
|
7
|
+
|
5
8
|
require 'lingua/stemmer'
|
6
9
|
|
7
10
|
module Chime
|
@@ -12,6 +15,12 @@ module Chime
|
|
12
15
|
Chime.get_emotion_score(message, EmotionBank.get_term_emotions, build_term_frequencies(message))
|
13
16
|
end
|
14
17
|
|
18
|
+
# this method returns the best-fit emotion for the status message
|
19
|
+
def self.category(message)
|
20
|
+
# get the emotion for which the emotion score value is highest
|
21
|
+
Chime.get_category_score(message, TermCategories.get_term_categories, build_term_frequencies(message))
|
22
|
+
end
|
23
|
+
|
15
24
|
# this method returns the polarity value for the status message
|
16
25
|
# (normalized by the number of 'polar' words that the status
|
17
26
|
# message contains)
|
@@ -20,6 +29,30 @@ module Chime
|
|
20
29
|
Chime.get_polarity_score(message, TermPolarities.get_term_polarities, Chime.build_term_frequencies(message))
|
21
30
|
end
|
22
31
|
|
32
|
+
#TODO: Utilize stems and stop words within the next two methods.
|
33
|
+
|
34
|
+
#This method works off of phrases instead of just words
|
35
|
+
def self.category_phrases(array)
|
36
|
+
array.map{|e| TermCategories.get_term_categories.find(proc{[nil,"Undefined"]}){|k,v| e.downcase.include? k}.last}
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
#This method works off of phrases instead of just words
|
41
|
+
def self.emotion_phrases(array)
|
42
|
+
array.map{|e| EmotionBankPhrases.get_term_emotion_phrases.find(proc{[nil,"Ambiguous"]}){|k,v| e.downcase.include? k}.last}
|
43
|
+
end
|
44
|
+
|
45
|
+
#Pull EmotionBankPhrases into strictly positive hash
|
46
|
+
def self.emotion_phrases_positive_array
|
47
|
+
EmotionBankPhrases.get_term_emotion_phrases.select { |key, value| value.to_s.match("Positive") }
|
48
|
+
end
|
49
|
+
|
50
|
+
#Pull EmotionBankPhrases into strictly negative hash
|
51
|
+
def self.emotion_phrases_negative_array
|
52
|
+
EmotionBankPhrases.get_term_emotion_phrases.select { |key, value| value.to_s.match("Negative") }
|
53
|
+
end
|
54
|
+
|
55
|
+
|
23
56
|
|
24
57
|
private
|
25
58
|
|
@@ -67,11 +100,24 @@ module Chime
|
|
67
100
|
check_emoticon_for_emotion(emotion_score, message)
|
68
101
|
end
|
69
102
|
|
103
|
+
# this method takes an emotion-words hash and a hash containing word
|
104
|
+
# frequencies for the status message, calculates a numerical score
|
105
|
+
# for each possble emotion, and returns the emotion with the highest
|
106
|
+
# "score"
|
107
|
+
def self.get_category_score(message, categories, term_frequencies, category_score = {})
|
108
|
+
term_frequencies.each do |key,value|
|
109
|
+
set_categories(categories, category_score, key, value)
|
110
|
+
end
|
111
|
+
# return an emotion_score_hash to be processed by emotion
|
112
|
+
# get clue from any emoticons present
|
113
|
+
check_emoticon_for_category(category_score, message)
|
114
|
+
end
|
115
|
+
|
70
116
|
# this method gives the status method a normalized polarity
|
71
117
|
# value based on the words it contains
|
72
118
|
def self.get_polarity_score (message, polarity_hash, term_frequencies, polarity_scores = [])
|
73
119
|
term_frequencies.each do |key, value|
|
74
|
-
|
120
|
+
set_polarities(key, value, polarity_hash, polarity_scores)
|
75
121
|
end
|
76
122
|
|
77
123
|
# return an polarity_score_hash to be processed by polarity method
|
@@ -103,6 +149,12 @@ module Chime
|
|
103
149
|
end
|
104
150
|
end
|
105
151
|
|
152
|
+
def self.set_categories(categories, category_score, term, frequency)
|
153
|
+
categories.keys.each do |k|
|
154
|
+
store_categories(categories, category_score, k, term, frequency)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
106
158
|
def self.set_polarities(term, frequency, polarity_hash, polarity_scores)
|
107
159
|
polarity_hash.keys.each do |k|
|
108
160
|
store_polarities(term, k, polarity_hash, polarity_scores)
|
@@ -116,6 +168,13 @@ module Chime
|
|
116
168
|
end
|
117
169
|
end
|
118
170
|
|
171
|
+
def self.store_categories(categories, category_score, category, term, frequency)
|
172
|
+
if categories[category].include?(term)
|
173
|
+
category_score[category] ||= 0
|
174
|
+
category_score[category] += frequency
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
119
178
|
def self.store_polarities(term, word, polarity_hash, polarity_scores)
|
120
179
|
if term == word
|
121
180
|
polarity_scores << (polarity_hash[word].to_f)
|
@@ -134,6 +193,18 @@ module Chime
|
|
134
193
|
end
|
135
194
|
end
|
136
195
|
|
196
|
+
def self.check_emoticon_for_category(category_score, message)
|
197
|
+
if (happy_emoticon(message) && sad_emoticon(message))
|
198
|
+
"ambiguous-cat"
|
199
|
+
elsif happy_emoticon(message)
|
200
|
+
"joy-cat"
|
201
|
+
elsif sad_emoticon(message)
|
202
|
+
"sadness-cat"
|
203
|
+
else
|
204
|
+
return_category_score(category_score)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
137
208
|
def self.return_emotion_score(emotion_score)
|
138
209
|
## 0 if unable to detect emotion
|
139
210
|
if emotion_score == {}
|
@@ -143,6 +214,15 @@ module Chime
|
|
143
214
|
end
|
144
215
|
end
|
145
216
|
|
217
|
+
def self.return_category_score(category_score)
|
218
|
+
## 0 if unable to detect emotion
|
219
|
+
if category_score == {}
|
220
|
+
"ambiguous-cat"
|
221
|
+
else
|
222
|
+
category_score.max_by{|k, v| v}[0]
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
146
226
|
def self.check_emoticon_for_polarity(polarity_scores, message)
|
147
227
|
if (happy_emoticon(message) && sad_emoticon(message))
|
148
228
|
score = 5
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jonathanamccann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|
@@ -100,9 +100,11 @@ files:
|
|
100
100
|
- chime.gemspec
|
101
101
|
- lib/chime.rb
|
102
102
|
- lib/chime/emotions/emotion_bank.rb
|
103
|
+
- lib/chime/emotions/emotion_bank_phrases.rb
|
103
104
|
- lib/chime/emotions/emotions.csv
|
104
105
|
- lib/chime/emotions/stopwords.rb
|
105
106
|
- lib/chime/emotions/subjectivity.csv
|
107
|
+
- lib/chime/emotions/term_categories.rb
|
106
108
|
- lib/chime/emotions/term_polarities.rb
|
107
109
|
- lib/chime/version.rb
|
108
110
|
- test/helper.rb
|