sentimentalizer 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +39 -2
- data/VERSION +1 -1
- data/lib/engine/classifier.rb +1 -0
- data/lib/engine/corpus.rb +1 -1
- data/sentimentalizer.gemspec +3 -3
- data/spec/sentimentalizer_spec.rb +8 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adaa7fcb374f3b8778289f933b001a8878db2b27
|
4
|
+
data.tar.gz: 6fe6763906ebfa20cbec0083f5fa08ce90088811
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26818b295d83d8b0bf2d90cd2ea3f144052b496aaf45710e2593cbb170b3cf57791fc39f4360a8e52e35915b9cde698d473509ec21de883f0e324415ce90ac5f
|
7
|
+
data.tar.gz: cefeae99f73f11bdf590a18e8dcca0e204a8cdd5a624ade0cb1038087bd84ba8dc310048079f50e3480ce230cca080c11e3e63593eaa2f2c75dbe8cb210181b9
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ This gem can be used separately or integrated with rails app.
|
|
10
10
|
|
11
11
|
# Codeclimate [](https://codeclimate.com/github/malavbhavsar/sentimentalizer)
|
12
12
|
|
13
|
-
## Instructions for use
|
13
|
+
## Instructions for Rails use
|
14
14
|
|
15
15
|
1. Install gem using bundler `gem "sentimentalizer"`
|
16
16
|
|
@@ -23,7 +23,7 @@ Sentimentalizer.analyze('message or tweet or status')
|
|
23
23
|
Sentimentalizer.analyze('message or tweet or status', true)
|
24
24
|
```
|
25
25
|
|
26
|
-
|
26
|
+
You will get output like this
|
27
27
|
```ruby
|
28
28
|
Sentimentalizer.analyze('i am so happy')
|
29
29
|
=> {'text' => 'i am so happy', 'probability' => '0.937', 'sentiment' => ':)' }
|
@@ -31,6 +31,43 @@ Sentimentalizer.analyze('i am so happy', true)
|
|
31
31
|
=> "{\"text\":\"i am so happy\",\"probability\":\"0.937\",\"sentiment\":\":)\"}"
|
32
32
|
```
|
33
33
|
|
34
|
+
## Instructions for Vanilla Ruby use
|
35
|
+
|
36
|
+
1. Install gem using bundler `gem "sentimentalizer"`
|
37
|
+
|
38
|
+
2. Either fire up `irb`, or require it in your project with `require 'sentimentalizer'`
|
39
|
+
|
40
|
+
3. Now, you need to train the engine in order to use it
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require "sentimentalizer"
|
44
|
+
|
45
|
+
Sentimentalizer.setup
|
46
|
+
|
47
|
+
# or, wrap it in a class so setup can be automatic
|
48
|
+
class Analyzer
|
49
|
+
def initialize
|
50
|
+
Sentimentalizer.setup
|
51
|
+
end
|
52
|
+
|
53
|
+
def process(phrase)
|
54
|
+
Sentimentalizer.analyze phrase
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# or for json output
|
59
|
+
Sentimentalizer.analyze('message or tweet or status', true)
|
60
|
+
```
|
61
|
+
|
62
|
+
And now you will get output like this
|
63
|
+
```ruby
|
64
|
+
analyzer = Analyzer.new
|
65
|
+
analyzer.process('i am so happy')
|
66
|
+
=> {'text' => 'i am so happy', 'probability' => '0.937', 'sentiment' => ':)' }
|
67
|
+
analyzer.process('i am so happy', true)
|
68
|
+
=> "{\"text\":\"i am so happy\",\"probability\":\"0.937\",\"sentiment\":\":)\"}"
|
69
|
+
```
|
70
|
+
|
34
71
|
## Contributing to sentimentalizer
|
35
72
|
|
36
73
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/engine/classifier.rb
CHANGED
@@ -61,6 +61,7 @@ class Classifier
|
|
61
61
|
negative_ratio = negative_count.to_f / negative_total
|
62
62
|
|
63
63
|
probability = positive_ratio.to_f / (positive_ratio + negative_ratio)
|
64
|
+
probability = 0 if probability.nan?
|
64
65
|
|
65
66
|
((UNKNOWN_WORD_STRENGTH*UNKNOWN_WORD_PROBABILITY) + (total * probability)) / (UNKNOWN_WORD_STRENGTH+total)
|
66
67
|
end
|
data/lib/engine/corpus.rb
CHANGED
data/sentimentalizer.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: sentimentalizer 0.
|
5
|
+
# stub: sentimentalizer 0.3.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "sentimentalizer"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.3.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["malavbhavsar"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2016-04-08"
|
15
15
|
s.description = "Sentiment analysis with ruby."
|
16
16
|
s.email = "malav.bhavsar@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -4,16 +4,20 @@ describe "Sentimentalizer" do
|
|
4
4
|
before do
|
5
5
|
Sentimentalizer.setup
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
it "will error without a valid input" do
|
9
9
|
expect{Sentimentalizer.analyze("")}.to raise_error
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it "will return a valid ruby hash with a valid input" do
|
13
13
|
Sentimentalizer.analyze("I hate not tests").sentiment.should eq(":(")
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
it "will return a valid json string with a valid input" do
|
17
17
|
JSON.parse(Sentimentalizer.analyze("I hate not tests", true))["sentiment"].should eq(":(")
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
|
+
it "will assign a probability of .5 in the case of an unknown word" do
|
21
|
+
Sentimentalizer.analyze("a;lsdnzi").overall_probability.should eq(0.5)
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentimentalizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- malavbhavsar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|