embulk-filter-google_natural_language_api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d4ad2a7fd3873b1b7e810bd19799f3cc4953648c
4
+ data.tar.gz: ff1f308f8ff6267cb232c8290ce0adfeaaaf8c4d
5
+ SHA512:
6
+ metadata.gz: 80ad5396e358eff5d6a18519fd1b410a97ee9651ef8fbc2c23ff4a829a64d1d10812c5a2672f5bd6435192acc2b13391facd3385c251f583d0dcc133a31e3efe
7
+ data.tar.gz: 840d7581b04d4208f9545070cbdb5be93c330c6ee0e788348ef1b648f2fa2cb93b8de394f0467a724d8ae8b83b1c03de92754d1275afa96e489e392682897c24
@@ -0,0 +1,6 @@
1
+ *~
2
+ /tmp/
3
+ /pkg/
4
+ /tmp/
5
+ /.bundle/
6
+ /Gemfile.lock
@@ -0,0 +1 @@
1
+ jruby-9.1.5.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec
@@ -0,0 +1,21 @@
1
+
2
+ MIT License
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Google Natural Language Api filter plugin for Embulk
2
+
3
+ Google Natural Language Api filter plugin for Embulk.
4
+
5
+ ## Overview
6
+
7
+ * **Plugin type**: filter
8
+
9
+ ## Configuration
10
+
11
+ - **api**: api type. analyzeSentiment or analyzeEntities or analyzeSyntax. (string, required)
12
+ - **out_key_name_suffix**: out_key_name_suffix (string, required)
13
+ - **key_names**: key_names (array, required)
14
+ - **delay**: delay (integer, default: 0)
15
+ - **google_api_key**: google_api_key (string, default: ENV['GOOGLE_API_KEY'])
16
+ - **language**: language. default is auto detect. (string, default: nil)
17
+
18
+
19
+ ## Example
20
+
21
+ ```yaml
22
+ filters:
23
+ - type: google_natural_language_api
24
+ api: analyzeSentiment
25
+ out_key_name_suffix: _parsed
26
+ language: en
27
+ key_names:
28
+ - title
29
+ - message
30
+ ```
31
+
32
+
33
+ ## Build
34
+
35
+ ```
36
+ $ rake
37
+ ```
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :build
@@ -0,0 +1,6 @@
1
+ *~
2
+ /tmp/
3
+ /pkg/
4
+ /tmp/
5
+ /.bundle/
6
+ /Gemfile.lock
@@ -0,0 +1 @@
1
+ jruby-9.1.5.0
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec
@@ -0,0 +1,21 @@
1
+
2
+ MIT License
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Google Natural Language Api filter plugin for Embulk
2
+
3
+ Google Natural Language Api filter plugin for Embulk.
4
+
5
+ ## Overview
6
+
7
+ * **Plugin type**: filter
8
+
9
+ ## Configuration
10
+
11
+ - **api**: api type. analyzeSentiment or analyzeEntities or analyzeSyntax. (string, required)
12
+ - **out_key_name_suffix**: out_key_name_suffix (string, required)
13
+ - **key_names**: key_names (array, required)
14
+ - **delay**: delay (integer, default: 0)
15
+ - **google_api_key**: google_api_key (string, default: ENV['GOOGLE_API_KEY'])
16
+ - **language**: language. default is auto detect. (string, default: nil)
17
+
18
+
19
+ ## Example
20
+
21
+ ```yaml
22
+ filters:
23
+ - type: google_natural_language_api
24
+ api: analyzeSentiment
25
+ out_key_name_suffix: _parsed
26
+ language: en
27
+ key_names:
28
+ - title
29
+ - message
30
+ ```
31
+
32
+
33
+ ## Build
34
+
35
+ ```
36
+ $ rake
37
+ ```
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :build
@@ -0,0 +1,20 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "embulk-filter-google_natural_language_api"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["toyama0919"]
6
+ spec.summary = "Google Natural Language Api filter plugin for Embulk"
7
+ spec.description = "Google Natural Language Api filter plugin for Embulk"
8
+ spec.email = ["toyama0919@gmail.com"]
9
+ spec.licenses = ["MIT"]
10
+ spec.homepage = "https://github.com/toyama0919/embulk-filter-google_natural_language_api"
11
+
12
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
13
+ spec.test_files = spec.files.grep(%r{^(test|spec)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_dependency 'jruby-openssl'
17
+ spec.add_development_dependency 'embulk', ['>= 0.8.15']
18
+ spec.add_development_dependency 'bundler', ['>= 1.10.6']
19
+ spec.add_development_dependency 'rake', ['>= 10.0']
20
+ end
@@ -0,0 +1,74 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+ require "openssl"
5
+
6
+ module Embulk
7
+ module Filter
8
+
9
+ class GoogleNaturalLanguageApi < FilterPlugin
10
+ Plugin.register_filter("google_natural_language_api", self)
11
+ ENDPOINT_PREFIX = "https://language.googleapis.com/v1/documents"
12
+
13
+ def self.transaction(config, in_schema, &control)
14
+ task = {
15
+ "api" => config.param("api", :string),
16
+ "out_key_name_suffix" => config.param("out_key_name_suffix", :string),
17
+ "key_names" => config.param("key_names", :array),
18
+ "delay" => config.param("delay", :integer, default: 0),
19
+ "google_api_key" => config.param("google_api_key", :string, default: ENV['GOOGLE_API_KEY']),
20
+ "language" => config.param("language", :string, default: nil),
21
+ }
22
+
23
+ add_columns = task["key_names"].map { |key_name|
24
+ Column.new(nil, key_name + task["out_key_name_suffix"], :json)
25
+ }
26
+
27
+ out_columns = in_schema + add_columns
28
+
29
+ yield(task, out_columns)
30
+ end
31
+
32
+ def init
33
+ @uri = URI.parse("#{ENDPOINT_PREFIX}:#{task['api']}?key=#{task['google_api_key']}")
34
+ @http = Net::HTTP.new(@uri.host, @uri.port)
35
+ @http.use_ssl = true
36
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
37
+ @request = Net::HTTP::Post.new(@uri.request_uri, initheader = {'Content-Type' =>'application/json'})
38
+ @key_names = task['key_names']
39
+ @out_key_name_suffix = task['out_key_name_suffix']
40
+ @delay = task['delay']
41
+ @body = {
42
+ "document" => {
43
+ "type" => "PLAIN_TEXT",
44
+ }
45
+ }
46
+ @body["document"]["language"] = task['language'] if task['language']
47
+ end
48
+
49
+ def close
50
+ end
51
+
52
+ def add(page)
53
+ page.each do |record|
54
+ hash = Hash[in_schema.names.zip(record)]
55
+ @key_names.each do |key_name|
56
+ @body["document"]["content"] = hash[key_name]
57
+ @request.body = @body.to_json
58
+
59
+ @http.start do |h|
60
+ response = h.request(@request)
61
+ hash[key_name + @out_key_name_suffix] = JSON.parse(response.body)
62
+ end
63
+ end
64
+ page_builder.add(hash.values)
65
+ sleep @delay
66
+ end
67
+ end
68
+
69
+ def finish
70
+ page_builder.finish
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,20 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "embulk-filter-google_natural_language_api"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["toyama0919"]
6
+ spec.summary = "Google Natural Language Api filter plugin for Embulk"
7
+ spec.description = "Google Natural Language Api filter plugin for Embulk"
8
+ spec.email = ["toyama0919@gmail.com"]
9
+ spec.licenses = ["MIT"]
10
+ spec.homepage = "https://github.com/toyama0919/embulk-filter-google_natural_language_api"
11
+
12
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
13
+ spec.test_files = spec.files.grep(%r{^(test|spec)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_dependency 'jruby-openssl'
17
+ spec.add_development_dependency 'embulk', ['>= 0.8.15']
18
+ spec.add_development_dependency 'bundler', ['>= 1.10.6']
19
+ spec.add_development_dependency 'rake', ['>= 10.0']
20
+ end
@@ -0,0 +1,74 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+ require "openssl"
5
+
6
+ module Embulk
7
+ module Filter
8
+
9
+ class GoogleNaturalLanguageApi < FilterPlugin
10
+ Plugin.register_filter("google_natural_language_api", self)
11
+ ENDPOINT_PREFIX = "https://language.googleapis.com/v1/documents"
12
+
13
+ def self.transaction(config, in_schema, &control)
14
+ task = {
15
+ "api" => config.param("api", :string),
16
+ "out_key_name_suffix" => config.param("out_key_name_suffix", :string),
17
+ "key_names" => config.param("key_names", :array),
18
+ "delay" => config.param("delay", :integer, default: 0),
19
+ "google_api_key" => config.param("google_api_key", :string, default: ENV['GOOGLE_API_KEY']),
20
+ "language" => config.param("language", :string, default: nil),
21
+ }
22
+
23
+ add_columns = task["key_names"].map { |key_name|
24
+ Column.new(nil, key_name + task["out_key_name_suffix"], :json)
25
+ }
26
+
27
+ out_columns = in_schema + add_columns
28
+
29
+ yield(task, out_columns)
30
+ end
31
+
32
+ def init
33
+ @uri = URI.parse("#{ENDPOINT_PREFIX}:#{task['api']}?key=#{task['google_api_key']}")
34
+ @http = Net::HTTP.new(@uri.host, @uri.port)
35
+ @http.use_ssl = true
36
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
37
+ @request = Net::HTTP::Post.new(@uri.request_uri, initheader = {'Content-Type' =>'application/json'})
38
+ @key_names = task['key_names']
39
+ @out_key_name_suffix = task['out_key_name_suffix']
40
+ @delay = task['delay']
41
+ @body = {
42
+ "document" => {
43
+ "type" => "PLAIN_TEXT",
44
+ }
45
+ }
46
+ @body["document"]["language"] = task['language'] if task['language']
47
+ end
48
+
49
+ def close
50
+ end
51
+
52
+ def add(page)
53
+ page.each do |record|
54
+ hash = Hash[in_schema.names.zip(record)]
55
+ @key_names.each do |key_name|
56
+ @body["document"]["content"] = hash[key_name]
57
+ @request.body = @body.to_json
58
+
59
+ @http.start do |h|
60
+ response = h.request(@request)
61
+ hash[key_name + @out_key_name_suffix] = JSON.parse(response.body)
62
+ end
63
+ end
64
+ page_builder.add(hash.values)
65
+ sleep @delay
66
+ end
67
+ end
68
+
69
+ def finish
70
+ page_builder.finish
71
+ end
72
+ end
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-filter-google_natural_language_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - toyama0919
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-12 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: '0'
19
+ name: jruby-openssl
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.8.15
33
+ name: embulk
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.15
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.10.6
47
+ name: bundler
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.10.6
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ name: rake
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Google Natural Language Api filter plugin for Embulk
70
+ email:
71
+ - toyama0919@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".ruby-version"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/.gitignore
83
+ - bin/.ruby-version
84
+ - bin/Gemfile
85
+ - bin/LICENSE.txt
86
+ - bin/README.md
87
+ - bin/Rakefile
88
+ - bin/embulk-filter-google_natural_language_api.gemspec
89
+ - bin/lib/embulk/filter/google_natural_language_api.rb
90
+ - embulk-filter-google_natural_language_api.gemspec
91
+ - lib/embulk/filter/google_natural_language_api.rb
92
+ homepage: https://github.com/toyama0919/embulk-filter-google_natural_language_api
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.6.6
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Google Natural Language Api filter plugin for Embulk
116
+ test_files: []