embulk-filter-amazon_rekognition 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be495b0edfb083fe1529919d862ebf95317c6e70
4
+ data.tar.gz: 7f02b004fa5cc4a4bce2bde54c6b21e0e60d43b5
5
+ SHA512:
6
+ metadata.gz: cd786c0d0959240d6e08ea8a91c318069139b99f095bcea32e6329c590942555efc9f7d61035fa0e6a46b5eeb89e0a16065de6bc20b376a5385571e895f39d5a
7
+ data.tar.gz: ae9f96da47ac79b3adf751a1202bf34fa4147e9d092bc34703deb208e162837c93898423e24090ba5bb30b8ae166fffe9800148654362719d2214e2e18ed18c8
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ /.bundle/
5
+ /Gemfile.lock
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ jruby-9.1.5.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Amazon Rekognition filter plugin for Embulk
2
+
3
+ * [Amazon Rekognition \| AWS](https://aws.amazon.com/jp/rekognition/)
4
+ * [Amazon Rekognition – Image Detection and Recognition Powered by Deep Learning \| AWS Blog](https://aws.amazon.com/jp/blogs/aws/amazon-rekognition-image-detection-and-recognition-powered-by-deep-learning/)
5
+ * [Class: Aws::Rekognition::Client — AWS SDK for Ruby V2](https://docs.aws.amazon.com/sdkforruby/api/Aws/Rekognition/Client.html)
6
+
7
+ ## Overview
8
+
9
+ * **Plugin type**: filter
10
+
11
+ ## Configuration
12
+
13
+ - **api_type**: api_type. detect_faces or detect_labels.(string)
14
+ - **out_key_name**: out_key_name(string)
15
+ - **image_path_key_name**: image_path_key_name(string)
16
+ - **delay**: delay(integer, default: 0)
17
+ - **aws_access_key_id**: aws_access_key_id(string, default: nil)
18
+ - **aws_region**: aws_region(string, default: 'us-east-1')
19
+
20
+ ## Example
21
+
22
+ ```yaml
23
+ filters:
24
+ - type: amazon_rekognition
25
+ api_type: detect_labels
26
+ out_key_name: amazon_rekognition_info
27
+ image_path_key_name: image_path
28
+ ```
29
+
30
+
31
+ ## Build
32
+
33
+ ```
34
+ $ rake
35
+ ```
data/Rakefile ADDED
@@ -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-amazon_rekognition"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["toyama0919"]
6
+ spec.summary = "Amazon Rekognition filter plugin for Embulk"
7
+ spec.description = "Amazon Rekognition"
8
+ spec.email = ["toyama0919@gmail.com"]
9
+ spec.licenses = ["MIT"]
10
+ spec.homepage = "https://github.com/toyama0919/embulk-filter-amazon_rekognition"
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 'aws-sdk-rekognition', ['1.0.0.rc3']
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,92 @@
1
+ require 'aws-sdk-rekognition'
2
+
3
+ module Embulk
4
+ module Filter
5
+ class AmazonRekognition < FilterPlugin
6
+ Plugin.register_filter("amazon_rekognition", self)
7
+ ENABLE_API = ['detect_faces', 'detect_labels']
8
+
9
+ def self.transaction(config, in_schema, &control)
10
+ task = {
11
+ "api_type" => config.param("api_type", :string),
12
+ "out_key_name" => config.param("out_key_name", :string),
13
+ "image_path_key_name" => config.param("image_path_key_name", :string),
14
+ "delay" => config.param("delay", :integer, default: 0),
15
+ "aws_access_key_id" => config.param("aws_access_key_id", :string, default: nil),
16
+ "aws_secret_access_key" => config.param("aws_secret_access_key", :string, default: nil),
17
+ "aws_region" => config.param("aws_region", :string, default: 'us-east-1'),
18
+ }
19
+
20
+ unless ENABLE_API.include?(task['api_type'])
21
+ raise ConfigError.new "Not support api => [#{task['api_type']}]"
22
+ end
23
+
24
+ Embulk.logger.info "api => [#{task['api_type']}]"
25
+
26
+ add_columns = [
27
+ Column.new(nil, task["out_key_name"], :json)
28
+ ]
29
+
30
+ out_columns = in_schema + add_columns
31
+
32
+ yield(task, out_columns)
33
+ end
34
+
35
+ def init
36
+ @image_path_key_name = task['image_path_key_name']
37
+ @delay = task['delay']
38
+ @api_type = task['api_type'].to_sym
39
+ @client = Aws::Rekognition::Client.new(
40
+ access_key_id: task['aws_access_key_id'],
41
+ secret_access_key: task['aws_secret_access_key'],
42
+ region: task['aws_region']
43
+ )
44
+ end
45
+
46
+ def close
47
+ end
48
+
49
+ def add(page)
50
+ page.each do |record|
51
+ hash = Hash[in_schema.names.zip(record)]
52
+ image_path = hash[@image_path_key_name]
53
+ Embulk.logger.info "Amazon Rekognition #{@api_type} processing.. #{image_path}"
54
+ page_builder.add(hash.values + [get_response(image_path)])
55
+ sleep @delay
56
+ end
57
+ end
58
+
59
+ def finish
60
+ page_builder.finish
61
+ end
62
+
63
+ def get_response(image_path)
64
+ image_params = get_image_params(image_path)
65
+ resp = @client.send(
66
+ @api_type,
67
+ { image: image_params }
68
+ )
69
+ resp.to_h
70
+ rescue => e
71
+ Embulk.logger.warn "#{image_path}\n#{e.message}\n#{e.backtrace.join("\n")}"
72
+ return { error_message: e.message }
73
+ end
74
+
75
+ def get_image_params(image_path)
76
+ if image_path =~ /s3\:\/\//
77
+ s3_uri = URI.parse(image_path)
78
+ return {
79
+ s3_object: {
80
+ bucket: s3_uri.host,
81
+ name: s3_uri.path,
82
+ }
83
+ }
84
+ elsif image_path =~ /https?\:\/\//
85
+ return { bytes: Net::HTTP.get_response(URI.parse(image_path)).body }
86
+ else
87
+ return { bytes: File.read(image_path) }
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-filter-amazon_rekognition
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-02-01 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: 1.0.0.rc3
19
+ name: aws-sdk-rekognition
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0.rc3
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: Amazon Rekognition
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
+ - embulk-filter-amazon_rekognition.gemspec
83
+ - lib/embulk/filter/amazon_rekognition.rb
84
+ homepage: https://github.com/toyama0919/embulk-filter-amazon_rekognition
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.6.6
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Amazon Rekognition filter plugin for Embulk
108
+ test_files: []