indico 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +21 -33
- data/Rakefile +1 -2
- data/indico.gemspec +15 -13
- data/lib/indico/helper.rb +32 -17
- data/lib/indico/settings.rb +93 -0
- data/lib/indico/version.rb +1 -1
- data/lib/indico.rb +52 -37
- data/spec/config/.indicorc.test +5 -0
- data/spec/config/.indicorc.test.2 +2 -0
- data/spec/indico_batch_spec.rb +51 -47
- data/spec/indico_spec.rb +50 -38
- data/spec/settings_spec.rb +95 -0
- data/spec/spec_helper.rb +1 -1
- metadata +27 -6
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# IndicoIo-ruby
|
2
2
|
|
3
|
-
A
|
3
|
+
A ruby wrapper for the [indico API](http://indico.io).
|
4
4
|
|
5
|
-
|
5
|
+
Installation
|
6
|
+
-------------
|
6
7
|
|
7
8
|
Add this line to your application's Gemfile:
|
8
9
|
|
@@ -10,17 +11,23 @@ Add this line to your application's Gemfile:
|
|
10
11
|
|
11
12
|
And then execute:
|
12
13
|
|
13
|
-
$ bundle
|
14
|
+
$ bundle install
|
14
15
|
|
15
16
|
Or install it yourself as:
|
16
17
|
|
17
18
|
$ gem install indico
|
18
19
|
|
19
|
-
|
20
|
+
|
21
|
+
API Keys + Setup
|
22
|
+
----------------
|
23
|
+
For API key registration and setup, checkout our [quickstart guide](http://docs.indico.io/v2.0/docs/api-keys).
|
24
|
+
|
25
|
+
Full Documentation
|
20
26
|
------------
|
21
|
-
|
27
|
+
Detailed documentation and further code examples are available at [indico.reame.io](http://indico.readme.io/v2.0/docs/ruby)
|
22
28
|
|
23
|
-
|
29
|
+
Examples
|
30
|
+
---------
|
24
31
|
|
25
32
|
```ruby
|
26
33
|
> require 'indico'
|
@@ -45,44 +52,25 @@ Found [here](http://indico.readme.io/v1.0/docs)
|
|
45
52
|
|
46
53
|
```
|
47
54
|
|
48
|
-
|
49
|
-
|
50
|
-
If you'd like to use our batch api interface, please check out the [pricing page](https://indico.io/pricing) on our website to find the right plan for you.
|
51
|
-
|
52
|
-
```ruby
|
53
|
-
> require 'indico'
|
54
|
-
|
55
|
-
=> true
|
55
|
+
Batch API
|
56
|
+
---------
|
56
57
|
|
57
|
-
|
58
|
+
Each `Indico` method has a corresponding batch method for analyzing many examples with a single request. Simply pass in an array of inputs and receive an array of results in return.
|
58
59
|
|
59
|
-
=> ["I believe in capital punishment", "The president is wrong"]
|
60
|
-
|
61
|
-
> Indico.batch_political(data, "username", "password")
|
62
|
-
|
63
|
-
=> [ {"Libertarian"=>0.3511057701654774, "Liberal"=>0.06709112089656208, "Green"=>0.03830472376983833, "Conservative"=>0.5434983851681222}, {"Libertarian"=>0.08762905907467175, "Liberal"=>0.18965142341591298, "Green"=>0.02612359787701222, "Conservative"=>0.696595919632403}]
|
64
|
-
````
|
65
|
-
|
66
|
-
###Private cloud API Access
|
67
|
-
|
68
|
-
If you're looking to use indico's API for high throughput applications, please check out the [pricing page](https://indico.io/pricing) on our website to find the right plan for you.
|
69
60
|
|
70
61
|
```ruby
|
71
62
|
> require 'indico'
|
72
63
|
|
73
64
|
=> true
|
74
65
|
|
75
|
-
>
|
66
|
+
> Indico.api_key = "YOUR_API_KEY"
|
76
67
|
|
77
|
-
=>
|
68
|
+
=> "YOUR_API_KEY"
|
78
69
|
|
79
|
-
> Indico.
|
80
|
-
|
81
|
-
=> [ {"Libertarian"=>0.3511057701654774, "Liberal"=>0.06709112089656208, "Green"=>0.03830472376983833, "Conservative"=>0.5434983851681222}, {"Libertarian"=>0.08762905907467175, "Liberal"=>0.18965142341591298, "Green"=>0.02612359787701222, "Conservative"=>0.696595919632403}]
|
82
|
-
````
|
83
|
-
|
84
|
-
The `cloud` parameter redirects API calls to your private cloud hosted at `[cloud].indico.domains`
|
70
|
+
> Indico.batch_sentiment(['Best day ever', 'Worst day ever'])
|
85
71
|
|
72
|
+
=> [0.9899001220871786, 0.005709885173415242]
|
73
|
+
```
|
86
74
|
|
87
75
|
## Contributing
|
88
76
|
|
data/Rakefile
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
data/indico.gemspec
CHANGED
@@ -4,21 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'indico/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'indico'
|
8
8
|
spec.version = Indico::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Slater Victoroff', 'Amit Ambardekar', 'Madison May', 'Annie Carlson']
|
10
|
+
spec.email = ['slater@indico.io', 'amitamb@gmail.com', 'madison@indico.io', 'annie@indico.io']
|
11
|
+
spec.summary = 'A simple Ruby Wrapper for the indico set of APIs.'
|
12
|
+
spec.description = 'A simple Ruby Wrapper for the indico set of APIs.'
|
13
|
+
spec.homepage = 'https://github.com/IndicoDataSolutions/IndicoIo-ruby'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(
|
18
|
-
spec.test_files = spec.files.grep(
|
19
|
-
spec.require_paths = [
|
17
|
+
spec.executables = spec.files.grep('^bin\\/') { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep('^(test|spec|features)\\/')
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'inifile', '~> 3.0.0'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rspec'
|
20
25
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "rspec"
|
24
26
|
end
|
data/lib/indico/helper.rb
CHANGED
@@ -1,30 +1,44 @@
|
|
1
|
-
require
|
1
|
+
require 'base64'
|
2
2
|
|
3
3
|
module Indico
|
4
4
|
private
|
5
5
|
|
6
6
|
def self.url_join(root, api)
|
7
|
-
if root
|
8
|
-
|
7
|
+
if !root
|
8
|
+
'http://apiv2.indico.io/' + api
|
9
9
|
else
|
10
|
-
|
10
|
+
Indico.cloud_protocol + root + '.indico.domains/' + api
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.api_handler(data,
|
14
|
+
def self.api_handler(data, api, config)
|
15
|
+
server = nil
|
16
|
+
api_key = nil
|
17
|
+
unless config.nil?
|
18
|
+
server = config[:cloud]
|
19
|
+
api_key = config[:api_key]
|
20
|
+
end
|
15
21
|
d = {}
|
16
22
|
d['data'] = data
|
17
23
|
data_dict = JSON.dump(d)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
24
|
+
|
25
|
+
if api_key.nil?
|
26
|
+
api_key = Indico.config['auth']
|
27
|
+
end
|
28
|
+
|
29
|
+
if server.nil?
|
30
|
+
server = Indico.config['cloud']
|
22
31
|
end
|
32
|
+
|
33
|
+
response = make_request(url_join(server, api), data_dict,
|
34
|
+
add_api_key_to_header(api_key))
|
35
|
+
|
36
|
+
|
23
37
|
results = JSON.parse(response.body)
|
24
|
-
if results.key?(
|
25
|
-
|
38
|
+
if results.key?('error')
|
39
|
+
fail results['error']
|
26
40
|
else
|
27
|
-
results
|
41
|
+
results['results']
|
28
42
|
end
|
29
43
|
end
|
30
44
|
|
@@ -43,11 +57,12 @@ module Indico
|
|
43
57
|
http.request(request)
|
44
58
|
end
|
45
59
|
|
46
|
-
def self.
|
47
|
-
|
48
|
-
|
49
|
-
|
60
|
+
def self.add_api_key_to_header(api_key)
|
61
|
+
if api_key.nil?
|
62
|
+
raise ArgumentError, 'api key is required'
|
63
|
+
end
|
64
|
+
headers = { 'Content-Type' => 'application/json', 'Accept' => 'text/plain' }
|
65
|
+
headers['X-ApiKey'] = api_key
|
50
66
|
headers
|
51
67
|
end
|
52
|
-
|
53
68
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'inifile'
|
2
|
+
|
3
|
+
module Indico
|
4
|
+
private
|
5
|
+
|
6
|
+
class << self; attr_accessor :config; end
|
7
|
+
class << self; attr_accessor :cloud_protocol; end
|
8
|
+
|
9
|
+
Indico.cloud_protocol = 'https://'
|
10
|
+
|
11
|
+
def self.valid_auth(config)
|
12
|
+
# Does a config hashmap have a valid auth definition?
|
13
|
+
return config['auth'] &&
|
14
|
+
config['auth']['api_key']
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.valid_cloud(config)
|
18
|
+
# Does a config hashmap have a valid private cloud definition?
|
19
|
+
return config['private_cloud'] &&
|
20
|
+
config['private_cloud']['cloud']
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.merge_config(prev_config, new_config)
|
24
|
+
# Merge two configurations, giving precedence to the second
|
25
|
+
if self.valid_auth(new_config)
|
26
|
+
prev_config['auth'] = new_config['auth']
|
27
|
+
end
|
28
|
+
|
29
|
+
if self.valid_cloud(new_config)
|
30
|
+
prev_config['private_cloud'] = new_config['private_cloud']
|
31
|
+
end
|
32
|
+
|
33
|
+
return prev_config
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.load_config_files(filenames)
|
37
|
+
# Given a list of filenames, build up an ini file config
|
38
|
+
master_ini = self.new_config()
|
39
|
+
|
40
|
+
for filename in filenames
|
41
|
+
ini = IniFile.load(filename)
|
42
|
+
if not ini then
|
43
|
+
next
|
44
|
+
end
|
45
|
+
master_ini = self.merge_config(master_ini, ini)
|
46
|
+
end
|
47
|
+
return master_ini
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.find_config_files()
|
51
|
+
# Provides a list of paths to search for indicorc files
|
52
|
+
localPath = File.join(Dir.pwd, ".indicorc")
|
53
|
+
globalPath = File.join(Dir.home, ".indicorc")
|
54
|
+
return [globalPath, localPath]
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.load_environment_vars()
|
58
|
+
# Load environment variables into same format as INI file reader
|
59
|
+
return {'auth' => {'api_key' => ENV["INDICO_API_KEY"]},
|
60
|
+
'private_cloud' => {'cloud' => ENV["INDICO_CLOUD"]}}
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.new_config()
|
64
|
+
# Makes a new, empty config object
|
65
|
+
new_config = Hash.new
|
66
|
+
new_config['auth'] = false
|
67
|
+
new_config['cloud'] = false
|
68
|
+
return new_config
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.simplify_config(config)
|
72
|
+
# Goes from nested representation to flatter version
|
73
|
+
new_config = self.new_config()
|
74
|
+
if self.valid_auth(config)
|
75
|
+
new_config['auth'] = config['auth']['api_key']
|
76
|
+
end
|
77
|
+
if self.valid_cloud(config)
|
78
|
+
new_config['cloud'] = config['private_cloud']['cloud']
|
79
|
+
end
|
80
|
+
return new_config
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.load_config()
|
84
|
+
# Finds, loads, and simplifies all configuration types
|
85
|
+
paths = self.find_config_files()
|
86
|
+
config_file = self.load_config_files(paths)
|
87
|
+
env_vars = self.load_environment_vars()
|
88
|
+
config = self.merge_config(config_file, env_vars)
|
89
|
+
return self.simplify_config(config)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
Indico.config = Indico.load_config()
|
data/lib/indico/version.rb
CHANGED
data/lib/indico.rb
CHANGED
@@ -1,75 +1,90 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require 'indico/version'
|
2
|
+
require 'indico/helper'
|
3
|
+
require 'indico/settings'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
require 'net/https'
|
6
7
|
|
7
8
|
module Indico
|
9
|
+
HEADERS = { 'Content-Type' => 'application/json', 'Accept' => 'text/plain' }
|
8
10
|
|
9
|
-
|
11
|
+
def self.api_key
|
12
|
+
config['auth']
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.api_key=(api)
|
16
|
+
config['auth'] = api
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.private_cloud
|
20
|
+
config['cloud']
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.private_cloud=(cloud)
|
24
|
+
config['cloud'] = cloud
|
25
|
+
end
|
10
26
|
|
11
|
-
def self.political(test_text,
|
12
|
-
api_handler(test_text,
|
27
|
+
def self.political(test_text, config = nil)
|
28
|
+
api_handler(test_text, 'political', config)
|
13
29
|
end
|
14
30
|
|
15
|
-
def self.batch_political(test_text,
|
16
|
-
api_handler(test_text,
|
31
|
+
def self.batch_political(test_text, config = nil)
|
32
|
+
api_handler(test_text, 'political/batch', config)
|
17
33
|
end
|
18
34
|
|
19
|
-
def self.posneg(test_text,
|
20
|
-
api_handler(test_text,
|
35
|
+
def self.posneg(test_text, config = nil)
|
36
|
+
api_handler(test_text, 'sentiment', config)
|
21
37
|
end
|
22
38
|
|
23
|
-
def self.batch_posneg(test_text,
|
24
|
-
api_handler(test_text,
|
39
|
+
def self.batch_posneg(test_text, config = nil)
|
40
|
+
api_handler(test_text, 'sentiment/batch', config)
|
25
41
|
end
|
26
42
|
|
27
43
|
def self.sentiment(*args)
|
28
|
-
|
44
|
+
posneg(*args)
|
29
45
|
end
|
30
46
|
|
31
47
|
def self.batch_sentiment(*args)
|
32
|
-
|
48
|
+
batch_posneg(*args)
|
33
49
|
end
|
34
50
|
|
35
|
-
def self.language(test_text,
|
36
|
-
api_handler(test_text,
|
51
|
+
def self.language(test_text, config = nil)
|
52
|
+
api_handler(test_text, 'language', config)
|
37
53
|
end
|
38
54
|
|
39
|
-
def self.batch_language(test_text,
|
40
|
-
api_handler(test_text,
|
55
|
+
def self.batch_language(test_text, config = nil)
|
56
|
+
api_handler(test_text, 'language/batch', config)
|
41
57
|
end
|
42
58
|
|
43
|
-
def self.text_tags(test_text,
|
44
|
-
api_handler(test_text,
|
59
|
+
def self.text_tags(test_text, config = nil)
|
60
|
+
api_handler(test_text, 'texttags', config)
|
45
61
|
end
|
46
62
|
|
47
|
-
def self.batch_text_tags(test_text,
|
48
|
-
api_handler(test_text,
|
63
|
+
def self.batch_text_tags(test_text, config = nil)
|
64
|
+
api_handler(test_text, 'texttags/batch', config)
|
49
65
|
end
|
50
66
|
|
51
|
-
def self.fer(face,
|
52
|
-
api_handler(face,
|
67
|
+
def self.fer(face, config = nil)
|
68
|
+
api_handler(face, 'fer', config)
|
53
69
|
end
|
54
70
|
|
55
|
-
def self.batch_fer(test_text,
|
56
|
-
api_handler(test_text,
|
71
|
+
def self.batch_fer(test_text, config = nil)
|
72
|
+
api_handler(test_text, 'fer/batch', config)
|
57
73
|
end
|
58
74
|
|
59
|
-
def self.facial_features(face,
|
60
|
-
api_handler(face,
|
75
|
+
def self.facial_features(face, config = nil)
|
76
|
+
api_handler(face, 'facialfeatures', config)
|
61
77
|
end
|
62
78
|
|
63
|
-
def self.batch_facial_features(test_text,
|
64
|
-
api_handler(test_text,
|
79
|
+
def self.batch_facial_features(test_text, config = nil)
|
80
|
+
api_handler(test_text, 'facialfeatures/batch', config)
|
65
81
|
end
|
66
82
|
|
67
|
-
def self.image_features(face,
|
68
|
-
api_handler(face,
|
83
|
+
def self.image_features(face, config = nil)
|
84
|
+
api_handler(face, 'imagefeatures', config)
|
69
85
|
end
|
70
86
|
|
71
|
-
def self.batch_image_features(test_text,
|
72
|
-
api_handler(test_text,
|
87
|
+
def self.batch_image_features(test_text, config = nil)
|
88
|
+
api_handler(test_text, 'imagefeatures/batch', config)
|
73
89
|
end
|
74
|
-
|
75
90
|
end
|
data/spec/indico_batch_spec.rb
CHANGED
@@ -1,37 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'set'
|
3
3
|
|
4
|
-
$username = ENV['INDICO_USERNAME']
|
5
|
-
$password = ENV['INDICO_PASSWORD']
|
6
|
-
$private_cloud = 'indico-test'
|
7
|
-
|
8
4
|
describe Indico do
|
5
|
+
before do
|
6
|
+
api_key = ENV['INDICO_API_KEY']
|
7
|
+
private_cloud = 'indico-test'
|
8
|
+
@config_private_cloud = { api_key: api_key, cloud: private_cloud}
|
9
|
+
@config = { api_key: api_key}
|
10
|
+
end
|
9
11
|
|
10
|
-
it
|
11
|
-
expected_keys = Set.new(
|
12
|
-
data = [
|
13
|
-
response = Indico.batch_political(data,
|
12
|
+
it 'should tag text with correct political tags' do
|
13
|
+
expected_keys = Set.new(%w(Conservative Green Liberal Libertarian))
|
14
|
+
data = ['Guns don\'t kill people.', ' People kill people.']
|
15
|
+
response = Indico.batch_political(data, @config)
|
14
16
|
|
15
17
|
expect(Set.new(response[0].keys)).to eql(expected_keys)
|
16
18
|
expect(Set.new(response[1].keys)).to eql(expected_keys)
|
17
19
|
end
|
18
20
|
|
19
|
-
it
|
20
|
-
expected_keys = Set.new(
|
21
|
-
data = [
|
22
|
-
|
21
|
+
it 'should access a private cloud' do
|
22
|
+
expected_keys = Set.new(%w(Conservative Green Liberal Libertarian))
|
23
|
+
data = ['Guns don\'t kill people.', ' People kill people.']
|
24
|
+
|
25
|
+
# for mocking: use http instead of https to route requests to our public cloud
|
26
|
+
Indico.cloud_protocol = 'http://'
|
27
|
+
response = Indico.batch_political(data, @config_private_cloud)
|
28
|
+
Indico.cloud_protocol = 'https://'
|
23
29
|
|
24
30
|
expect(Set.new(response[0].keys)).to eql(expected_keys)
|
25
31
|
expect(Set.new(response[1].keys)).to eql(expected_keys)
|
26
32
|
end
|
27
33
|
|
28
|
-
it
|
29
|
-
response = Indico.batch_sentiment([
|
30
|
-
|
34
|
+
it 'should tag text with correct sentiment tags' do
|
35
|
+
response = Indico.batch_sentiment(['Worst movie ever.'], @config)
|
31
36
|
expect(response[0] < 0.5).to eql(true)
|
32
37
|
end
|
33
38
|
|
34
|
-
it
|
39
|
+
it 'should tag text with correct language tags' do
|
35
40
|
expected_keys = Set.new([
|
36
41
|
'English',
|
37
42
|
'Spanish',
|
@@ -70,64 +75,63 @@ describe Indico do
|
|
70
75
|
])
|
71
76
|
|
72
77
|
data = ['Quis custodiet ipsos custodes', 'Clearly english, foo!']
|
73
|
-
response = Indico.batch_language(data,
|
78
|
+
response = Indico.batch_language(data, @config)
|
74
79
|
|
75
80
|
expect(Set.new(response[0].keys)).to eql(expected_keys)
|
76
81
|
expect(Set.new(response[1].keys)).to eql(expected_keys)
|
77
82
|
end
|
78
83
|
|
79
|
-
it
|
80
|
-
expected_keys = Set.new(
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
data = [
|
93
|
-
response = Indico.batch_text_tags(data,
|
84
|
+
it 'should tag text with correct text tags' do
|
85
|
+
expected_keys = Set.new(%w(fashion art energy economics entrepreneur
|
86
|
+
books politics gardening nba conservative
|
87
|
+
technology startups relationships education
|
88
|
+
humor psychology bicycling investing travel
|
89
|
+
cooking christianity environment religion health
|
90
|
+
hockey pets music soccer guns gaming jobs
|
91
|
+
business nature food cars photography philosophy
|
92
|
+
geek sports baseball news television
|
93
|
+
entertainment parenting comics science nfl
|
94
|
+
programming personalfinance atheism movies anime
|
95
|
+
fitness military realestate history))
|
96
|
+
|
97
|
+
data = ['Guns don\'t kill people.', 'People kill people.']
|
98
|
+
response = Indico.batch_text_tags(data, @config)
|
94
99
|
|
95
100
|
expect Set.new(response[0].keys).subset?(Set.new(expected_keys))
|
96
101
|
expect Set.new(response[1].keys).subset?(Set.new(expected_keys))
|
97
102
|
end
|
98
103
|
|
99
|
-
it
|
100
|
-
expected_keys = Set.new(
|
101
|
-
test_face = Array.new(48){Array.new(48){rand(100)/100.0} }
|
102
|
-
response = Indico.batch_fer([test_face, test_face],
|
104
|
+
it 'should tag face with correct facial expression' do
|
105
|
+
expected_keys = Set.new(%w(Angry Sad Neutral Surprise Fear Happy))
|
106
|
+
test_face = Array.new(48) { Array.new(48) { rand(100) / 100.0 } }
|
107
|
+
response = Indico.batch_fer([test_face, test_face], @config)
|
103
108
|
|
104
109
|
expect(Set.new(response[0].keys)).to eql(expected_keys)
|
105
110
|
expect(Set.new(response[1].keys)).to eql(expected_keys)
|
106
111
|
end
|
107
112
|
|
108
|
-
it
|
109
|
-
test_face = Array.new(48){Array.new(48){rand(100)/100.0} }
|
110
|
-
response = Indico.batch_facial_features([test_face, test_face],
|
111
|
-
|
113
|
+
it 'should tag face with correct facial features' do
|
114
|
+
test_face = Array.new(48) { Array.new(48) { rand(100) / 100.0 } }
|
115
|
+
response = Indico.batch_facial_features([test_face, test_face], @config)
|
112
116
|
expect(response[0].length).to eql(48)
|
113
117
|
expect(response[1].length).to eql(48)
|
114
118
|
end
|
115
119
|
|
116
|
-
it
|
117
|
-
test_image = Array.new(48){Array.new(48){rand(100)/100.0} }
|
118
|
-
response = Indico.batch_image_features([test_image, test_image],
|
119
|
-
|
120
|
+
it 'should tag image with correct image features' do
|
121
|
+
test_image = Array.new(48) { Array.new(48) { rand(100) / 100.0 } }
|
122
|
+
response = Indico.batch_image_features([test_image, test_image], @config)
|
120
123
|
expect(response[0].length).to eql(2048)
|
121
124
|
expect(response[1].length).to eql(2048)
|
122
125
|
end
|
123
126
|
|
124
127
|
# Uncomment when frontend updated to accept image urls
|
125
128
|
# it "should accept image urls" do
|
126
|
-
# test_image =
|
127
|
-
#
|
129
|
+
# test_image = 'http://icons.iconarchive.com/icons/oxygen-icons.org/' +
|
130
|
+
# 'oxygen/48/Emotes-face-smile-icon.png'
|
131
|
+
# response = Indico.batch_image_features([test_image, test_image],
|
132
|
+
# @config)
|
128
133
|
|
129
134
|
# expect(response[0].length).to eql(2048)
|
130
135
|
# expect(response[1].length).to eql(2048)
|
131
136
|
# end
|
132
|
-
|
133
137
|
end
|
data/spec/indico_spec.rb
CHANGED
@@ -1,34 +1,38 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'set'
|
3
3
|
|
4
|
-
$username = ENV['INDICO_USERNAME']
|
5
|
-
$password = ENV['INDICO_PASSWORD']
|
6
|
-
$private_cloud = 'indico-test'
|
7
|
-
|
8
4
|
describe Indico do
|
5
|
+
before do
|
6
|
+
api_key = ENV['INDICO_API_KEY']
|
7
|
+
private_cloud = 'indico-test'
|
8
|
+
@config = { api_key: api_key, cloud: private_cloud}
|
9
|
+
end
|
9
10
|
|
10
|
-
it
|
11
|
-
expected_keys = Set.new(
|
12
|
-
response = Indico.political(
|
11
|
+
it 'should tag text with correct political tags' do
|
12
|
+
expected_keys = Set.new(%w(Conservative Green Liberal Libertarian))
|
13
|
+
response = Indico.political('Guns don\'t kill people. People kill people.')
|
13
14
|
|
14
15
|
expect(Set.new(response.keys)).to eql(expected_keys)
|
15
16
|
end
|
16
17
|
|
17
|
-
it
|
18
|
-
expected_keys = Set.new(
|
19
|
-
data =
|
20
|
-
|
21
|
-
|
18
|
+
it 'should tag text with correct political tags' do
|
19
|
+
expected_keys = Set.new(%w(Conservative Green Liberal Libertarian))
|
20
|
+
data = 'Guns don\'t kill people. People kill people.'
|
21
|
+
|
22
|
+
# for mocking: use http to redirect requests to our public cloud endpoint
|
23
|
+
Indico.cloud_protocol = 'http://'
|
24
|
+
response = Indico.political(data, @config)
|
25
|
+
Indico.cloud_protocol = 'https://'
|
22
26
|
expect(Set.new(response.keys)).to eql(expected_keys)
|
23
27
|
end
|
24
28
|
|
25
|
-
it
|
26
|
-
response = Indico.sentiment(
|
29
|
+
it 'should tag text with correct sentiment tags' do
|
30
|
+
response = Indico.sentiment('Worst movie ever.')
|
27
31
|
|
28
32
|
expect(response < 0.5).to eql(true)
|
29
33
|
end
|
30
34
|
|
31
|
-
it
|
35
|
+
it 'should tag text with correct language tags' do
|
32
36
|
expected_keys = Set.new([
|
33
37
|
'English',
|
34
38
|
'Spanish',
|
@@ -70,51 +74,59 @@ describe Indico do
|
|
70
74
|
expect(Set.new(response.keys)).to eql(expected_keys)
|
71
75
|
end
|
72
76
|
|
73
|
-
it
|
74
|
-
expected_keys = Set.new(
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
response = Indico.text_tags(
|
77
|
+
it 'should tag text with correct text tags' do
|
78
|
+
expected_keys = Set.new(%w(fashion art energy economics entrepreneur
|
79
|
+
books politics gardening nba conservative
|
80
|
+
technology startups relationships education
|
81
|
+
humor psychology bicycling investing travel
|
82
|
+
cooking christianity environment religion health
|
83
|
+
hockey pets music soccer guns gaming jobs
|
84
|
+
business nature food cars photography philosophy
|
85
|
+
geek sports baseball news television
|
86
|
+
entertainment parenting comics science nfl
|
87
|
+
programming personalfinance atheism movies anime
|
88
|
+
fitness military realestate history))
|
89
|
+
response = Indico.text_tags('Guns don\'t kill people. People kill people.')
|
86
90
|
|
87
91
|
expect Set.new(response.keys).subset?(Set.new(expected_keys))
|
88
92
|
end
|
89
93
|
|
90
|
-
it
|
91
|
-
expected_keys = Set.new(
|
92
|
-
test_face = Array.new(48){Array.new(48){rand(100)/100.0} }
|
94
|
+
it 'should tag face with correct facial expression' do
|
95
|
+
expected_keys = Set.new(%w(Angry Sad Neutral Surprise Fear Happy))
|
96
|
+
test_face = Array.new(48) { Array.new(48) { rand(100) / 100.0 } }
|
93
97
|
|
94
98
|
response = Indico.fer(test_face)
|
95
99
|
|
96
100
|
expect(Set.new(response.keys)).to eql(expected_keys)
|
97
101
|
end
|
98
102
|
|
99
|
-
it
|
100
|
-
test_face = Array.new(48){Array.new(48){rand(100)/100.0} }
|
103
|
+
it 'should tag face with correct facial features' do
|
104
|
+
test_face = Array.new(48) { Array.new(48) { rand(100) / 100.0 } }
|
101
105
|
response = Indico.facial_features(test_face)
|
102
106
|
|
103
107
|
expect(response.length).to eql(48)
|
104
108
|
end
|
105
109
|
|
106
|
-
it
|
107
|
-
test_image = Array.new(48){Array.new(48){rand(100)/100.0} }
|
110
|
+
it 'should tag image with correct image features' do
|
111
|
+
test_image = Array.new(48) { Array.new(48) { rand(100) / 100.0 } }
|
112
|
+
response = Indico.image_features(test_image)
|
113
|
+
|
114
|
+
expect(response.length).to eql(2048)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should tag rgb image with correct image features" do
|
118
|
+
test_image = Array.new(48){Array.new(48){Array.new(3){rand(100)/100.0}}}
|
108
119
|
response = Indico.image_features(test_image)
|
109
120
|
|
110
121
|
expect(response.length).to eql(2048)
|
111
122
|
end
|
112
123
|
|
113
124
|
# Uncomment when frontend updated to accept image urls
|
114
|
-
# it
|
115
|
-
# response = Indico.image_features(
|
125
|
+
# it 'should accept image urls' do
|
126
|
+
# response = Indico.image_features('http://icons.iconarchive.com/icons/' +
|
127
|
+
# 'oxygen-icons.org/oxygen/48/' +
|
128
|
+
# 'Emotes-face-smile-icon.png')
|
116
129
|
|
117
130
|
# expect(response.length).to eql(2048)
|
118
131
|
# end
|
119
|
-
|
120
132
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Indico do
|
4
|
+
it 'should correctly parse an ini file without raising an error' do
|
5
|
+
Indico.load_config_files(Indico.find_config_files())
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should find the correct config files' do
|
9
|
+
files = Indico.find_config_files()
|
10
|
+
expect(files[0]).to eql("#{Dir.home}/.indicorc")
|
11
|
+
expect(files[1]).to eql("#{Dir.pwd}/.indicorc")
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should read in config files properly' do
|
15
|
+
files = [
|
16
|
+
File.expand_path('../config/.indicorc.test', __FILE__),
|
17
|
+
File.expand_path('../config/.indicorc.test.2', __FILE__)
|
18
|
+
]
|
19
|
+
config = Indico.load_config_files(files)
|
20
|
+
expected_auth = Hash.new
|
21
|
+
expected_auth['api_key'] = 'testapikey'
|
22
|
+
expect(config['auth']).to eql(expected_auth)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should read in variables from the user\'s environment' do
|
26
|
+
api_key = 'testapikey'
|
27
|
+
cloud = 'cloud'
|
28
|
+
ENV['INDICO_API_KEY'] = api_key
|
29
|
+
ENV['INDICO_CLOUD'] = cloud
|
30
|
+
|
31
|
+
config = Indico.load_environment_vars()
|
32
|
+
expected_auth = Hash.new
|
33
|
+
expected_auth['api_key'] = 'testapikey'
|
34
|
+
|
35
|
+
expected_cloud = Hash.new
|
36
|
+
expected_cloud['cloud'] = cloud
|
37
|
+
|
38
|
+
expect(config['auth']).to eql(expected_auth)
|
39
|
+
expect(config['private_cloud']).to eql(expected_cloud)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should combine file and env variable configuration' do
|
43
|
+
api_key = 'testapikey'
|
44
|
+
cloud = 'cloud'
|
45
|
+
ENV['INDICO_API_KEY'] = api_key
|
46
|
+
ENV['INDICO_CLOUD'] = cloud
|
47
|
+
|
48
|
+
expected = Hash.new
|
49
|
+
expected['auth'] = api_key
|
50
|
+
expected['cloud'] = cloud
|
51
|
+
|
52
|
+
config = Indico.load_config()
|
53
|
+
expect(config).to eql(expected)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should merge configurations properly' do
|
57
|
+
|
58
|
+
file_api_key = 'file-api-key'
|
59
|
+
file_cloud = 'file-cloud'
|
60
|
+
file_config = Hash.new
|
61
|
+
file_config['auth'] = Hash.new
|
62
|
+
file_config['private_cloud'] = Hash.new
|
63
|
+
file_config['auth']['api_key'] = file_api_key
|
64
|
+
file_config['private_cloud']['cloud'] = file_cloud
|
65
|
+
|
66
|
+
env_api_key = 'env-api-key'
|
67
|
+
env_cloud = 'env-cloud'
|
68
|
+
ENV['INDICO_API_KEY'] = env_api_key
|
69
|
+
ENV['INDICO_CLOUD'] = env_cloud
|
70
|
+
|
71
|
+
env_config = Indico.load_environment_vars()
|
72
|
+
merged = Indico.merge_config(file_config, env_config)
|
73
|
+
expect(merged['auth']['api_key']).to eql(env_api_key)
|
74
|
+
expect(merged['private_cloud']['cloud']).to eql(env_cloud)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should set api key with a call to set_api_key' do
|
78
|
+
Indico.api_key = nil
|
79
|
+
begin
|
80
|
+
Indico.political('Guns don\'t kill people. People kill people.')
|
81
|
+
rescue ArgumentError => exception
|
82
|
+
expect(exception.message).to eql('api key is required')
|
83
|
+
else
|
84
|
+
fail('api_key was not null')
|
85
|
+
end
|
86
|
+
|
87
|
+
begin
|
88
|
+
Indico.political('Guns don\'t kill people. People kill people.')
|
89
|
+
rescue ArgumentError => exception
|
90
|
+
expect(exception.message).to eql('api key is required')
|
91
|
+
else
|
92
|
+
fail('api_key was not null')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,7 +2,7 @@ require 'indico'
|
|
2
2
|
|
3
3
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
4
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
-
# The generated `.rspec` file contains `--require spec_helper` which
|
5
|
+
# The generated `.rspec` file contains `--require spec_helper` which causes this
|
6
6
|
# file to always be loaded, without a need to explicitly require it in any files.
|
7
7
|
#
|
8
8
|
# Given that it is always loaded, you are encouraged to keep this file as
|
metadata
CHANGED
@@ -1,17 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: indico
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Slater Victoroff
|
9
9
|
- Amit Ambardekar
|
10
|
+
- Madison May
|
11
|
+
- Annie Carlson
|
10
12
|
autorequire:
|
11
13
|
bindir: bin
|
12
14
|
cert_chain: []
|
13
|
-
date: 2015-
|
15
|
+
date: 2015-04-08 00:00:00.000000000 Z
|
14
16
|
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: inifile
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.0.0
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
15
33
|
- !ruby/object:Gem::Dependency
|
16
34
|
name: bundler
|
17
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,6 +82,8 @@ description: A simple Ruby Wrapper for the indico set of APIs.
|
|
64
82
|
email:
|
65
83
|
- slater@indico.io
|
66
84
|
- amitamb@gmail.com
|
85
|
+
- madison@indico.io
|
86
|
+
- annie@indico.io
|
67
87
|
executables: []
|
68
88
|
extensions: []
|
69
89
|
extra_rdoc_files: []
|
@@ -77,9 +97,13 @@ files:
|
|
77
97
|
- indico.gemspec
|
78
98
|
- lib/indico.rb
|
79
99
|
- lib/indico/helper.rb
|
100
|
+
- lib/indico/settings.rb
|
80
101
|
- lib/indico/version.rb
|
102
|
+
- spec/config/.indicorc.test
|
103
|
+
- spec/config/.indicorc.test.2
|
81
104
|
- spec/indico_batch_spec.rb
|
82
105
|
- spec/indico_spec.rb
|
106
|
+
- spec/settings_spec.rb
|
83
107
|
- spec/spec_helper.rb
|
84
108
|
homepage: https://github.com/IndicoDataSolutions/IndicoIo-ruby
|
85
109
|
licenses:
|
@@ -106,7 +130,4 @@ rubygems_version: 1.8.23
|
|
106
130
|
signing_key:
|
107
131
|
specification_version: 3
|
108
132
|
summary: A simple Ruby Wrapper for the indico set of APIs.
|
109
|
-
test_files:
|
110
|
-
- spec/indico_batch_spec.rb
|
111
|
-
- spec/indico_spec.rb
|
112
|
-
- spec/spec_helper.rb
|
133
|
+
test_files: []
|