sentiment_tracker 0.1.0alpha

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3490ea1586eecfb700a24a3b446f9fc81916c832404923a0a452f787d47d9523
4
+ data.tar.gz: 840249ab2615a4fcb7051e285a03a9e991e6dc9dd27cabedf473be7e345f3c07
5
+ SHA512:
6
+ metadata.gz: c8823315e1f0b0bbf572a37e0acfdc18a1cf92bdf2fc98d76b407b857a9dced7cbd3f8bf7713b49565caf19f0b77325d5d22010cfffe96d2d59d8aeda06ac6aa
7
+ data.tar.gz: 82dd8fe7881a5c39ca9df343cef23e4596e4929390a19afcc14d97bb8ec936cf53035c1e044e4c4fd2fa29912504088aa036eceda3f8c31a5043d597922bd443
@@ -0,0 +1,20 @@
1
+ Copyright 2020
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,59 @@
1
+ # SentimentTracker
2
+
3
+ SentimentTracker is a plugin Rails for keep track of sentiment analysis process.
4
+
5
+ [![Build Status](https://travis-ci.org/armando1339/sentiment_tracker.svg?branch=master)](https://travis-ci.org/armando1339/sentiment_tracker) [![Coverage Status](https://coveralls.io/repos/github/armando1339/sentiment_tracker/badge.svg?branch=master)](https://coveralls.io/github/armando1339/sentiment_tracker?branch=master)
6
+
7
+ ## Usage
8
+
9
+ How to use my plugin.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'sentiment_tracker'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```bash
22
+ $ bundle install
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```bash
28
+ $ gem install sentiment_tracker
29
+ ```
30
+
31
+ Ones installed, generate migrations:
32
+
33
+ ```bash
34
+ $ rails generate sentiment_tracker
35
+ ```
36
+
37
+ Then:
38
+
39
+ ```bash
40
+ $ rails db:migrate
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ Bug report or pull request are welcome.
46
+
47
+ Make a pull request:
48
+
49
+ - Clone the repo
50
+ - Create your feature branch
51
+ - Commit your changes
52
+ - Push the branch
53
+ - Create PR
54
+
55
+ Please write tests if necessary.
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SentimentTracker'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+ require "rspec/core/rake_task"
19
+
20
+ RSpec::Core::RakeTask.new(:spec)
21
+ task default: :spec
@@ -0,0 +1,25 @@
1
+ class SentimentTrackerGenerator < Rails::Generators::Base
2
+ include Rails::Generators::Migration
3
+ source_root File.expand_path('templates', __dir__)
4
+
5
+ def migration
6
+ migration_template(
7
+ 'migration.rb',
8
+ 'db/migrate/create_sentiment_tracker.rb'
9
+ )
10
+ end
11
+
12
+ def rails5_and_up?
13
+ Rails::VERSION::MAJOR >= 5
14
+ end
15
+
16
+ def migration_version
17
+ if rails5_and_up?
18
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
19
+ end
20
+ end
21
+
22
+ def self.next_migration_number(dir)
23
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ class CreateSentimentTracker < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ create_table :texts do |t|
4
+ t.string :description
5
+ t.references :entity, polymorphic: true, index: true
6
+ t.timestamps
7
+ end
8
+
9
+ create_table :sentences do |t|
10
+ t.string :description
11
+ t.references :text, foreign_key: true, index: true
12
+ t.timestamps
13
+ end
14
+
15
+ create_table :sentiments do |t|
16
+ t.string :polarity
17
+ t.string :kind
18
+ t.references :entity, polymorphic: true, index: true
19
+ t.timestamps
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ require "sentiment_tracker/railtie"
2
+ require "light-service"
3
+ require "sentiment_al"
4
+
5
+ require_relative 'sentiment_tracker/models/text'
6
+ require_relative 'sentiment_tracker/models/sentence'
7
+ require_relative 'sentiment_tracker/models/sentiment'
8
+
9
+ require 'sentiment_tracker/strategies/prepare_params'
10
+ require 'sentiment_tracker/strategies/process_sentiment'
11
+ require 'sentiment_tracker/service'
@@ -0,0 +1,12 @@
1
+ class Sentence < ActiveRecord::Base
2
+
3
+ # => Associations
4
+ belongs_to :text, touch: true
5
+ has_one :sentiment, as: :entity, dependent: :destroy
6
+
7
+ # => Validations
8
+ validates_presence_of :description
9
+
10
+ # => Nested
11
+ accepts_nested_attributes_for :sentiment
12
+ end
@@ -0,0 +1,8 @@
1
+ class Sentiment < ActiveRecord::Base
2
+
3
+ # => Associations
4
+ belongs_to :entity, polymorphic: true
5
+
6
+ # => Validations
7
+ validates_presence_of :polarity, :kind
8
+ end
@@ -0,0 +1,59 @@
1
+ class Text < ActiveRecord::Base
2
+
3
+ # => Associations
4
+ belongs_to :entity, polymorphic: true, optional: true
5
+ has_one :sentiment, as: :entity, dependent: :destroy
6
+ has_many :sentences, dependent: :destroy
7
+
8
+ # => Callbacks
9
+ after_create :exec_sentiment_analysis
10
+
11
+ # => Validations
12
+ validates_presence_of :description
13
+
14
+ # => Nested
15
+ accepts_nested_attributes_for :sentences, :sentiment
16
+
17
+ # => Execute the request to SENTIM-API
18
+ # and process the responces creating
19
+ # some trackeable data
20
+ #
21
+ def exec_sentiment_analysis
22
+ sentiment_al.call text: description
23
+
24
+ create_tracking! if sentiment_al.successfully?
25
+ end
26
+
27
+ private
28
+
29
+ # => *
30
+ def create_tracking!
31
+ update(
32
+ sentences_attributes: build_track_params,
33
+ sentiment_attributes: build_result_params
34
+ )
35
+ end
36
+
37
+ # => *
38
+ def build_track_params
39
+ sentiment_al.response_to_hash.fetch('sentences').each do |sentence|
40
+ sentence.transform_keys!{ |key| keys_map[key] }
41
+ sentence.fetch('sentiment_attributes').transform_keys!{ |key| keys_map[key] }
42
+ end
43
+ end
44
+
45
+ # => *
46
+ def build_result_params
47
+ sentiment_al.response_to_hash.fetch('result').transform_keys!{ |key| keys_map[key] }
48
+ end
49
+
50
+ # => *
51
+ def keys_map
52
+ {
53
+ 'sentence' => 'description',
54
+ 'sentiment' => 'sentiment_attributes',
55
+ 'type' => 'kind',
56
+ 'polarity' => 'polarity'
57
+ }
58
+ end
59
+ end
@@ -0,0 +1,4 @@
1
+ module SentimentTracker
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ module SentimentTracker
2
+ class Service
3
+ extend LightService::Organizer
4
+
5
+ def self.call(args = {})
6
+ with(args).reduce(
7
+ [
8
+ SentimentTracker::PrepareParams,
9
+ SentimentTracker::ProcessSentiment
10
+ ]
11
+ )
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module SentimentTracker
2
+ class PrepareParams
3
+ extend LightService::Action
4
+ expects :params
5
+
6
+ executed do |context|
7
+ unless context.params.kind_of? ActionController::Parameters
8
+ context.params = ActionController::Parameters.new context.params
9
+ end
10
+
11
+ context.params = context.params.permit(data_processable: [:description])
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module SentimentTracker
2
+ class ProcessSentiment
3
+ extend LightService::Action
4
+ expects :params
5
+ promises :processed_texts
6
+
7
+ executed do |context|
8
+ context.processed_texts = Text.create context.params.fetch('data_processable')
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module SentimentTracker
2
+ VERSION = '0.1.0alpha'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :sentiment_tracker do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sentiment_tracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0alpha
5
+ platform: ruby
6
+ authors:
7
+ - Armando Alejandre
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.3
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 6.0.3.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 6.0.3
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 6.0.3.4
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: pg
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec-rails
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: shoulda-matchers
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: shoulda-callback-matchers
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: coveralls
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: pry-rails
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ description: Plugin Rails for keep track of sentiment analysis process
132
+ email:
133
+ - armando1339@gmail.com
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - MIT-LICENSE
139
+ - README.md
140
+ - Rakefile
141
+ - lib/generators/sentiment_tracker_generator.rb
142
+ - lib/generators/templates/migration.rb
143
+ - lib/sentiment_tracker.rb
144
+ - lib/sentiment_tracker/models/sentence.rb
145
+ - lib/sentiment_tracker/models/sentiment.rb
146
+ - lib/sentiment_tracker/models/text.rb
147
+ - lib/sentiment_tracker/railtie.rb
148
+ - lib/sentiment_tracker/service.rb
149
+ - lib/sentiment_tracker/strategies/prepare_params.rb
150
+ - lib/sentiment_tracker/strategies/process_sentiment.rb
151
+ - lib/sentiment_tracker/version.rb
152
+ - lib/tasks/sentiment_tracker_tasks.rake
153
+ homepage: https://github.com/armando1339
154
+ licenses:
155
+ - MIT
156
+ metadata:
157
+ allowed_push_host: https://rubygems.org/
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">"
170
+ - !ruby/object:Gem::Version
171
+ version: 1.3.1
172
+ requirements: []
173
+ rubygems_version: 3.1.4
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: SentimentTracker is a plugin Rails for keep track of sentiment analysis process.
177
+ test_files: []