sad_panda 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sad_panda.rb +2 -5
- data/lib/sad_panda/emotions/stopwords.rb +2 -2
- data/lib/sad_panda/version.rb +1 -1
- data/spec/sad_panda_spec.rb +178 -0
- data/spec/spec_helper.rb +2 -2
- metadata +10 -5
- data/lib/sad_panda/emotions/datalist +0 -2
- data/spec/status_message_spec.rb +0 -185
data/lib/sad_panda.rb
CHANGED
@@ -6,9 +6,6 @@ require 'lingua/stemmer'
|
|
6
6
|
|
7
7
|
module SadPanda
|
8
8
|
|
9
|
-
attr_accessor :message, :verbose
|
10
|
-
attr_reader :stemmer
|
11
|
-
|
12
9
|
# this method reads the text of the status message
|
13
10
|
# inputed by the user, removes common english words,
|
14
11
|
# strips punctuation and capitalized letters, isolates
|
@@ -85,7 +82,7 @@ module SadPanda
|
|
85
82
|
# return an emotion_score_hash to be processed by emotion
|
86
83
|
# get clue from any emoticons present
|
87
84
|
if (@happy_que && @sad_que)
|
88
|
-
return "
|
85
|
+
return "ambiguous"
|
89
86
|
elsif @happy_que
|
90
87
|
return "joy"
|
91
88
|
elsif @sad_que
|
@@ -93,7 +90,7 @@ module SadPanda
|
|
93
90
|
else
|
94
91
|
## 0 if unable to detect emotion
|
95
92
|
if emotion_score == {}
|
96
|
-
return "
|
93
|
+
return "ambiguous"
|
97
94
|
else
|
98
95
|
score = emotion_score.max_by{|k, v| v}[0]
|
99
96
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Stopwords
|
2
|
-
# common english words
|
2
|
+
# common english words
|
3
3
|
def self.stopwords
|
4
4
|
%w{i a a's able about above according accordingly across actually after
|
5
5
|
afterwards again against ain't all allow allows almost alone along already also although
|
@@ -39,4 +39,4 @@ module Stopwords
|
|
39
39
|
with within without won't wonder would would wouldn't x y yes yet yo you you'd you'll you're you've your yours
|
40
40
|
yourself yourselves z zero}
|
41
41
|
end
|
42
|
-
end
|
42
|
+
end
|
data/lib/sad_panda/version.rb
CHANGED
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe SadPanda do
|
5
|
+
|
6
|
+
let(:emotions) {EmotionBank.get_term_emotions}
|
7
|
+
let(:polarities) {TermPolarities.get_term_polarities}
|
8
|
+
let(:term_frequencies) {SadPanda.build_term_frequencies("My cactus collection makes me happy.")}
|
9
|
+
|
10
|
+
describe "when 'build_term_frequencies' method is called" do
|
11
|
+
|
12
|
+
context "when status_message is an empty string" do
|
13
|
+
it "returns an empty hash" do
|
14
|
+
empty_message = " "
|
15
|
+
expect(SadPanda.build_term_frequencies(empty_message)).to be_empty
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when input is a non-recogizable word" do
|
20
|
+
it "returns a empty hash with key == zorg and and value == 1" do
|
21
|
+
word = "zorg"
|
22
|
+
expect(SadPanda.build_term_frequencies(word)).to eql({"zorg" => 1})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when input includes recognizable words" do
|
27
|
+
it "returns a non-empty hash" do
|
28
|
+
hash = SadPanda.build_term_frequencies("I am happy")
|
29
|
+
expect(hash).to_not be_empty
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "when 'get_emotion_score' method is called" do
|
36
|
+
it 'returns a string' do
|
37
|
+
output = SadPanda.get_emotion_score emotions,term_frequencies
|
38
|
+
expect(output.class).to eql(String)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "when 'get_polarity_score' method is called" do
|
43
|
+
it 'returns a string' do
|
44
|
+
output = SadPanda.get_polarity_score polarities,term_frequencies
|
45
|
+
expect(output.class).to eql(Fixnum)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
describe "when polarity method is called" do
|
51
|
+
|
52
|
+
it "returns a fixnum" do
|
53
|
+
expect(SadPanda.polarity("My cactus collection makes me happy.").class).to eql(Fixnum)
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when status_message == 'my lobster collection makes me happy' " do
|
57
|
+
it "emotion == 'joy' " do
|
58
|
+
status_message = "my lobster collection makes me happy"
|
59
|
+
expect(SadPanda.emotion(status_message)).to eql("joy")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when status_message == 'sad' " do
|
64
|
+
it "emotion == 'sadness' " do
|
65
|
+
status_message = "sad"
|
66
|
+
expect(SadPanda.emotion(status_message)).to eql("sadness")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when status_message == 'angry' " do
|
71
|
+
it "emotion == 'anger' " do
|
72
|
+
status_message = "angry"
|
73
|
+
expect(SadPanda.emotion(status_message)).to eql('anger')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when status_message == 'I am ril afraid of cats, homie' " do
|
78
|
+
it "emotion == 'fear' " do
|
79
|
+
status_message = "I am ril afraid of cats, homie"
|
80
|
+
expect(SadPanda.emotion(status_message)).to eql("fear")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when status == 'I am disgusted' " do
|
85
|
+
it "emotion == 'disgust'" do
|
86
|
+
status_message = "I am disgusted"
|
87
|
+
expect(SadPanda.emotion(status_message)).to eql('disgust')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "when status == 'I am so surprised'" do
|
92
|
+
it "emotion == 'surprise'" do
|
93
|
+
status_message = "I am so surprised"
|
94
|
+
expect(SadPanda.emotion(status_message)).to eql('surprise')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "when status_message == 'blarg' " do
|
99
|
+
it "emotion == 'ambiguous' " do
|
100
|
+
status_message = "blarg"
|
101
|
+
expect(SadPanda.emotion(status_message)).to eql('ambiguous')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "when status_message == ' ' " do
|
106
|
+
it "emotion is 'ambiguous'" do
|
107
|
+
status_message = " "
|
108
|
+
expect(SadPanda.emotion(status_message)).to eql('ambiguous')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "when emotion method is called" do
|
115
|
+
|
116
|
+
it "returns a string" do
|
117
|
+
status_message="joy"
|
118
|
+
expect(SadPanda.emotion(status_message).class).to eql(String)
|
119
|
+
end
|
120
|
+
|
121
|
+
context "when status_message == 'I am happy' " do
|
122
|
+
it "polarity is greater than zero" do
|
123
|
+
status_message = "I am happy"
|
124
|
+
expect(SadPanda.polarity(status_message)).to be > 0
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
context "when status_message == 'sad' " do
|
130
|
+
it "polarity is less than zero" do
|
131
|
+
status_message = "sad"
|
132
|
+
expect(SadPanda.polarity(status_message)).to be < 5
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "when status_message == 'anger' " do
|
137
|
+
it "polarity is zero" do
|
138
|
+
status_message = "anger"
|
139
|
+
expect(SadPanda.polarity(status_message)).to be < 5
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "when status_message == 'I am terrified' " do
|
144
|
+
it "polarity is zero" do
|
145
|
+
status_message = "I am fearful"
|
146
|
+
expect(SadPanda.polarity(status_message)).to be < 5
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "when status == 'I am disgusted' " do
|
151
|
+
it "has a non-zero polarity value" do
|
152
|
+
status_message = "I am disgusted"
|
153
|
+
expect(SadPanda.polarity(status_message)).to be < 5
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "when status == 'This is surprising'" do
|
158
|
+
it "has a neutral polarity value" do
|
159
|
+
status_message = "This is surprising"
|
160
|
+
expect(SadPanda.polarity(status_message)).to eql(5)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "when status_message == 'blarg' " do
|
165
|
+
it "polarity is zero" do
|
166
|
+
status_message = "blarg"
|
167
|
+
expect(SadPanda.polarity(status_message)).to eql(5)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "when status_message == ' ' " do
|
172
|
+
it "polarity is zero" do
|
173
|
+
status_message = " "
|
174
|
+
expect(SadPanda.polarity(status_message)).to eql(5)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'sad_panda/version'
|
2
|
-
require 'sad_panda
|
2
|
+
require './lib/sad_panda'
|
3
3
|
require 'lingua/stemmer'
|
4
4
|
require './lib/sad_panda/emotions/emotion_bank'
|
5
5
|
require './lib/sad_panda/emotions/term_polarities'
|
6
|
-
require './lib/sad_panda/emotions/stopwords'
|
6
|
+
require './lib/sad_panda/emotions/stopwords'
|
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.
|
4
|
+
version: 0.2.1
|
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-
|
12
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -90,7 +90,6 @@ files:
|
|
90
90
|
- README.md
|
91
91
|
- Rakefile
|
92
92
|
- lib/sad_panda.rb
|
93
|
-
- lib/sad_panda/emotions/datalist
|
94
93
|
- lib/sad_panda/emotions/emotion_bank.rb
|
95
94
|
- lib/sad_panda/emotions/emotions.csv
|
96
95
|
- lib/sad_panda/emotions/stopwords.rb
|
@@ -99,8 +98,8 @@ files:
|
|
99
98
|
- lib/sad_panda/version.rb
|
100
99
|
- sad_panda.gemspec
|
101
100
|
- spec/emotion_bank_spec.rb
|
101
|
+
- spec/sad_panda_spec.rb
|
102
102
|
- spec/spec_helper.rb
|
103
|
-
- spec/status_message_spec.rb
|
104
103
|
- spec/term_polarities_spec.rb
|
105
104
|
homepage: ''
|
106
105
|
licenses:
|
@@ -115,12 +114,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
114
|
- - ! '>='
|
116
115
|
- !ruby/object:Gem::Version
|
117
116
|
version: '0'
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
hash: 1579113864349454449
|
118
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
121
|
none: false
|
120
122
|
requirements:
|
121
123
|
- - ! '>='
|
122
124
|
- !ruby/object:Gem::Version
|
123
125
|
version: '0'
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
hash: 1579113864349454449
|
124
129
|
requirements: []
|
125
130
|
rubyforge_project:
|
126
131
|
rubygems_version: 1.8.25
|
@@ -130,6 +135,6 @@ summary: ! 'sad_panda is a gem featuring tools for sentiment analysis of natural
|
|
130
135
|
positivity/negativity and emotion classification.'
|
131
136
|
test_files:
|
132
137
|
- spec/emotion_bank_spec.rb
|
138
|
+
- spec/sad_panda_spec.rb
|
133
139
|
- spec/spec_helper.rb
|
134
|
-
- spec/status_message_spec.rb
|
135
140
|
- spec/term_polarities_spec.rb
|
data/spec/status_message_spec.rb
DELETED
@@ -1,185 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module SadPanda
|
4
|
-
describe StatusMessage do
|
5
|
-
|
6
|
-
let(:status_message) {SadPanda::StatusMessage.new "a message"}
|
7
|
-
let(:emotions) {EmotionBank.get_term_emotions}
|
8
|
-
let(:polarities) {TermPolarities.get_term_polarities}
|
9
|
-
let(:term_frequencies) {status_message.build_term_frequencies}
|
10
|
-
|
11
|
-
describe "when initialized" do
|
12
|
-
it "verbose defaults to false" do
|
13
|
-
expect(status_message.verbose).to be_false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "when 'build_term_frequencies' method is called" do
|
18
|
-
context "when status_message is an empty string" do
|
19
|
-
it "returns an empty hash" do
|
20
|
-
empty_message = SadPanda::StatusMessage.new " "
|
21
|
-
expect(empty_message.build_term_frequencies).to be_empty
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when status_message is a non-recogizable word" do
|
26
|
-
it "returns a empty hash with key == zorg and and value == 1" do
|
27
|
-
word = "zorg"
|
28
|
-
strange_message = SadPanda::StatusMessage.new word
|
29
|
-
expect(strange_message.build_term_frequencies).to eql({"zorg" => 1})
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when status_message includes recognizable words" do
|
34
|
-
it "returns a non-empty hash" do
|
35
|
-
hash = status_message.build_term_frequencies
|
36
|
-
expect(hash).to_not be_empty
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "when 'get_emotion_score' method is called" do
|
42
|
-
it 'returns a string' do
|
43
|
-
output = status_message.get_emotion_score emotions,term_frequencies
|
44
|
-
expect(output.class).to eql(String)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "when 'get_polarity_score' method is called" do
|
49
|
-
it 'returns a string' do
|
50
|
-
output = status_message.get_polarity_score polarities,term_frequencies
|
51
|
-
expect(output.class).to eql(Fixnum)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
describe "when polarity method is called" do
|
57
|
-
|
58
|
-
it "returns a fixnum" do
|
59
|
-
expect(status_message.polarity.class).to eql(Fixnum)
|
60
|
-
end
|
61
|
-
|
62
|
-
context "when status_message == 'my lobster collection makes me happy' " do
|
63
|
-
it "emotion == 'joy' " do
|
64
|
-
status_message = SadPanda::StatusMessage.new "my lobster collection makes me happy"
|
65
|
-
expect(status_message.emotion).to eql("joy")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when status_message == 'sad' " do
|
70
|
-
it "emotion == 'sadness' " do
|
71
|
-
status_message = SadPanda::StatusMessage.new "sad"
|
72
|
-
expect(status_message.emotion).to eql("sadness")
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "when status_message == 'angry' " do
|
77
|
-
it "emotion == 'anger' " do
|
78
|
-
status_message = SadPanda::StatusMessage.new "angry"
|
79
|
-
expect(status_message.emotion).to eql('anger')
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "when status_message == 'I am ril afraid of cats, homie' " do
|
84
|
-
it "emotion == 'fear' " do
|
85
|
-
status_message = SadPanda::StatusMessage.new "I am ril afraid of cats, homie"
|
86
|
-
expect(status_message.emotion).to eql("fear")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context "when status == 'I am disgusted' " do
|
91
|
-
it "emotion == 'disgust'" do
|
92
|
-
status_message = SadPanda::StatusMessage.new "I am disgusted"
|
93
|
-
expect(status_message.emotion).to eql('disgust')
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
context "when status == 'I am so surprised'" do
|
98
|
-
it "emotion == 'surprise'" do
|
99
|
-
status_message = SadPanda::StatusMessage.new "I am so surprised"
|
100
|
-
expect(status_message.emotion).to eql('surprise')
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "when status_message == 'blarg' " do
|
105
|
-
it "emotion == 'uncertain' " do
|
106
|
-
status_message = SadPanda::StatusMessage.new "blarg"
|
107
|
-
expect(status_message.emotion).to eql('uncertain')
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "when status_message == ' ' " do
|
112
|
-
it "emotion is 'uncertain'" do
|
113
|
-
status_message = SadPanda::StatusMessage.new " "
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
describe "when emotion method is called" do
|
120
|
-
|
121
|
-
it "returns a string" do
|
122
|
-
expect(status_message.emotion.class).to eql(String)
|
123
|
-
end
|
124
|
-
|
125
|
-
context "when status_message == 'I am happy' " do
|
126
|
-
it "polarity is greater than zero" do
|
127
|
-
status_message = SadPanda::StatusMessage.new "I am happy"
|
128
|
-
expect(status_message.polarity).to be > 0
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
|
133
|
-
context "when status_message == 'sad' " do
|
134
|
-
it "polarity is less than zero" do
|
135
|
-
status_message = SadPanda::StatusMessage.new "sad"
|
136
|
-
expect(status_message.polarity).to be < 5
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
context "when status_message == 'anger' " do
|
141
|
-
it "polarity is zero" do
|
142
|
-
status_message = SadPanda::StatusMessage.new "anger"
|
143
|
-
expect(status_message.polarity).to be < 5
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context "when status_message == 'I am terrified' " do
|
148
|
-
it "polarity is zero" do
|
149
|
-
status_message = SadPanda::StatusMessage.new "I am fearful"
|
150
|
-
expect(status_message.polarity).to be < 5
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
context "when status == 'I am disgusted' " do
|
155
|
-
it "has a non-zero polarity value" do
|
156
|
-
status_message = SadPanda::StatusMessage.new "I am disgusted"
|
157
|
-
expect(status_message.polarity).to be < 5
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context "when status == 'This is surprising'" do
|
162
|
-
it "has a neutral polarity value" do
|
163
|
-
status_message = SadPanda::StatusMessage.new "This is surprising"
|
164
|
-
expect(status_message.polarity).to eql(5)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context "when status_message == 'blarg' " do
|
169
|
-
it "polarity is zero" do
|
170
|
-
status_message = SadPanda::StatusMessage.new "blarg"
|
171
|
-
expect(status_message.polarity).to eql(5)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context "when status_message == ' ' " do
|
176
|
-
it "polarity is zero" do
|
177
|
-
status_message = SadPanda::StatusMessage.new " "
|
178
|
-
expect(status_message.polarity).to eql(5)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
end
|
185
|
-
end
|