ibmsag 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ibms.rb +74 -0
  3. metadata +43 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9617694121424f4201415b2489333f29b5e705a9
4
+ data.tar.gz: 63279d98a8ce74068f27eb09a261e3d31dd865a1
5
+ SHA512:
6
+ metadata.gz: aa0043377ff287320ca7e0f6ac6c18392f08758737b436d715123f2edb0ff2bffff9d69bd7aa5c6adf91d73876e3079b5a6082d90a5c686cafa61d34c7bb1bb9
7
+ data.tar.gz: bd45d504befabb25a2fe50d03a3d970d51ced8c30e4d45ae3b00ebe07d517dc386d4740feb53639aa2d6ce8af406a7e29652b5a12190e0dfa10e2900f408938e
@@ -0,0 +1,74 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ require 'rubygems'
6
+ require 'excon'
7
+
8
+
9
+ class IbmS
10
+
11
+ def self.analyze(text,user,password)
12
+
13
+ @url = "https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone"
14
+
15
+
16
+
17
+ @data = {text:text}
18
+
19
+ response = Excon.post(@url,
20
+ :body => @data.to_json,
21
+ :headers => {
22
+ "Content-Type" => "application/json",
23
+ "Content-Language" => "en",
24
+ "Accept-Language" => "en"
25
+ },
26
+ :query => {
27
+ "raw_scores" => true,
28
+ "consumption_preferences" => true,
29
+ "version" => "2017-09-21"
30
+ },
31
+ :user => user,
32
+ :password => password)
33
+
34
+
35
+ puts response.body
36
+
37
+ return self.getOvereallTone(response.body)
38
+
39
+
40
+ end
41
+
42
+ def self.getOvereallTone(json_data)
43
+ data = JSON.parse(json_data)
44
+ score = 0
45
+
46
+ data['document_tone']['tones'].each do |tone|
47
+ tone = tone['tone_name']
48
+
49
+ if tone == 'Anger' then
50
+ score = score - 1
51
+ end
52
+ if tone == 'Fear' then
53
+ score = score - 1
54
+ end
55
+ if tone == 'Sadness' then
56
+ score = score - 1
57
+ end
58
+ if tone == 'Joy' then
59
+ score = score + 1
60
+ end
61
+ if tone == 'Confident' then
62
+ score = score + 1
63
+ end
64
+ if tone == 'Tentative' then
65
+ score = score + 1
66
+ end
67
+
68
+ end
69
+
70
+ return score
71
+
72
+ end
73
+
74
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ibmsag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - DrDeStro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: IbmSentiment Gem
14
+ email: denmantm@inbox.lv
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/ibms.rb
20
+ homepage: http://rubygems.org/gems/ibmsag
21
+ licenses: []
22
+ metadata: {}
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ requirements: []
38
+ rubyforge_project:
39
+ rubygems_version: 2.6.11
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Gem that checks the sentiments!
43
+ test_files: []