logstash-filter-sentimentalizer 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d01ae62913663f01498106240233691ba9554a7b
4
+ data.tar.gz: cd400d8bd6e832f8161f0a8365575cca9acfb467
5
+ SHA512:
6
+ metadata.gz: 831e9ca15c91a307d0a13c220b7d102e96c6f46f606af045cbcd004553ee20b262006e0918e8280d9894ad6bd7c9913b69be05c18c62b296127fe095aa2361c0
7
+ data.tar.gz: 44f9e8b5842088167d85bf895aead64e660759bbbf6a58f8a1d3a2752e5cf11af0152243827a44a4b64605eec672ffe5a64e5cb098f44eae754d41968f4b7bd5
data/.gitignore ADDED
@@ -0,0 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
36
+
37
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - jruby
5
+
6
+ script: 'bundle exec rspec'
data/CONTRIBUTORS ADDED
@@ -0,0 +1,11 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * Aaron Mildenstein (untergeek)
6
+ * Pier-Hugues Pellerin (ph)
7
+
8
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
9
+ Logstash, and you aren't on the list above and want to be, please let us know
10
+ and we'll make sure you're here. Contributions from folks like you are what make
11
+ open source awesome.
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-filter-example
2
+ Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Logstash Plugin
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)
4
+
5
+ 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
+
7
+ ## Documentation
8
+
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/).
10
+
11
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com mailing list.
17
+
18
+ ## Developing
19
+
20
+ ### 1. Plugin Developement and Testing
21
+
22
+ #### Code
23
+ - To get started, you'll need JRuby with the Bundler gem installed.
24
+
25
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ - Update your dependencies
35
+
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ - Run tests
41
+
42
+ ```sh
43
+ bundle exec rspec
44
+ ```
45
+
46
+ ### 2. Running your unpublished Plugin in Logstash
47
+
48
+ #### 2.1 Run in a local Logstash clone
49
+
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
51
+ ```ruby
52
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
53
+ ```
54
+ - Install plugin
55
+ ```sh
56
+ bin/plugin install --no-verify
57
+ ```
58
+ - Run Logstash with your plugin
59
+ ```sh
60
+ bin/logstash -e 'filter {awesome {}}'
61
+ ```
62
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
63
+
64
+ #### 2.2 Run in an installed Logstash
65
+
66
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
67
+
68
+ - Build your plugin gem
69
+ ```sh
70
+ gem build logstash-filter-awesome.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
75
+ ```
76
+ - Start Logstash and proceed to test the plugin
77
+
78
+ ## Contributing
79
+
80
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
81
+
82
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
83
+
84
+ It is more important to the community that you are able to contribute.
85
+
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rake"
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ require 'logstash/filters/base'
4
+ require 'logstash/namespace'
5
+
6
+ # This plugin will analyze sentiment of a specified field and enrich the event
7
+ # with sentiment probability values.
8
+ class LogStash::Filters::Sentimentalizer < LogStash::Filters::Base
9
+ config_name 'sentimentalizer'
10
+
11
+ # Run sentiment analysis on this field
12
+ config :source, :validate => :string, :default => 'message'
13
+
14
+ # What key to place sentiment values under
15
+ config :target, :validate => :string, :default => 'sentiment'
16
+
17
+ # Should we scrub hashtags to better extract their sentiment?
18
+ config :scrub, :validate => :boolean, :default => true
19
+
20
+ public
21
+
22
+ def register
23
+ require 'sentimentalizer'
24
+
25
+ # Monkey patch the weird defaults for positive/negative string values
26
+ %w[POSITIVE NEGATIVE NEUTRAL].each do |s|
27
+ Sentiment.send(:remove_const, s)
28
+ Sentiment.const_set(s, s.downcase)
29
+ end
30
+
31
+ Sentimentalizer.setup
32
+ end # def register
33
+
34
+ def filter(event)
35
+ return unless filter?(event)
36
+
37
+ source = event.get(@source)
38
+ source.gsub!(/\B#(\S+)\b/, '\1') if @scrub
39
+
40
+ unless source.nil?
41
+ begin
42
+ sentiment = Sentimentalizer.analyze(source)
43
+ rescue NoMethodError => e
44
+ @logger.error(
45
+ 'Error parsing sentiment for field',
46
+ :exception => e,
47
+ :field => source
48
+ )
49
+ end
50
+
51
+ unless sentiment.nil?
52
+ event.set(
53
+ @target,
54
+ 'probability' => sentiment.overall_probability,
55
+ 'polarity' => sentiment.sentiment
56
+ )
57
+ end
58
+ end
59
+
60
+ # filter_matched should go in the last line of our successful code
61
+ filter_matched(event)
62
+ end # def filter
63
+ end # class LogStash::Filters::Sentimentalizer
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-sentimentalizer'
3
+ s.version = '0.2.0'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'This plugin will analyze sentiment of a specified field.'
6
+ s.description = 'A logstash plugin to derive sentiment from fields.'
7
+ s.authors = ['Tyler Langlois']
8
+ s.email = 'tyler@elastic.co'
9
+ s.homepage = 'https://github.com/tylerjl/logstash-filter-sentimentalizer'
10
+ s.require_paths = ['lib']
11
+
12
+ # Files
13
+ s.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
14
+
15
+ # Tests
16
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
+
18
+ # Special flag to let us know this is actually a logstash plugin
19
+ s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'filter' }
20
+
21
+ # Gem dependencies
22
+ s.add_runtime_dependency 'logstash-codec-plain', '~> 3.0'
23
+ s.add_runtime_dependency 'logstash-core-plugin-api', '~> 2.0'
24
+ s.add_runtime_dependency 'sentimentalizer', '~> 0.3.0'
25
+
26
+ s.add_development_dependency 'logstash-devutils', '~> 1.0'
27
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+ require "logstash/filters/sentimentalizer"
3
+
4
+ describe LogStash::Filters::Sentimentalizer do
5
+ describe 'default sentiment configuration' do
6
+ let(:config) do <<-CONFIG
7
+ filter {
8
+ sentimentalizer { }
9
+ }
10
+ CONFIG
11
+ end
12
+
13
+ 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
18
+ end
19
+
20
+ 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
25
+ end
26
+ end
27
+
28
+ describe 'twitter hashtag scoring without scrubbing' do
29
+ let(:config) do <<-CONFIG
30
+ filter {
31
+ sentimentalizer {
32
+ scrub => false
33
+ }
34
+ }
35
+ CONFIG
36
+ end
37
+
38
+ 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)
42
+ end
43
+
44
+ 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)
48
+ end
49
+ end
50
+
51
+ describe 'twitter hashtag scoring with scrubbing' do
52
+ let(:config) do <<-CONFIG
53
+ filter {
54
+ sentimentalizer {
55
+ scrub => true
56
+ }
57
+ }
58
+ CONFIG
59
+ end
60
+
61
+ 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
66
+ end
67
+
68
+ 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
73
+ end
74
+ end
75
+ end
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-sentimentalizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Langlois
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '3.0'
19
+ name: logstash-codec-plain
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ name: logstash-core-plugin-api
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.3.0
47
+ name: sentimentalizer
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
61
+ name: logstash-devutils
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ description: A logstash plugin to derive sentiment from fields.
70
+ email: tyler@elastic.co
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - ".travis.yml"
77
+ - CONTRIBUTORS
78
+ - DEVELOPER.md
79
+ - Gemfile
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - lib/logstash/filters/sentimentalizer.rb
84
+ - logstash-filter-sentimentalizer.gemspec
85
+ - spec/filters/sentimentalizer_spec.rb
86
+ - spec/spec_helper.rb
87
+ homepage: https://github.com/tylerjl/logstash-filter-sentimentalizer
88
+ licenses:
89
+ - Apache-2.0
90
+ metadata:
91
+ logstash_plugin: 'true'
92
+ logstash_group: filter
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.6.8
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: This plugin will analyze sentiment of a specified field.
113
+ test_files:
114
+ - spec/filters/sentimentalizer_spec.rb
115
+ - spec/spec_helper.rb