indico 0.5.0 → 0.5.1

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: e4e4ebe9a3cf53dba1c8ca028f77791ecd6afc50
4
+ data.tar.gz: a72dd4eca05693da019919d24d52c74aa173ff40
5
+ SHA512:
6
+ metadata.gz: 3888771271c807c9439ca1093408c02426067bef7518510772faad21d61c3014ccd1c1ec7d117e11b972dd05a8c37ae41f2312dd26046d8dbfd0b148156b1ce1
7
+ data.tar.gz: b5ea3d04258c46d7553337531f7abbbc2acafc9081e045e5025882c95fc81726cf7f1c365e427321951163797ae463b2245f52ca91848f5ad326ba27be82e812
data/lib/indico/helper.rb CHANGED
@@ -19,20 +19,22 @@ module Indico
19
19
  d['data'] = data
20
20
 
21
21
  if data.class == Array
22
+ if api != "apis/intersections"
22
23
  api += "/batch"
24
+ end
23
25
  end
24
26
 
25
27
  unless config.nil?
26
- server = config[:cloud]
27
- api_key = config[:api_key]
28
- apis = config[:apis]
28
+ server = config.delete('cloud')
29
+ api_key = config.delete('api_key')
30
+ apis = config.delete(:apis)
29
31
  d = d.merge(config)
30
32
  end
31
33
 
34
+
32
35
  server = server or Indico.config['cloud']
33
36
 
34
37
  url = url_join(server, api) + (apis ? "?apis=" + apis.join(",") : "")
35
-
36
38
  response = make_request(url, JSON.dump(d),
37
39
  add_api_key_to_header((api_key or Indico.config['auth'])))
38
40
 
data/lib/indico/multi.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative './errors'
2
+ require_relative './settings'
2
3
 
3
4
  module Indico
4
5
  CLIENT_TO_SERVER = {
@@ -8,41 +9,69 @@ module Indico
8
9
  "language" => "language",
9
10
  "text_tags" => "texttags",
10
11
  "fer" => "fer",
11
- "named_entities" => "named_entities",
12
+ "named_entities" => "namedentities",
12
13
  "keywords" => "keywords",
13
14
  "facial_features" => "facialfeatures",
15
+ "facial_localization" => "facial_localization",
14
16
  "image_features" => "imagefeatures",
15
17
  "content_filtering" => "contentfiltering",
16
18
  "twitter_engagement" => "twitterengagement"
17
19
  }
18
20
 
19
21
  SERVER_TO_CLIENT = CLIENT_TO_SERVER.invert
20
- def self.multi(data, type, apis, allowed, batch = false, config)
21
- converted_apis = Array.new
22
+
23
+ def self.validate_apis(apis, type="api", allowed=CLIENT_TO_SERVER.keys)
22
24
  apis.each { |api|
23
25
  if not allowed.include? api
24
26
  fail api + " is not a valid api for " + type + " requests. Please use: " + allowed.join(", ")
25
- else
26
- converted_apis.push(CLIENT_TO_SERVER[api])
27
27
  end
28
28
  }
29
+ end
30
+
31
+ def self.multi(data, type, apis, allowed, batch = false, config)
29
32
 
30
33
  if config.nil?
31
34
  config = {}
32
35
  end
33
36
 
34
- config[:apis] = converted_apis
37
+ self.validate_apis(apis, type, allowed)
38
+ config[:apis] = apis
35
39
  response = api_handler(data, batch ? "apis/batch" : "apis", config)
36
- results = handle_multi(response)
40
+ return handle_multi(response)
41
+ end
42
+
43
+ def self.intersections(data, apis = nil, config = nil)
44
+
45
+ if apis == nil
46
+ fail "Argument 'apis' must be provided"
47
+ end
48
+
49
+ api_types = apis.map { |api| API_TYPES[api] }
50
+
51
+ if !apis.is_a? Array or apis.length != 2
52
+ fail "Argument 'apis' must be of length 2"
53
+ elsif data.is_a? Array and data.length < 3
54
+ fail "At least 3 examples are required to use the intersections api"
55
+ elsif api_types[0] != api_types[1]
56
+ fail "Both 'apis' must accept the same kind of input to use the intersections api."
57
+ end
58
+
59
+ if config.nil?
60
+ config = {}
61
+ end
62
+
63
+ self.validate_apis(apis)
64
+ config[:apis] = apis
65
+ response = api_handler(data, "apis/intersections", config)
66
+ return response
37
67
 
38
- results
39
68
  end
40
69
 
41
70
  def self.handle_multi(results)
42
71
  converted_results = Hash.new
43
72
  results.each do |key, value|
44
73
  if value.is_a?(Hash) && value.has_key?("results")
45
- converted_results[SERVER_TO_CLIENT[key]] = value["results"]
74
+ converted_results[key] = value["results"]
46
75
  else
47
76
  raise IndicoError, 'unexpected result from ' + key + '. ' + value.fetch("error", "")
48
77
  end
@@ -6,8 +6,31 @@ HEADERS = { 'Content-Type' => 'application/json',
6
6
  'client-lib' => 'ruby',
7
7
  'version-number' => Indico::VERSION }
8
8
  # APIS
9
- TEXT_APIS = ["political", "sentiment", "sentiment_hq", "language", "text_tags"]
10
- IMAGE_APIS = ["fer", "facial_features", "image_features", "content_filtering"]
9
+ TEXT_APIS = [
10
+ "political",
11
+ "sentiment",
12
+ "sentiment_hq",
13
+ "language",
14
+ "text_tags",
15
+ "twitter_engagement",
16
+ "keywords",
17
+ "named_entities"
18
+ ]
19
+ IMAGE_APIS = [
20
+ "fer",
21
+ "facial_features",
22
+ "facial_localization",
23
+ "image_features",
24
+ "content_filtering"
25
+ ]
26
+
27
+ API_TYPES = {}
28
+ TEXT_APIS.each do |api|
29
+ API_TYPES[:api] = 'text'
30
+ end
31
+ IMAGE_APIS.each do |api|
32
+ API_TYPES[:api] = 'image'
33
+ end
11
34
 
12
35
  module Indico
13
36
  private
@@ -1,3 +1,3 @@
1
1
  module Indico
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
data/lib/indico.rb CHANGED
@@ -199,30 +199,30 @@ module Indico
199
199
  self.content_filtering(image, config)
200
200
  end
201
201
 
202
- def self.predict_image(face, apis = IMAGE_APIS, config = nil)
202
+ def self.analyze_image(face, apis = IMAGE_APIS, config = nil)
203
203
  api_hash = {apis:apis}
204
204
  multi(preprocess(face, 48, false), "image", apis, IMAGE_APIS, config ? config.update(api_hash) : api_hash)
205
205
  end
206
206
 
207
- def self.batch_predict_image(image, config = nil)
207
+ def self.batch_analyze_image(image, apis = IMAGE_APIS, config = nil)
208
208
  warn(
209
- "The `batch_predict_image` function will be deprecated in the next major upgrade. " +
210
- "Please call `predict_image` instead with the same arguments"
209
+ "The `batch_analyze_image` function will be deprecated in the next major upgrade. " +
210
+ "Please call `analyze_image` instead with the same arguments"
211
211
  )
212
- self.predict_image(image, config)
212
+ self.analyze_image(image, apis, config)
213
213
  end
214
214
 
215
- def self.predict_text(text, apis = TEXT_APIS, config = nil)
215
+ def self.analyze_text(text, apis = TEXT_APIS, config = nil)
216
216
  api_hash = {apis:apis}
217
217
  multi(text, "text", apis, TEXT_APIS, config ? config.update(api_hash) : api_hash)
218
218
  end
219
219
 
220
- def self.batch_predict_text(text, config = nil)
220
+ def self.batch_analyze_text(text, apis = TEXT_APIS, config = nil)
221
221
  warn(
222
- "The `batch_predict_text` function will be deprecated in the next major upgrade. " +
223
- "Please call `predict_text` instead with the same arguments"
222
+ "The `batch_analyze_text` function will be deprecated in the next major upgrade. " +
223
+ "Please call `analyze_text` instead with the same arguments"
224
224
  )
225
- self.predict_text(text, config)
225
+ self.analyze_text(text, apis, config)
226
226
  end
227
227
 
228
228
  end
@@ -189,7 +189,7 @@ describe Indico do
189
189
 
190
190
  it "should respond with all text apis called in batch" do
191
191
  expected_keys = Set.new(TEXT_APIS)
192
- response = Indico.predict_text(["Worst movie ever."], TEXT_APIS)
192
+ response = Indico.analyze_text(["Worst movie ever."], TEXT_APIS)
193
193
 
194
194
  expect(response.class).to eql(Hash)
195
195
  expect(Set.new(response.keys)).to eql(expected_keys)
@@ -199,7 +199,7 @@ describe Indico do
199
199
  test_image = File.dirname(__FILE__) + "/data/happy.png"
200
200
  expected_keys = Set.new(IMAGE_APIS)
201
201
  silent_warnings do
202
- response = Indico.predict_image([test_image], IMAGE_APIS)
202
+ response = Indico.analyze_image([test_image], IMAGE_APIS)
203
203
 
204
204
  expect(response.class).to eql(Hash)
205
205
  expect(Set.new(response.keys)).to eql(expected_keys)
@@ -210,7 +210,7 @@ describe Indico do
210
210
  test_image = File.dirname(__FILE__) + "/data/happy.png"
211
211
  expected_keys = Set.new(IMAGE_APIS)
212
212
  silent_warnings do
213
- response = Indico.predict_image([test_image], IMAGE_APIS)
213
+ response = Indico.analyze_image([test_image], IMAGE_APIS)
214
214
 
215
215
  expect(response.class).to eql(Hash)
216
216
  expect(Set.new(response.keys)).to eql(expected_keys)
data/spec/indico_spec.rb CHANGED
@@ -212,7 +212,7 @@ describe Indico do
212
212
 
213
213
  it "should respond with all text apis called" do
214
214
  expected_keys = Set.new(TEXT_APIS)
215
- response = Indico.predict_text("Worst movie ever.", TEXT_APIS)
215
+ response = Indico.analyze_text("Worst movie ever.", TEXT_APIS)
216
216
 
217
217
  expect(response.class).to eql(Hash)
218
218
  expect(Set.new(response.keys)).to eql(expected_keys)
@@ -220,7 +220,7 @@ describe Indico do
220
220
 
221
221
  it "should respond with all text apis called by default" do
222
222
  expected_keys = Set.new(TEXT_APIS)
223
- response = Indico.predict_text("Worst movie ever.", TEXT_APIS)
223
+ response = Indico.analyze_text("Worst movie ever.", TEXT_APIS)
224
224
 
225
225
  expect(response.class).to eql(Hash)
226
226
  expect(Set.new(response.keys)).to eql(expected_keys)
@@ -230,7 +230,7 @@ describe Indico do
230
230
  test_image = File.open(File.dirname(__FILE__) + "/data/happy64.txt", 'rb') { |f| f.read }
231
231
  expected_keys = Set.new(IMAGE_APIS)
232
232
  silent_warnings do
233
- response = Indico.predict_image(test_image, IMAGE_APIS)
233
+ response = Indico.analyze_image(test_image, IMAGE_APIS)
234
234
 
235
235
  expect(response.class).to eql(Hash)
236
236
  expect(Set.new(response.keys)).to eql(expected_keys)
@@ -241,7 +241,7 @@ describe Indico do
241
241
  test_image = File.open(File.dirname(__FILE__) + "/data/happy64.txt", 'rb') { |f| f.read }
242
242
  expected_keys = Set.new(IMAGE_APIS)
243
243
  silent_warnings do
244
- response = Indico.predict_image(test_image, IMAGE_APIS)
244
+ response = Indico.analyze_image(test_image, IMAGE_APIS)
245
245
 
246
246
  expect(response.class).to eql(Hash)
247
247
  expect(Set.new(response.keys)).to eql(expected_keys)
@@ -257,6 +257,21 @@ describe Indico do
257
257
  end
258
258
  end
259
259
 
260
+ it 'should respond with proper results from intersections api' do
261
+ text = ['data', 'baseball', 'weather']
262
+ apis = ['twitter_engagement', 'sentiment']
263
+ response = Indico.intersections(text, apis)
264
+ expect(Set.new(response.keys)).to eql(Set.new(['twitter_engagement']))
265
+ end
266
+
267
+ it 'should respond with proper results from raw intersections api' do
268
+ data = {}
269
+ data['sentiment'] = [0.1, 0.2, 0.3];
270
+ data['twitter_engagement'] = [0.1, 0.2, 0.3]
271
+ response = Indico.intersections(data, ['sentiment', 'twitter_engagement'])
272
+ expect(Set.new(response.keys)).to eql(Set.new(['sentiment']))
273
+ end
274
+
260
275
  # Uncomment when frontend updated to accept image urls
261
276
  # it 'should accept image urls' do
262
277
  # response = Indico.image_features('http://icons.iconarchive.com/icons/' +
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indico
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
5
- prerelease:
4
+ version: 0.5.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Slater Victoroff
@@ -12,86 +11,76 @@ authors:
12
11
  autorequire:
13
12
  bindir: bin
14
13
  cert_chain: []
15
- date: 2015-08-07 00:00:00.000000000 Z
14
+ date: 2015-08-14 00:00:00.000000000 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: inifile
19
18
  requirement: !ruby/object:Gem::Requirement
20
- none: false
21
19
  requirements:
22
- - - ~>
20
+ - - "~>"
23
21
  - !ruby/object:Gem::Version
24
22
  version: 3.0.0
25
23
  type: :runtime
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
26
  requirements:
30
- - - ~>
27
+ - - "~>"
31
28
  - !ruby/object:Gem::Version
32
29
  version: 3.0.0
33
30
  - !ruby/object:Gem::Dependency
34
31
  name: oily_png
35
32
  requirement: !ruby/object:Gem::Requirement
36
- none: false
37
33
  requirements:
38
- - - ~>
34
+ - - "~>"
39
35
  - !ruby/object:Gem::Version
40
36
  version: 1.2.0
41
37
  type: :runtime
42
38
  prerelease: false
43
39
  version_requirements: !ruby/object:Gem::Requirement
44
- none: false
45
40
  requirements:
46
- - - ~>
41
+ - - "~>"
47
42
  - !ruby/object:Gem::Version
48
43
  version: 1.2.0
49
44
  - !ruby/object:Gem::Dependency
50
45
  name: bundler
51
46
  requirement: !ruby/object:Gem::Requirement
52
- none: false
53
47
  requirements:
54
- - - ~>
48
+ - - "~>"
55
49
  - !ruby/object:Gem::Version
56
50
  version: '1.6'
57
51
  type: :development
58
52
  prerelease: false
59
53
  version_requirements: !ruby/object:Gem::Requirement
60
- none: false
61
54
  requirements:
62
- - - ~>
55
+ - - "~>"
63
56
  - !ruby/object:Gem::Version
64
57
  version: '1.6'
65
58
  - !ruby/object:Gem::Dependency
66
59
  name: rake
67
60
  requirement: !ruby/object:Gem::Requirement
68
- none: false
69
61
  requirements:
70
- - - ! '>='
62
+ - - ">="
71
63
  - !ruby/object:Gem::Version
72
64
  version: '0'
73
65
  type: :development
74
66
  prerelease: false
75
67
  version_requirements: !ruby/object:Gem::Requirement
76
- none: false
77
68
  requirements:
78
- - - ! '>='
69
+ - - ">="
79
70
  - !ruby/object:Gem::Version
80
71
  version: '0'
81
72
  - !ruby/object:Gem::Dependency
82
73
  name: rspec
83
74
  requirement: !ruby/object:Gem::Requirement
84
- none: false
85
75
  requirements:
86
- - - ! '>='
76
+ - - ">="
87
77
  - !ruby/object:Gem::Version
88
78
  version: '0'
89
79
  type: :development
90
80
  prerelease: false
91
81
  version_requirements: !ruby/object:Gem::Requirement
92
- none: false
93
82
  requirements:
94
- - - ! '>='
83
+ - - ">="
95
84
  - !ruby/object:Gem::Version
96
85
  version: '0'
97
86
  description: A simple Ruby Wrapper for the indico set of APIs.
@@ -104,8 +93,8 @@ executables: []
104
93
  extensions: []
105
94
  extra_rdoc_files: []
106
95
  files:
107
- - .gitignore
108
- - .rspec
96
+ - ".gitignore"
97
+ - ".rspec"
109
98
  - Gemfile
110
99
  - LICENSE.txt
111
100
  - README.md
@@ -129,26 +118,25 @@ files:
129
118
  homepage: https://github.com/IndicoDataSolutions/IndicoIo-ruby
130
119
  licenses:
131
120
  - MIT
121
+ metadata: {}
132
122
  post_install_message:
133
123
  rdoc_options: []
134
124
  require_paths:
135
125
  - lib
136
126
  required_ruby_version: !ruby/object:Gem::Requirement
137
- none: false
138
127
  requirements:
139
- - - ! '>='
128
+ - - ">="
140
129
  - !ruby/object:Gem::Version
141
130
  version: '0'
142
131
  required_rubygems_version: !ruby/object:Gem::Requirement
143
- none: false
144
132
  requirements:
145
- - - ! '>='
133
+ - - ">="
146
134
  - !ruby/object:Gem::Version
147
135
  version: '0'
148
136
  requirements: []
149
137
  rubyforge_project:
150
- rubygems_version: 1.8.23
138
+ rubygems_version: 2.4.6
151
139
  signing_key:
152
- specification_version: 3
140
+ specification_version: 4
153
141
  summary: A simple Ruby Wrapper for the indico set of APIs.
154
142
  test_files: []