sentimentalizer 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3157d1123401a03ced17de7c55e6115331490aa
4
- data.tar.gz: 07869dd69cb3bd464b3d391b35546b70348b6a46
3
+ metadata.gz: adaa7fcb374f3b8778289f933b001a8878db2b27
4
+ data.tar.gz: 6fe6763906ebfa20cbec0083f5fa08ce90088811
5
5
  SHA512:
6
- metadata.gz: be56e07803500a0714e23061e14fb27f06020671cad0c70622219b75907c90e8c897e52360bda6e3f29964047b4737d95fb5592096ea3abcca0c63a93cf8d132
7
- data.tar.gz: 458e80553d5b36aa2b068a9dd002c8a7471875e3e5f9284543889b6535f624edcfcb55f0ec1cfd8960e3fc593b9db0f0c44a3acc5624a1dfe953f9ac6fabc810
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 [![Code Climate](https://codeclimate.com/github/malavbhavsar/sentimentalizer.png)](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
- 4. You will get output like this
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.2.2
1
+ 0.3.0
@@ -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
@@ -18,7 +18,7 @@ class Corpus
18
18
 
19
19
  def load_from_directory directory
20
20
  Dir.glob("#{directory}/*.txt") do |entry|
21
- IO.foreach(entry) do |line|
21
+ IO.foreach(entry, encoding: Encoding::UTF_8) do |line|
22
22
  add Document.new(line)
23
23
  end
24
24
  end
@@ -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.2.2 ruby lib
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.2.2"
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 = "2014-12-27"
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
- end
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.2.2
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: 2014-12-27 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec