baidu-aip 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +48 -0
- data/Rakefile +6 -0
- data/baidu-aip.gemspec +29 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/baidu/aip.rb +11 -0
- data/lib/baidu/aip/base.rb +112 -0
- data/lib/baidu/aip/client.rb +536 -0
- data/lib/baidu/aip/configure.rb +24 -0
- data/lib/baidu/aip/constants.rb +89 -0
- data/lib/baidu/aip/face/detect.rb +11 -0
- data/lib/baidu/aip/face/group_copy_user.rb +11 -0
- data/lib/baidu/aip/face/group_delete_user.rb +11 -0
- data/lib/baidu/aip/face/group_get_list.rb +11 -0
- data/lib/baidu/aip/face/group_get_users.rb +11 -0
- data/lib/baidu/aip/face/identify.rb +11 -0
- data/lib/baidu/aip/face/match.rb +11 -0
- data/lib/baidu/aip/face/multi_identify.rb +11 -0
- data/lib/baidu/aip/face/user_add.rb +11 -0
- data/lib/baidu/aip/face/user_delete.rb +11 -0
- data/lib/baidu/aip/face/user_get.rb +11 -0
- data/lib/baidu/aip/face/user_update.rb +11 -0
- data/lib/baidu/aip/face/verify.rb +11 -0
- data/lib/baidu/aip/image_audit/anti_porn.rb +11 -0
- data/lib/baidu/aip/image_audit/anti_porn_gif.rb +11 -0
- data/lib/baidu/aip/image_audit/anti_terror.rb +11 -0
- data/lib/baidu/aip/image_audit/combination.rb +11 -0
- data/lib/baidu/aip/image_audit/face.rb +11 -0
- data/lib/baidu/aip/image_audit/user_defined.rb +11 -0
- data/lib/baidu/aip/image_recognition/animal.rb +11 -0
- data/lib/baidu/aip/image_recognition/car.rb +11 -0
- data/lib/baidu/aip/image_recognition/dish.rb +11 -0
- data/lib/baidu/aip/image_recognition/logo.rb +11 -0
- data/lib/baidu/aip/image_recognition/logo_add.rb +11 -0
- data/lib/baidu/aip/image_recognition/logo_delete.rb +11 -0
- data/lib/baidu/aip/image_recognition/object.rb +11 -0
- data/lib/baidu/aip/image_recognition/plant.rb +11 -0
- data/lib/baidu/aip/image_search/product.rb +11 -0
- data/lib/baidu/aip/image_search/product_add.rb +11 -0
- data/lib/baidu/aip/image_search/product_delete.rb +11 -0
- data/lib/baidu/aip/image_search/same.rb +11 -0
- data/lib/baidu/aip/image_search/same_add.rb +11 -0
- data/lib/baidu/aip/image_search/same_delete.rb +11 -0
- data/lib/baidu/aip/image_search/similar.rb +11 -0
- data/lib/baidu/aip/image_search/similar_add.rb +11 -0
- data/lib/baidu/aip/image_search/similar_delete.rb +11 -0
- data/lib/baidu/aip/knowledge_graph/task_create.rb +11 -0
- data/lib/baidu/aip/knowledge_graph/task_info.rb +11 -0
- data/lib/baidu/aip/knowledge_graph/task_query.rb +11 -0
- data/lib/baidu/aip/knowledge_graph/task_start.rb +11 -0
- data/lib/baidu/aip/knowledge_graph/task_status.rb +11 -0
- data/lib/baidu/aip/knowledge_graph/task_update.rb +11 -0
- data/lib/baidu/aip/nlp/comment_tag.rb +11 -0
- data/lib/baidu/aip/nlp/dep_parser.rb +11 -0
- data/lib/baidu/aip/nlp/dnnlm_cn.rb +11 -0
- data/lib/baidu/aip/nlp/keyword.rb +11 -0
- data/lib/baidu/aip/nlp/lexer.rb +11 -0
- data/lib/baidu/aip/nlp/lexer_custom.rb +11 -0
- data/lib/baidu/aip/nlp/sentiment_classify.rb +11 -0
- data/lib/baidu/aip/nlp/simnet.rb +11 -0
- data/lib/baidu/aip/nlp/word_embedding.rb +11 -0
- data/lib/baidu/aip/nlp/word_sim_embedding.rb +11 -0
- data/lib/baidu/aip/ocr/accurate.rb +11 -0
- data/lib/baidu/aip/ocr/accurate_basic.rb +11 -0
- data/lib/baidu/aip/ocr/bankcard.rb +11 -0
- data/lib/baidu/aip/ocr/business_license.rb +11 -0
- data/lib/baidu/aip/ocr/custom.rb +11 -0
- data/lib/baidu/aip/ocr/driving_license.rb +11 -0
- data/lib/baidu/aip/ocr/form_recognize.rb +11 -0
- data/lib/baidu/aip/ocr/form_result_get.rb +11 -0
- data/lib/baidu/aip/ocr/general.rb +11 -0
- data/lib/baidu/aip/ocr/general_basic.rb +11 -0
- data/lib/baidu/aip/ocr/general_enhanced.rb +11 -0
- data/lib/baidu/aip/ocr/idcard.rb +11 -0
- data/lib/baidu/aip/ocr/license_plate.rb +11 -0
- data/lib/baidu/aip/ocr/receipt.rb +11 -0
- data/lib/baidu/aip/ocr/vehicle_license.rb +11 -0
- data/lib/baidu/aip/ocr/web_image.rb +11 -0
- data/lib/baidu/aip/post_base.rb +15 -0
- data/lib/baidu/aip/tokenable.rb +26 -0
- data/lib/baidu/aip/version.rb +5 -0
- metadata +193 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aecaa6e31f338d03bc7981481954cbc345aa5a0e
|
4
|
+
data.tar.gz: 511656a9ee52dc90da2b9787d1e5c490198c4e30
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aff7d45fd52c1f47c837e3619b84e142d6251a5a688bc8b0675bf016e02e6597cd4cccf1e0ddf8ea1ee1c46dfccd284f4d79e5aaa2e3fb17890c55e777b29a5d
|
7
|
+
data.tar.gz: 235f4baf9e817632fc1ba467788e71f207ad8f10717e4910ff57dca490e22632423d38bee1accd5c20f549cfaea71e45832503bf0df3fa14b06d3abed5acae7c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at tsuijy@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jeremy Cui
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Baidu::Aip - unofficial
|
2
|
+
|
3
|
+
This gem is used for calling baidu aip.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'baidu-aip'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install baidu-aip
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
Add file baidu-aip.rb to your initializers folder.
|
23
|
+
```ruby
|
24
|
+
Baidu::Aip.configure do |config|
|
25
|
+
config.api_key = 'your baidu app api key'
|
26
|
+
config.secret_key = 'your baidu app secret key'
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
e.g.
|
31
|
+
Baidu dish detect:
|
32
|
+
```ruby
|
33
|
+
base64 = Base64.encode64(File.open("your image path", "rb").read)
|
34
|
+
|
35
|
+
result = Baidu::Aip.image_recognition_dish base64
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
I will not consume all the apis, there are some issue maybe.
|
41
|
+
Welcome pr.
|
42
|
+
|
43
|
+
Hope help.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
48
|
+
|
data/Rakefile
ADDED
data/baidu-aip.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'baidu/aip/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'baidu-aip'
|
8
|
+
spec.version = Baidu::Aip::VERSION
|
9
|
+
spec.authors = ['Jeremy Cui']
|
10
|
+
spec.email = ['tsuijy@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Baidu aip ruby sdk(unofficial)}
|
13
|
+
spec.description = %q{Baidu aip ruby sdk(unofficial)}
|
14
|
+
spec.homepage = 'https://github.com/jerecui/baidu-aip'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'rest-client', '>=2.0', '<6.0'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "baidu/aip"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/baidu/aip.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'json'
|
3
|
+
require 'rest-client'
|
4
|
+
require 'baidu/aip/constants'
|
5
|
+
|
6
|
+
module Baidu
|
7
|
+
module Aip
|
8
|
+
class Base
|
9
|
+
include Constants
|
10
|
+
|
11
|
+
attr_accessor :client
|
12
|
+
|
13
|
+
TOKEN_URL = 'https://aip.baidubce.com/oauth/2.0/token'
|
14
|
+
|
15
|
+
def service_url
|
16
|
+
name = underscore(self.class.name.sub('Baidu::Aip::', '').sub('::', '')).upcase
|
17
|
+
self.class.const_get(name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_params
|
21
|
+
custom_params.merge intrinsic_params
|
22
|
+
end
|
23
|
+
|
24
|
+
def post_params
|
25
|
+
{}
|
26
|
+
end
|
27
|
+
|
28
|
+
def headers
|
29
|
+
{accept: :json}
|
30
|
+
end
|
31
|
+
|
32
|
+
def process
|
33
|
+
begin
|
34
|
+
response = RestClient.post "#{service_url}?#{build_url(get_params)}", post_params, headers
|
35
|
+
JSON(response.body)
|
36
|
+
rescue RestClient::ExceptionWithResponse => e
|
37
|
+
log e.response
|
38
|
+
JSON(e.response.body)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_token
|
43
|
+
if client.access_token && from_now(hour(1)) < client.expire_time
|
44
|
+
client.access_token
|
45
|
+
else
|
46
|
+
token_hash = {
|
47
|
+
:grant_type => 'client_credentials',
|
48
|
+
:client_id => client.api_key,
|
49
|
+
:client_secret => client.secret_key
|
50
|
+
}
|
51
|
+
|
52
|
+
begin
|
53
|
+
token_response = RestClient.post "#{TOKEN_URL}?#{build_url(token_hash)}", {}, {}
|
54
|
+
json = JSON(token_response.body)
|
55
|
+
client.access_token = json['access_token']
|
56
|
+
client.expire_time = Time.now + json['expires_in']
|
57
|
+
client.access_token
|
58
|
+
rescue RestClient::ExceptionWithResponse => e
|
59
|
+
log e.response
|
60
|
+
return nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
def build_url(hash)
|
67
|
+
hash.map{|k,v|"#{encode(k.to_s)}=#{encode(v.to_s)}"}.join('&')
|
68
|
+
end
|
69
|
+
|
70
|
+
def encode(str)
|
71
|
+
ERB::Util.url_encode str
|
72
|
+
end
|
73
|
+
|
74
|
+
def custom_params
|
75
|
+
{}
|
76
|
+
end
|
77
|
+
|
78
|
+
def intrinsic_params
|
79
|
+
{
|
80
|
+
:access_token => get_token,
|
81
|
+
:aipSdk => 'ruby',
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
def hour(num)
|
86
|
+
3600 * num
|
87
|
+
end
|
88
|
+
|
89
|
+
def from_now(seconds)
|
90
|
+
Time.now + seconds
|
91
|
+
end
|
92
|
+
|
93
|
+
def ago(seconds)
|
94
|
+
Time.now - seconds
|
95
|
+
end
|
96
|
+
|
97
|
+
def log(text)
|
98
|
+
puts text
|
99
|
+
Rails.logger.info(text) if defined? Rails
|
100
|
+
end
|
101
|
+
|
102
|
+
def underscore(str)
|
103
|
+
str.gsub(/::/, '/').
|
104
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
105
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
106
|
+
tr("-", "_").
|
107
|
+
downcase
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,536 @@
|
|
1
|
+
require 'baidu/aip/tokenable'
|
2
|
+
|
3
|
+
require 'baidu/aip/face/detect'
|
4
|
+
require 'baidu/aip/face/group_copy_user'
|
5
|
+
require 'baidu/aip/face/group_delete_user'
|
6
|
+
require 'baidu/aip/face/group_get_list'
|
7
|
+
require 'baidu/aip/face/group_get_users'
|
8
|
+
require 'baidu/aip/face/identify'
|
9
|
+
require 'baidu/aip/face/match'
|
10
|
+
require 'baidu/aip/face/multi_identify'
|
11
|
+
require 'baidu/aip/face/user_add'
|
12
|
+
require 'baidu/aip/face/user_delete'
|
13
|
+
require 'baidu/aip/face/user_get'
|
14
|
+
require 'baidu/aip/face/user_update'
|
15
|
+
require 'baidu/aip/face/verify'
|
16
|
+
|
17
|
+
require 'baidu/aip/image_recognition/animal'
|
18
|
+
require 'baidu/aip/image_recognition/car'
|
19
|
+
require 'baidu/aip/image_recognition/dish'
|
20
|
+
require 'baidu/aip/image_recognition/logo'
|
21
|
+
require 'baidu/aip/image_recognition/logo_add'
|
22
|
+
require 'baidu/aip/image_recognition/logo_delete'
|
23
|
+
require 'baidu/aip/image_recognition/object'
|
24
|
+
require 'baidu/aip/image_recognition/plant'
|
25
|
+
|
26
|
+
require 'baidu/aip/image_audit/anti_porn'
|
27
|
+
require 'baidu/aip/image_audit/anti_porn_gif'
|
28
|
+
require 'baidu/aip/image_audit/anti_terror'
|
29
|
+
require 'baidu/aip/image_audit/combination'
|
30
|
+
require 'baidu/aip/image_audit/face'
|
31
|
+
require 'baidu/aip/image_audit/user_defined'
|
32
|
+
|
33
|
+
require 'baidu/aip/image_search/product_add'
|
34
|
+
require 'baidu/aip/image_search/product_delete'
|
35
|
+
require 'baidu/aip/image_search/product'
|
36
|
+
require 'baidu/aip/image_search/same_add'
|
37
|
+
require 'baidu/aip/image_search/same_delete'
|
38
|
+
require 'baidu/aip/image_search/same'
|
39
|
+
require 'baidu/aip/image_search/similar_add'
|
40
|
+
require 'baidu/aip/image_search/similar_delete'
|
41
|
+
require 'baidu/aip/image_search/similar'
|
42
|
+
|
43
|
+
require 'baidu/aip/knowledge_graph/task_create'
|
44
|
+
require 'baidu/aip/knowledge_graph/task_info'
|
45
|
+
require 'baidu/aip/knowledge_graph/task_query'
|
46
|
+
require 'baidu/aip/knowledge_graph/task_status'
|
47
|
+
require 'baidu/aip/knowledge_graph/task_start'
|
48
|
+
require 'baidu/aip/knowledge_graph/task_update'
|
49
|
+
|
50
|
+
require 'baidu/aip/nlp/comment_tag'
|
51
|
+
require 'baidu/aip/nlp/dep_parser'
|
52
|
+
require 'baidu/aip/nlp/dnnlm_cn'
|
53
|
+
require 'baidu/aip/nlp/keyword'
|
54
|
+
require 'baidu/aip/nlp/lexer_custom'
|
55
|
+
require 'baidu/aip/nlp/lexer'
|
56
|
+
require 'baidu/aip/nlp/sentiment_classify'
|
57
|
+
require 'baidu/aip/nlp/simnet'
|
58
|
+
require 'baidu/aip/nlp/word_embedding'
|
59
|
+
require 'baidu/aip/nlp/word_sim_embedding'
|
60
|
+
|
61
|
+
require 'baidu/aip/ocr/accurate_basic'
|
62
|
+
require 'baidu/aip/ocr/accurate'
|
63
|
+
require 'baidu/aip/ocr/bankcard'
|
64
|
+
require 'baidu/aip/ocr/business_license'
|
65
|
+
require 'baidu/aip/ocr/custom'
|
66
|
+
require 'baidu/aip/ocr/driving_license'
|
67
|
+
require 'baidu/aip/ocr/form_recognize'
|
68
|
+
require 'baidu/aip/ocr/form_result_get'
|
69
|
+
require 'baidu/aip/ocr/general_basic'
|
70
|
+
require 'baidu/aip/ocr/general_enhanced'
|
71
|
+
require 'baidu/aip/ocr/general'
|
72
|
+
require 'baidu/aip/ocr/idcard'
|
73
|
+
require 'baidu/aip/ocr/license_plate'
|
74
|
+
require 'baidu/aip/ocr/receipt'
|
75
|
+
require 'baidu/aip/ocr/vehicle_license'
|
76
|
+
require 'baidu/aip/ocr/web_image'
|
77
|
+
|
78
|
+
module Baidu::Aip
|
79
|
+
module Client
|
80
|
+
include Tokenable
|
81
|
+
|
82
|
+
attr_accessor :api_key, :secret_key
|
83
|
+
|
84
|
+
# Face
|
85
|
+
def face_detect(image_in_base64, options = {})
|
86
|
+
aip = Face::Detect.new options.merge({image: image_in_base64})
|
87
|
+
aip.client = self
|
88
|
+
aip.process
|
89
|
+
end
|
90
|
+
|
91
|
+
def face_group_copy_user(group_id, uid, source_group_id)
|
92
|
+
aip = Face::GroupCopyUser.new({group_id: group_id, uid: uid, src_group_id: source_group_id})
|
93
|
+
aip.client = self
|
94
|
+
aip.process
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def face_group_delete_user(group_id, uid)
|
99
|
+
aip = Face::GroupDeleteUser.new({group_id: group_id, uid: uid})
|
100
|
+
aip.client = self
|
101
|
+
aip.process
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
def face_group_get_list(options = {})
|
106
|
+
aip = Face::GroupGetList.new options
|
107
|
+
aip.client = self
|
108
|
+
aip.process
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
def face_group_get_users(group_id, options = {})
|
113
|
+
aip = Face::GroupGetUsers.new options.merge({group_id: group_id})
|
114
|
+
aip.client = self
|
115
|
+
aip.process
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
def face_identify(image_in_base64, group_id, options = {})
|
120
|
+
aip = Face::Identify.new options.merge({image: image_in_base64, group_id: group_id})
|
121
|
+
aip.client = self
|
122
|
+
aip.process
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
def face_match(images_in_base64 = [], options = {})
|
127
|
+
aip = Face::Match.new options.merge({image: images_in_base64.join(',')})
|
128
|
+
aip.client = self
|
129
|
+
aip.process
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
def face_multi_identify(image_in_base64, group_id, options = {})
|
134
|
+
aip = Face::MultiIdentify.new options.merge({image: image_in_base64, group_id: group_id})
|
135
|
+
aip.client = self
|
136
|
+
aip.process
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
def face_user_add(uid, group_id, image_in_base64, user_info, options = {})
|
141
|
+
aip = Face::UserAdd.new options.merge({uid: uid, group_id: group_id, image: image_in_base64, user_info: user_info})
|
142
|
+
aip.client = self
|
143
|
+
aip.process
|
144
|
+
end
|
145
|
+
|
146
|
+
def face_user_delete(uid, options = {})
|
147
|
+
aip = Face::UserDelete.new options.merge({uid: uid})
|
148
|
+
aip.client = self
|
149
|
+
aip.process
|
150
|
+
end
|
151
|
+
|
152
|
+
def face_user_get(uid, options = {})
|
153
|
+
aip = Face::UserGet.new options.merge({uid: uid})
|
154
|
+
aip.client = self
|
155
|
+
aip.process
|
156
|
+
end
|
157
|
+
|
158
|
+
def face_user_update(uid, image_in_base64, user_info, group_id, options = {})
|
159
|
+
aip = Face::UserUpdate.new options.merge({uid: uid, image: image_in_base64, user_info: user_info, group_id: group_id})
|
160
|
+
aip.client = self
|
161
|
+
aip.process
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
def face_verify(image_in_base64, id_card_number, name, options = {})
|
166
|
+
aip = Face::Verify.new options.merge({image: image_in_base64, id_card_number: id_card_number, name: name})
|
167
|
+
aip.client = self
|
168
|
+
aip.process
|
169
|
+
end
|
170
|
+
|
171
|
+
|
172
|
+
# Image_recognition
|
173
|
+
|
174
|
+
def image_recognition_animal(image_in_base64, options = {})
|
175
|
+
aip = ImageRecognition::Animal.new options.merge({image: image_in_base64})
|
176
|
+
aip.client = self
|
177
|
+
|
178
|
+
aip.process
|
179
|
+
end
|
180
|
+
|
181
|
+
def image_recognition_car(image_in_base64, options = {})
|
182
|
+
aip = ImageRecognition::Car.new options.merge({image: image_in_base64})
|
183
|
+
aip.client = self
|
184
|
+
|
185
|
+
aip.process
|
186
|
+
end
|
187
|
+
|
188
|
+
def image_recognition_dish(image_in_base64, options = {})
|
189
|
+
aip = ImageRecognition::Dish.new options.merge({image: image_in_base64})
|
190
|
+
aip.client = self
|
191
|
+
|
192
|
+
aip.process
|
193
|
+
end
|
194
|
+
|
195
|
+
def image_recognition_logo(image_in_base64, options = {})
|
196
|
+
aip = ImageRecognition::Logo.new options.merge({image: image_in_base64})
|
197
|
+
aip.client = self
|
198
|
+
|
199
|
+
aip.process
|
200
|
+
end
|
201
|
+
|
202
|
+
def image_recognition_logo_add(image_in_base64, brief)
|
203
|
+
aip = ImageRecognition::LogoAdd.new options.merge({image: image_in_base64, brief: brief})
|
204
|
+
aip.client = self
|
205
|
+
|
206
|
+
aip.process
|
207
|
+
end
|
208
|
+
|
209
|
+
def image_recognition_logo_delete(image_in_base64, cont_sign)
|
210
|
+
aip = ImageRecognition::LogoDelete.new options.merge({image: image_in_base64, cont_sign: cont_sign})
|
211
|
+
aip.client = self
|
212
|
+
|
213
|
+
aip.process
|
214
|
+
end
|
215
|
+
|
216
|
+
def image_recognition_object(image_in_base64, options = {})
|
217
|
+
aip = ImageRecognition::Object.new options.merge({image: image_in_base64})
|
218
|
+
aip.client = self
|
219
|
+
|
220
|
+
aip.process
|
221
|
+
end
|
222
|
+
|
223
|
+
def image_recognition_plant(image_in_base64)
|
224
|
+
aip = ImageRecognition::Plant.new({image: image_in_base64})
|
225
|
+
aip.client = self
|
226
|
+
|
227
|
+
aip.process
|
228
|
+
end
|
229
|
+
|
230
|
+
# Image audit
|
231
|
+
def image_audit_anti_porn(image_in_base64)
|
232
|
+
aip = ImageAudit::AntiPorn.new({image: image_in_base64})
|
233
|
+
aip.client = self
|
234
|
+
aip.process
|
235
|
+
end
|
236
|
+
|
237
|
+
def image_audit_anti_porn_gif(image_in_base64)
|
238
|
+
aip = ImageAudit::AntiPornGif.new({image: image_in_base64})
|
239
|
+
aip.client = self
|
240
|
+
aip.process
|
241
|
+
end
|
242
|
+
|
243
|
+
def image_audit_anti_terrer(image_in_base64)
|
244
|
+
aip = ImageAudit::AntiTerror.new({image: image_in_base64})
|
245
|
+
aip.client = self
|
246
|
+
aip.process
|
247
|
+
end
|
248
|
+
|
249
|
+
def image_audit_combination(scenes, image_in_base64, options={})
|
250
|
+
aip = ImageAudit::Combination.new options.merge({scenes: scenes, image: image_in_base64})
|
251
|
+
aip.client = self
|
252
|
+
aip.process
|
253
|
+
end
|
254
|
+
|
255
|
+
def image_audit_combination_with_url(scenes, image_url, options={})
|
256
|
+
aip = ImageAudit::Combination.new options.merge({scenes: scenes, imageUrl: image_url})
|
257
|
+
aip.client = self
|
258
|
+
aip.process
|
259
|
+
end
|
260
|
+
|
261
|
+
def image_audit_face(images_in_base64 = [])
|
262
|
+
aip = ImageAudit::Face.new({images: images_in_base64.join(',')})
|
263
|
+
aip.client = self
|
264
|
+
aip.process
|
265
|
+
end
|
266
|
+
|
267
|
+
def image_audit_face_url(image_urls = [])
|
268
|
+
aip = ImageAudit::Face.new({imgUrls: image_urls.join(',')})
|
269
|
+
aip.client = self
|
270
|
+
aip.process
|
271
|
+
end
|
272
|
+
|
273
|
+
def image_audit_user_defined(image_in_base64)
|
274
|
+
aip = ImageAudit::UserDefined.new({image: images_in_base64})
|
275
|
+
aip.client = self
|
276
|
+
aip.process
|
277
|
+
end
|
278
|
+
|
279
|
+
def image_audit_face_url(image_url)
|
280
|
+
aip = ImageAudit::UserDefined.new({imgUrl: image_url})
|
281
|
+
aip.client = self
|
282
|
+
aip.process
|
283
|
+
end
|
284
|
+
|
285
|
+
# Image Search
|
286
|
+
def image_search_product_add(image_in_base64, options = {})
|
287
|
+
aip = ImageSearch::ProductAdd.new options.merge({image: image_in_base64})
|
288
|
+
aip.client = self
|
289
|
+
aip.process
|
290
|
+
end
|
291
|
+
|
292
|
+
def image_search_product(image_in_base64, options = {})
|
293
|
+
aip = ImageSearch::Product.new options.merge({image: image_in_base64})
|
294
|
+
aip.client = self
|
295
|
+
aip.process
|
296
|
+
end
|
297
|
+
|
298
|
+
def image_search_product_delete(image_in_base64)
|
299
|
+
aip = ImageSearch::ProductDelete.new({image: image_in_base64})
|
300
|
+
aip.client = self
|
301
|
+
aip.process
|
302
|
+
end
|
303
|
+
|
304
|
+
def image_search_same_add(image_in_base64, brief)
|
305
|
+
aip = ImageSearch::SameAdd.new({image: image_in_base64, brief: brief})
|
306
|
+
aip.client = self
|
307
|
+
aip.process
|
308
|
+
end
|
309
|
+
|
310
|
+
def image_search_same(image_in_base64)
|
311
|
+
aip = ImageSearch::Same.new({image: image_in_base64})
|
312
|
+
aip.client = self
|
313
|
+
aip.process
|
314
|
+
end
|
315
|
+
|
316
|
+
def image_search_same_delete(image_in_base64)
|
317
|
+
aip = ImageSearch::SameDelete.new({image: image_in_base64})
|
318
|
+
aip.client = self
|
319
|
+
aip.process
|
320
|
+
end
|
321
|
+
|
322
|
+
def image_search_similar_add(image_in_base64, brief)
|
323
|
+
aip = ImageSearch::SimilarAdd.new({image: image_in_base64, brief: brief})
|
324
|
+
aip.client = self
|
325
|
+
aip.process
|
326
|
+
end
|
327
|
+
|
328
|
+
def image_search_similar(image_in_base64)
|
329
|
+
aip = ImageSearch::Similar.new({image: image_in_base64})
|
330
|
+
aip.client = self
|
331
|
+
aip.process
|
332
|
+
end
|
333
|
+
|
334
|
+
def image_search_similar_delete(image_in_base64)
|
335
|
+
aip = ImageSearch::SimilarDelete.new({image: image_in_base64})
|
336
|
+
aip.client = self
|
337
|
+
aip.process
|
338
|
+
end
|
339
|
+
|
340
|
+
# knowledge_graph
|
341
|
+
def knowledge_graph_task_create(name, template_content, input_mapping_file, output_file, ulr_pattern, options = {})
|
342
|
+
aip = KnowledgeGraph::TaskCreate.new options.merge({name: name, template_content: template_content, input_mapping_file: input_mapping_file, output_file: output_file})
|
343
|
+
aip.client = self
|
344
|
+
aip.process
|
345
|
+
end
|
346
|
+
|
347
|
+
def knowledge_graph_task_info(id, options = {})
|
348
|
+
aip = KnowledgeGraph::TaskInfo.new options.merge({id: id})
|
349
|
+
aip.client = self
|
350
|
+
aip.process
|
351
|
+
end
|
352
|
+
|
353
|
+
def knowledge_graph_task_query(options = {})
|
354
|
+
aip = KnowledgeGraph::TaskQuery.new(options)
|
355
|
+
aip.client = self
|
356
|
+
aip.process
|
357
|
+
end
|
358
|
+
|
359
|
+
def knowledge_graph_task_status(id, options = {})
|
360
|
+
aip = KnowledgeGraph::TaskStatus.new options.merge({id: id})
|
361
|
+
aip.client = self
|
362
|
+
aip.process
|
363
|
+
end
|
364
|
+
|
365
|
+
def knowledge_graph_task_start(id, options = {})
|
366
|
+
aip = KnowledgeGraph::TaskStart.new options.merge({id: id})
|
367
|
+
aip.client = self
|
368
|
+
aip.process
|
369
|
+
end
|
370
|
+
|
371
|
+
def knowledge_graph_task_update(id, options = {})
|
372
|
+
aip = KnowledgeGraph::TaskUpdate.new options.merge({id: id})
|
373
|
+
aip.client = self
|
374
|
+
aip.process
|
375
|
+
end
|
376
|
+
|
377
|
+
# nlp
|
378
|
+
def nlp_comment_tag(text, options = {})
|
379
|
+
aip = Nlp::CommentTag.new options.merge({text: text})
|
380
|
+
aip.client = self
|
381
|
+
aip.process
|
382
|
+
end
|
383
|
+
|
384
|
+
def nlp_dep_parser(text, options = {})
|
385
|
+
aip = Nlp::DepParser.new options.merge({text: text})
|
386
|
+
aip.client = self
|
387
|
+
aip.process
|
388
|
+
end
|
389
|
+
|
390
|
+
def nlp_dnnlm_cn(text, options = {})
|
391
|
+
aip = Nlp::DnnlmCn.new options.merge({text: text})
|
392
|
+
aip.client = self
|
393
|
+
aip.process
|
394
|
+
end
|
395
|
+
|
396
|
+
def nlp_keyword(title, content, options = {})
|
397
|
+
aip = Nlp::Keyword.new options.merge({title: title, content: content})
|
398
|
+
aip.client = self
|
399
|
+
aip.process
|
400
|
+
end
|
401
|
+
|
402
|
+
def nlp_lexer_custom(text, options = {})
|
403
|
+
aip = Nlp::LexerCustom.new options.merge({text: text})
|
404
|
+
aip.client = self
|
405
|
+
aip.process
|
406
|
+
end
|
407
|
+
|
408
|
+
def nlp_lexer(text, options = {})
|
409
|
+
aip = Nlp::Lexer.new options.merge({text: text})
|
410
|
+
aip.client = self
|
411
|
+
aip.process
|
412
|
+
end
|
413
|
+
|
414
|
+
def nlp_sentiment_classify(text, options={})
|
415
|
+
aip = Nlp::SentimentClassify.new options.merge({text: text})
|
416
|
+
aip.client = self
|
417
|
+
aip.process
|
418
|
+
end
|
419
|
+
|
420
|
+
def nlp_simnet(text1, text2, options = {})
|
421
|
+
aip = Nlp::Simnet.new options.merge({text_1:text1, text_2: text2})
|
422
|
+
aip.client = self
|
423
|
+
aip.process
|
424
|
+
end
|
425
|
+
|
426
|
+
def nlp_word_embedding(word, options = {})
|
427
|
+
aip = Nlp::WordEmbedding.new options.merge({word: word})
|
428
|
+
aip.client = self
|
429
|
+
aip.process
|
430
|
+
end
|
431
|
+
|
432
|
+
def nlp_word_sim_embedding(word1, word2, options = {})
|
433
|
+
aip = Nlp::WordSimEmbedding.new options.merge({word_1: word1, word_2: word2})
|
434
|
+
aip.client = self
|
435
|
+
aip.process
|
436
|
+
end
|
437
|
+
|
438
|
+
# Ocr
|
439
|
+
def ocr_accurate_basic(image_in_base64, options = {})
|
440
|
+
aip = Ocr::AccurateBasic.new options.merge({image: image_in_base64})
|
441
|
+
aip.client = self
|
442
|
+
aip.process
|
443
|
+
end
|
444
|
+
|
445
|
+
def ocr_accurate(image_in_base64, options = {})
|
446
|
+
aip = Ocr::Accurate.new options.merge({image: image_in_base64})
|
447
|
+
aip.client = self
|
448
|
+
aip.process
|
449
|
+
end
|
450
|
+
|
451
|
+
def ocr_bankcard(image_in_base64, options = {})
|
452
|
+
aip = Ocr::Bankcard.new options.merge({image: image_in_base64})
|
453
|
+
aip.client = self
|
454
|
+
aip.process
|
455
|
+
end
|
456
|
+
|
457
|
+
def ocr_business_license(image_in_base64, options = {})
|
458
|
+
aip = Ocr::BusinessLicense.new options.merge({image: image_in_base64})
|
459
|
+
aip.client = self
|
460
|
+
aip.process
|
461
|
+
end
|
462
|
+
|
463
|
+
def ocr_custom(image_in_base64, template_sign, options = {})
|
464
|
+
aip = Ocr::Custom.new options.merge({image: image_in_base64, templateSign: template_sign})
|
465
|
+
aip.client = self
|
466
|
+
aip.process
|
467
|
+
end
|
468
|
+
|
469
|
+
def ocr_driving_license(image_in_base64, options = {})
|
470
|
+
aip = Ocr::DrivingLicense.new options.merge({image: image_in_base64})
|
471
|
+
aip.client = self
|
472
|
+
aip.process
|
473
|
+
end
|
474
|
+
|
475
|
+
# todo
|
476
|
+
# def ocr_form_recognize(image_in_base64, options = {})
|
477
|
+
# aip = Ocr::FormRecognize.new options.merge({image: image_in_base64})
|
478
|
+
# aip.client = self
|
479
|
+
# aip.process
|
480
|
+
# end
|
481
|
+
|
482
|
+
def ocr_form_result_get(request_id, options = {})
|
483
|
+
aip = Ocr::FormResultGet.new options.merge({request_id: request_id})
|
484
|
+
aip.client = self
|
485
|
+
aip.process
|
486
|
+
end
|
487
|
+
|
488
|
+
def ocr_general_basic(image_in_base64, options = {})
|
489
|
+
aip = Ocr::GeneralBasic.new options.merge({image: image_in_base64})
|
490
|
+
aip.client = self
|
491
|
+
aip.process
|
492
|
+
end
|
493
|
+
|
494
|
+
def ocr_genral_enhanced(image_in_base64, options = {})
|
495
|
+
aip = Ocr::GeneralEnhanced.new options.merge({image: image_in_base64})
|
496
|
+
aip.client = self
|
497
|
+
aip.process
|
498
|
+
end
|
499
|
+
|
500
|
+
def ocr_general(image_in_base64, options = {})
|
501
|
+
aip = Ocr::General.new options.merge({image: image_in_base64})
|
502
|
+
aip.client = self
|
503
|
+
aip.process
|
504
|
+
end
|
505
|
+
|
506
|
+
def ocr_idcard(image_in_base64, idcard_side, options = {})
|
507
|
+
aip = Ocr::Idcard.new options.merge({image: image_in_base64, id_card_side: idcard_side})
|
508
|
+
aip.client = self
|
509
|
+
aip.process
|
510
|
+
end
|
511
|
+
|
512
|
+
def ocr_license_plate(image_in_base64, options = {})
|
513
|
+
aip = Ocr::LicensePlate.new options.merge({image: image_in_base64})
|
514
|
+
aip.client = self
|
515
|
+
aip.process
|
516
|
+
end
|
517
|
+
|
518
|
+
def ocr_receipt(image_in_base64, options = {})
|
519
|
+
aip = Ocr::Receipt.new options.merge({image: image_in_base64})
|
520
|
+
aip.client = self
|
521
|
+
aip.process
|
522
|
+
end
|
523
|
+
|
524
|
+
def ocr_vehicle_license(image_in_base64, options = {})
|
525
|
+
aip = Ocr::VehicleLicense.new options.merge({image: image_in_base64})
|
526
|
+
aip.client = self
|
527
|
+
aip.process
|
528
|
+
end
|
529
|
+
|
530
|
+
def ocr_web_image(image_in_base64, options = {})
|
531
|
+
aip = Ocr::WebImage.new options.merge({image: image_in_base64})
|
532
|
+
aip.client = self
|
533
|
+
aip.process
|
534
|
+
end
|
535
|
+
end
|
536
|
+
end
|