logstash-filter-sentimentalizer 0.2.0 → 0.2.1

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: d01ae62913663f01498106240233691ba9554a7b
4
- data.tar.gz: cd400d8bd6e832f8161f0a8365575cca9acfb467
3
+ metadata.gz: 985434fa92185812a9723b193bbf35993c35cd39
4
+ data.tar.gz: 2d9778a8dc3854c1d8eee28a95a846b02f23579b
5
5
  SHA512:
6
- metadata.gz: 831e9ca15c91a307d0a13c220b7d102e96c6f46f606af045cbcd004553ee20b262006e0918e8280d9894ad6bd7c9913b69be05c18c62b296127fe095aa2361c0
7
- data.tar.gz: 44f9e8b5842088167d85bf895aead64e660759bbbf6a58f8a1d3a2752e5cf11af0152243827a44a4b64605eec672ffe5a64e5cb098f44eae754d41968f4b7bd5
6
+ metadata.gz: 2d5d64917cdcc72cf81c95c09a6a1271a2fe20eda29bb137c3b6382f71d70c9a797696dcc6a45bf688fda48856b8fdd285fedfb73654033787f31fd8fb5a9ce4
7
+ data.tar.gz: 4b6efdc4e66ffae2c9267d5f92514c368a62a8980211fd44c96873f7756216a27fa8b27694baa9eb1af51385b6a8b93f73ae97bc2854f8dfe5c662f125d409bc
data/.travis.yml CHANGED
@@ -1,6 +1,13 @@
1
+ ---
2
+ sudo: false
1
3
  language: ruby
2
-
3
- rvm:
4
- - jruby
5
-
4
+ cache: bundler
5
+ matrix:
6
+ include:
7
+ - rvm: jruby-9.1.13.0
8
+ - rvm: jruby-9.1.13.0
9
+ - rvm: jruby-9.1.13.0
10
+ - rvm: jruby-1.7.27
11
+ fast_finish: true
12
+ jdk: oraclejdk8
6
13
  script: 'bundle exec rspec'
data/README.md CHANGED
@@ -1,6 +1,25 @@
1
- # Logstash Plugin
1
+ # logstash-filter-sentimentalizer [![Build Status](https://travis-ci.org/tylerjl/logstash-filter-sentimentalizer.svg?branch=master)](https://travis-ci.org/tylerjl/logstash-filter-sentimentalizer)
2
2
 
3
- This is a plugin for [Logstash](https://github.com/elasticsearch/logstash). [![Build Status](https://travis-ci.org/tylerjl/logstash-filter-sentimentalizer.svg?branch=master)](https://travis-ci.org/tylerjl/logstash-filter-sentimentalizer)
3
+ This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
4
+
5
+ This plugin enables you to perform effective sentiment analysis on arbitrary event fields with pretty simple configuration.
6
+ Consider the following:
7
+
8
+ ```
9
+ filter {
10
+ sentimentalizer {
11
+ source => "message"
12
+ }
13
+ }
14
+ ```
15
+
16
+ Is enough to perform sentiment analysis on the `message` field.
17
+
18
+ Results are stored in the `sentiment.probability` (a float between 0 and 1, 0 being wholly negative and 1 being maximum positive) and `sentiment.polarity` (an enum with the members "positive", "negative", and "neutral") fields of the processed event (these names come from the underlying sentiment analysis library).
19
+
20
+ Here's a short demo of it in action.
21
+
22
+ ![logstash demo gif](./demo.gif)
4
23
 
5
24
  It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
25
 
data/demo.gif ADDED
Binary file
@@ -34,12 +34,13 @@ class LogStash::Filters::Sentimentalizer < LogStash::Filters::Base
34
34
  def filter(event)
35
35
  return unless filter?(event)
36
36
 
37
- source = event.get(@source)
38
- source.gsub!(/\B#(\S+)\b/, '\1') if @scrub
37
+ source = event.get(@source).dup
39
38
 
40
39
  unless source.nil?
41
40
  begin
42
- sentiment = Sentimentalizer.analyze(source)
41
+ sentiment = Sentimentalizer.analyze(
42
+ @scrub ? source.gsub(/\B#(\S+)\b/, '\1') : source
43
+ )
43
44
  rescue NoMethodError => e
44
45
  @logger.error(
45
46
  'Error parsing sentiment for field',
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-sentimentalizer'
3
- s.version = '0.2.0'
3
+ s.version = '0.2.1'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = 'This plugin will analyze sentiment of a specified field.'
6
6
  s.description = 'A logstash plugin to derive sentiment from fields.'
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency 'sentimentalizer', '~> 0.3.0'
25
25
 
26
26
  s.add_development_dependency 'logstash-devutils', '~> 1.0'
27
+ s.add_development_dependency 'rspec', '~> 3.0'
27
28
  end
@@ -1,75 +1,78 @@
1
1
  require 'spec_helper'
2
- require "logstash/filters/sentimentalizer"
2
+ require 'logstash/filters/sentimentalizer'
3
3
 
4
4
  describe LogStash::Filters::Sentimentalizer do
5
5
  describe 'default sentiment configuration' do
6
- let(:config) do <<-CONFIG
7
- filter {
8
- sentimentalizer { }
9
- }
10
- CONFIG
6
+ let(:config) do
7
+ <<-CONFIG
8
+ filter {
9
+ sentimentalizer { }
10
+ }
11
+ CONFIG
11
12
  end
12
13
 
13
14
  sample 'Horrible' do
14
- expect(subject).to include("message")
15
- expect(subject['sentiment']['polarity']).to eq('negative')
16
- expect(subject['sentiment']['probability']).to be_a(Float)
17
- expect(subject['sentiment']['probability']).to be < 0.5
15
+ expect(subject).to include('message')
16
+ expect(subject.get('sentiment')['polarity']).to eq('negative')
17
+ expect(subject.get('sentiment')['probability']).to be_a(Float)
18
+ expect(subject.get('sentiment')['probability']).to be < 0.5
18
19
  end
19
20
 
20
21
  sample 'Fantastic' do
21
- expect(subject).to include("message")
22
- expect(subject['sentiment']['polarity']).to eq('positive')
23
- expect(subject['sentiment']['probability']).to be_a(Float)
24
- expect(subject['sentiment']['probability']).to be > 0.5
22
+ expect(subject).to include('message')
23
+ expect(subject.get('sentiment')['polarity']).to eq('positive')
24
+ expect(subject.get('sentiment')['probability']).to be_a(Float)
25
+ expect(subject.get('sentiment')['probability']).to be > 0.5
25
26
  end
26
27
  end
27
28
 
28
29
  describe 'twitter hashtag scoring without scrubbing' do
29
- let(:config) do <<-CONFIG
30
- filter {
31
- sentimentalizer {
32
- scrub => false
30
+ let(:config) do
31
+ <<-CONFIG
32
+ filter {
33
+ sentimentalizer {
34
+ scrub => false
35
+ }
33
36
  }
34
- }
35
- CONFIG
37
+ CONFIG
36
38
  end
37
39
 
38
40
  sample 'What a #horrible idea' do
39
- expect(subject).to include("message")
40
- expect(subject['sentiment']['probability']).to be_a(Float)
41
- expect(subject['sentiment']['probability']).to be_within(0.1).of(0.5)
41
+ expect(subject).to include('message')
42
+ expect(subject.get('sentiment')['probability']).to be_a(Float)
43
+ expect(subject.get('sentiment')['probability']).to be_within(0.1).of(0.5)
42
44
  end
43
45
 
44
46
  sample 'What a #fantastic idea' do
45
- expect(subject).to include("message")
46
- expect(subject['sentiment']['probability']).to be_a(Float)
47
- expect(subject['sentiment']['probability']).to be_within(0.1).of(0.5)
47
+ expect(subject).to include('message')
48
+ expect(subject.get('sentiment')['probability']).to be_a(Float)
49
+ expect(subject.get('sentiment')['probability']).to be_within(0.1).of(0.5)
48
50
  end
49
51
  end
50
52
 
51
53
  describe 'twitter hashtag scoring with scrubbing' do
52
- let(:config) do <<-CONFIG
53
- filter {
54
- sentimentalizer {
55
- scrub => true
54
+ let(:config) do
55
+ <<-CONFIG
56
+ filter {
57
+ sentimentalizer {
58
+ scrub => true
59
+ }
56
60
  }
57
- }
58
- CONFIG
61
+ CONFIG
59
62
  end
60
63
 
61
64
  sample 'What a #horrible idea' do
62
- expect(subject).to include("message")
63
- expect(subject['sentiment']['polarity']).to eq('negative')
64
- expect(subject['sentiment']['probability']).to be_a(Float)
65
- expect(subject['sentiment']['probability']).to be < 0.1
65
+ expect(subject).to include('message')
66
+ expect(subject.get('sentiment')['polarity']).to eq('negative')
67
+ expect(subject.get('sentiment')['probability']).to be_a(Float)
68
+ expect(subject.get('sentiment')['probability']).to be < 0.1
66
69
  end
67
70
 
68
71
  sample 'What a #fantastic idea' do
69
- expect(subject).to include("message")
70
- expect(subject['sentiment']['polarity']).to eq('positive')
71
- expect(subject['sentiment']['probability']).to be_a(Float)
72
- expect(subject['sentiment']['probability']).to be > 0.9
72
+ expect(subject).to include('message')
73
+ expect(subject.get('sentiment')['polarity']).to eq('positive')
74
+ expect(subject.get('sentiment')['probability']).to be_a(Float)
75
+ expect(subject.get('sentiment')['probability']).to be > 0.9
73
76
  end
74
77
  end
75
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-sentimentalizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Langlois
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ name: rspec
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
69
83
  description: A logstash plugin to derive sentiment from fields.
70
84
  email: tyler@elastic.co
71
85
  executables: []
@@ -80,6 +94,7 @@ files:
80
94
  - LICENSE
81
95
  - README.md
82
96
  - Rakefile
97
+ - demo.gif
83
98
  - lib/logstash/filters/sentimentalizer.rb
84
99
  - logstash-filter-sentimentalizer.gemspec
85
100
  - spec/filters/sentimentalizer_spec.rb