sentiment_tracker 0.1.0alpha → 1.0.0beta

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
  SHA256:
3
- metadata.gz: 3490ea1586eecfb700a24a3b446f9fc81916c832404923a0a452f787d47d9523
4
- data.tar.gz: 840249ab2615a4fcb7051e285a03a9e991e6dc9dd27cabedf473be7e345f3c07
3
+ metadata.gz: d48182658fe6b71819eab46c09e16424a1868a218d1146eebc076d9ae8901210
4
+ data.tar.gz: 104635c21bbec583f7d6adde43731ffd56c5b29841b4ea9cd4a6825a216851f9
5
5
  SHA512:
6
- metadata.gz: c8823315e1f0b0bbf572a37e0acfdc18a1cf92bdf2fc98d76b407b857a9dced7cbd3f8bf7713b49565caf19f0b77325d5d22010cfffe96d2d59d8aeda06ac6aa
7
- data.tar.gz: 82dd8fe7881a5c39ca9df343cef23e4596e4929390a19afcc14d97bb8ec936cf53035c1e044e4c4fd2fa29912504088aa036eceda3f8c31a5043d597922bd443
6
+ metadata.gz: 2fbe16c776a2291e1fa2ceebd4233ac223c56f1fc56a44658f55b99f87d82ab311bba1319277872f5d60984b04a5f70511dfedf5e1791644607b3f45c7caebda
7
+ data.tar.gz: 653a0e074574140c5235914eb93027bf7029b63e2e30e2e51398d709a7853a2ec3b33fb83cb4b9f0d5a13aad1a14042d67cfa628dd0e3987d1bf783e42c90bc4
data/README.md CHANGED
@@ -4,10 +4,6 @@ SentimentTracker is a plugin Rails for keep track of sentiment analysis process.
4
4
 
5
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
6
 
7
- ## Usage
8
-
9
- How to use my plugin.
10
-
11
7
  ## Installation
12
8
 
13
9
  Add this line to your application's Gemfile:
@@ -40,6 +36,33 @@ Then:
40
36
  $ rails db:migrate
41
37
  ```
42
38
 
39
+ ## Usage
40
+
41
+ SentimentTracker is a plugin Rails for keep track of sentiment analysis process. It contains a control that process the data given throught SentimentTracker::Service. Ones the data is processed the service will create a tracks about all the responces.
42
+
43
+ The service use [sentiment-al](https://github.com/armando1339/sentiment-al) gem to execute the Sentiment Analysis .
44
+
45
+ A control is available to track the process about the texts. To access the routes call the #sentiment_tracker method into the route file.
46
+
47
+ ```ruby
48
+ # call method #sentiment_tracker:
49
+ # config/routes.rb
50
+
51
+ Rails.application.routes.draw do
52
+
53
+ sentiment_tracker
54
+ end
55
+
56
+ ```
57
+
58
+ Check routes.
59
+
60
+ ```bach
61
+ rails routes
62
+ ```
63
+
64
+ More information about the routes and request structure visit [Postman](https://documenter.getpostman.com/view/2691667/TVRn3Sen) documentation.
65
+
43
66
  ## Contributing
44
67
 
45
68
  Bug report or pull request are welcome.
@@ -1,11 +1,15 @@
1
1
  require "sentiment_tracker/railtie"
2
+ require "jbuilder"
2
3
  require "light-service"
3
4
  require "sentiment_al"
4
5
 
5
6
  require_relative 'sentiment_tracker/models/text'
6
7
  require_relative 'sentiment_tracker/models/sentence'
7
8
  require_relative 'sentiment_tracker/models/sentiment'
9
+ require_relative 'sentiment_tracker/controllers/sentiment_base_controller'
10
+ require_relative 'sentiment_tracker/controllers/texts_controller'
8
11
 
9
12
  require 'sentiment_tracker/strategies/prepare_params'
10
13
  require 'sentiment_tracker/strategies/process_sentiment'
11
14
  require 'sentiment_tracker/service'
15
+ require 'sentiment_tracker/routing'
@@ -0,0 +1,49 @@
1
+ class SentimentBaseController < ActionController::Base
2
+ protect_from_forgery with: :null_session
3
+ before_action :set_jbuilder
4
+
5
+ def build_index_json(instances)
6
+ json_builder.texts do
7
+ json_builder.array! instances do |text|
8
+ build_partial_json(text)
9
+ end
10
+ end
11
+ end
12
+
13
+ def build_show_json(instance)
14
+ json_builder.text do
15
+ build_partial_json(instance)
16
+ end
17
+ end
18
+
19
+ def build_partial_json(instance)
20
+ json_builder.call(
21
+ instance,
22
+ :id,
23
+ :description,
24
+ :created_at,
25
+ :updated_at,
26
+ :sentiment
27
+ )
28
+
29
+ json_builder.sentences do
30
+ json_builder.array! instance.sentences do |sentence|
31
+ json_builder.call(
32
+ sentence,
33
+ :id,
34
+ :description,
35
+ :created_at,
36
+ :updated_at,
37
+ :sentiment
38
+ )
39
+ end
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def set_jbuilder
46
+ self.class.send(:attr_accessor, :json_builder)
47
+ instance_variable_set(:@json_builder, Jbuilder.new)
48
+ end
49
+ end
@@ -0,0 +1,38 @@
1
+ class TextsController < SentimentBaseController
2
+ before_action :set_text, only: %i(show update destroy)
3
+
4
+ def index
5
+ render json: build_index_json(Text.includes(:sentences, :sentiment).all), status: :ok
6
+ end
7
+
8
+ def show
9
+ render json: build_show_json(@text), status: :ok
10
+ end
11
+
12
+ def create
13
+ service = SentimentTracker::Service.call params: params
14
+
15
+ if service.success?
16
+ render(
17
+ json: build_index_json(service.processed_texts),
18
+ status: :ok
19
+ )
20
+ end
21
+ end
22
+
23
+ def destroy
24
+ @text.destroy
25
+ end
26
+
27
+ private
28
+
29
+ def set_text
30
+ @text = Text.includes(:sentences, :sentiment).find params.fetch(:id)
31
+ rescue ActiveRecord::RecordNotFound
32
+ head :not_found
33
+ end
34
+
35
+ def text_params
36
+ params.permit data_processable: [:description]
37
+ end
38
+ end
@@ -3,7 +3,7 @@ class Text < ActiveRecord::Base
3
3
  # => Associations
4
4
  belongs_to :entity, polymorphic: true, optional: true
5
5
  has_one :sentiment, as: :entity, dependent: :destroy
6
- has_many :sentences, dependent: :destroy
6
+ has_many :sentences, -> { includes(:sentiment) }, dependent: :destroy
7
7
 
8
8
  # => Callbacks
9
9
  after_create :exec_sentiment_analysis
@@ -0,0 +1,20 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+
4
+ # => Inserting routes
5
+ #
6
+ # Example:
7
+ #
8
+ # sentiment_tracker do
9
+ # resources :texts
10
+ # end
11
+ #
12
+ def sentiment_tracker
13
+ scope :rails, defaults: { format: :json } do
14
+ scope :sentiment_tracker do
15
+ scope(:operations){ resources :texts }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module SentimentTracker
2
- VERSION = '0.1.0alpha'
2
+ VERSION = '1.0.0beta'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentiment_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0alpha
4
+ version: 1.0.0beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Armando Alejandre
@@ -30,6 +30,26 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 6.0.3.4
33
+ - !ruby/object:Gem::Dependency
34
+ name: jbuilder
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.10'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.10.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.10'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.10.1
33
53
  - !ruby/object:Gem::Dependency
34
54
  name: rake
35
55
  requirement: !ruby/object:Gem::Requirement
@@ -141,10 +161,13 @@ files:
141
161
  - lib/generators/sentiment_tracker_generator.rb
142
162
  - lib/generators/templates/migration.rb
143
163
  - lib/sentiment_tracker.rb
164
+ - lib/sentiment_tracker/controllers/sentiment_base_controller.rb
165
+ - lib/sentiment_tracker/controllers/texts_controller.rb
144
166
  - lib/sentiment_tracker/models/sentence.rb
145
167
  - lib/sentiment_tracker/models/sentiment.rb
146
168
  - lib/sentiment_tracker/models/text.rb
147
169
  - lib/sentiment_tracker/railtie.rb
170
+ - lib/sentiment_tracker/routing.rb
148
171
  - lib/sentiment_tracker/service.rb
149
172
  - lib/sentiment_tracker/strategies/prepare_params.rb
150
173
  - lib/sentiment_tracker/strategies/process_sentiment.rb