indico 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de85a9b86534b52b962f7293c6a012ce1beed21f
4
- data.tar.gz: bb518f38c4797add87f0cfb24467d960d5df23cb
3
+ metadata.gz: 4e197cd029719640023170141e26211f2695029a
4
+ data.tar.gz: f9439e5f00fc3370d49ca7368b806c0f1451bb1f
5
5
  SHA512:
6
- metadata.gz: bb5111b6aeb42548a2c654c8401d5be53f6c31c09d6916908e247918193b0b55da6fab98d1c58a1345d1912be8400bd8fc6661bdf312b12954079c412379e509
7
- data.tar.gz: 9d96c560aa0926b193ab813f5ce5cffa303fb698783a928e94e9857740206629c0690da6c48c05fc27ad0bfd742f6b51dd9cce0cee994fabe0b81c642590a006
6
+ metadata.gz: bb6c9222db326aec5a02f5d4fcbcfe99fe744439df6f6c5d8cd62536d61ade512fc4009df2ec38735ddbfceffc50b502ca19ac09f3885813266aa3c0ca3887d1
7
+ data.tar.gz: 47741995eaaf733b88673b745dca5b698843f62be040268d9920657320aecb6abee4cbb8aecf75f2945876569d7f683a76d754ef6fdb384fa4e642bef9540593
data/lib/indico/helper.rb CHANGED
@@ -10,8 +10,8 @@ module Indico
10
10
  Indico.cloud_protocol + root + '.indico.domains/' + api
11
11
  end
12
12
  end
13
-
14
- def self.api_handler(data, api, config)
13
+
14
+ def self.api_handler(data, api, config, method='predict')
15
15
  server = nil
16
16
  api_key = nil
17
17
  version = nil
@@ -25,6 +25,8 @@ module Indico
25
25
  end
26
26
  end
27
27
 
28
+ api += (method != "predict" ? ("/" + method) : "")
29
+
28
30
  unless config.nil?
29
31
  server = config.delete('cloud')
30
32
  api_key = config.delete('api_key')
@@ -48,7 +50,7 @@ module Indico
48
50
  response = make_request(url, JSON.dump(d),
49
51
  add_api_key_to_header(api_key))
50
52
 
51
- response.header.each_header do |key, value|
53
+ response.each_header do |key, value|
52
54
  if key.downcase == 'x-warning'
53
55
  warn value
54
56
  end
data/lib/indico/multi.rb CHANGED
@@ -15,7 +15,8 @@ module Indico
15
15
  "facial_localization" => "facial_localization",
16
16
  "image_features" => "imagefeatures",
17
17
  "content_filtering" => "contentfiltering",
18
- "twitter_engagement" => "twitterengagement"
18
+ "twitter_engagement" => "twitterengagement",
19
+ "myers_briigs" => "myersbriggs"
19
20
  }
20
21
 
21
22
  SERVER_TO_CLIENT = CLIENT_TO_SERVER.invert
@@ -1,3 +1,3 @@
1
1
  module Indico
2
- VERSION = '0.5.4'
2
+ VERSION = '0.6.0'
3
3
  end
data/lib/indico.rb CHANGED
@@ -28,154 +28,63 @@ module Indico
28
28
  api_handler(text, 'political', config)
29
29
  end
30
30
 
31
- def self.batch_political(text, config = nil)
32
- warn(
33
- "The `batch_political` function will be deprecated in the next major upgrade. " +
34
- "Please call `political` instead with the same arguments"
35
- )
36
- self.political(text, config)
37
- end
38
-
39
31
  def self.posneg(*args)
40
32
  sentiment(*args)
41
33
  end
42
34
 
43
- def self.batch_posneg(text, config = nil)
44
- warn(
45
- "The `batch_posneg` function will be deprecated in the next major upgrade. " +
46
- "Please call `posneg` instead with the same arguments"
47
- )
48
- self.posneg(text, config)
49
- end
50
-
51
35
  def self.sentiment(text, config = nil)
52
36
  api_handler(text, 'sentiment', config)
53
37
  end
54
38
 
55
- def self.batch_sentiment(text, config = nil)
56
- warn(
57
- "The `batch_sentiment` function will be deprecated in the next major upgrade. " +
58
- "Please call `sentiment` instead with the same arguments"
59
- )
60
- self.sentiment(text, config)
39
+ def self.personality(text, config = nil)
40
+ api_handler(text, 'personality', config)
61
41
  end
62
42
 
43
+ def self.personas(text, config = {'persona'=> true})
44
+ api_handler(text, 'personality', config)
45
+ end
63
46
 
64
47
  def self.twitter_engagement(text, config = nil)
65
48
  api_handler(text, 'twitterengagement', config)
66
49
  end
67
50
 
68
- def self.batch_twitter_engagement(text, config = nil)
69
- warn(
70
- "The `batch_twitter_engagement` function will be deprecated in the next major upgrade. " +
71
- "Please call `twitter_engagement` instead with the same arguments"
72
- )
73
- self.twitter_engagement(text, config)
74
- end
75
-
76
51
  def self.sentiment_hq(text, config = nil)
77
52
  api_handler(text, 'sentimenthq', config)
78
53
  end
79
54
 
80
- def self.batch_sentiment_hq(text, config = nil)
81
- warn(
82
- "The `batch_sentiment_hq` function will be deprecated in the next major upgrade. " +
83
- "Please call `sentiment_hq` instead with the same arguments"
84
- )
85
- self.sentiment_hq(text, config)
86
- end
87
-
88
-
89
55
  def self.language(text, config = nil)
90
56
  api_handler(text, 'language', config)
91
57
  end
92
58
 
93
- def self.batch_language(text, config = nil)
94
- warn(
95
- "The `batch_language` function will be deprecated in the next major upgrade. " +
96
- "Please call `language` instead with the same arguments"
97
- )
98
- self.language(text, config)
99
- end
100
-
101
-
102
59
  def self.text_tags(text, config = nil)
103
60
  api_handler(text, 'texttags', config)
104
61
  end
105
62
 
106
- def self.batch_text_tags(text, config = nil)
107
- warn(
108
- "The `batch_text_tags` function will be deprecated in the next major upgrade. " +
109
- "Please call `text_tags` instead with the same arguments"
110
- )
111
- self.text_tags(text, config)
112
- end
113
-
114
-
115
63
  def self.keywords(text, config = nil)
116
64
  api_handler(text, 'keywords', config)
117
65
  end
118
66
 
119
- def self.batch_keywords(text, config = nil)
120
- warn(
121
- "The `batch_keywords` function will be deprecated in the next major upgrade. " +
122
- "Please call `keywords` instead with the same arguments"
123
- )
124
- self.keywords(text, config)
125
- end
126
-
127
-
128
67
  def self.named_entities(test_text, config = nil)
129
68
  api_handler(test_text, 'namedentities', config)
130
69
  end
131
70
 
132
- def self.batch_named_entities(text, config = nil)
133
- warn(
134
- "The `batch_named_entities` function will be deprecated in the next major upgrade. " +
135
- "Please call `named_entities` instead with the same arguments"
136
- )
137
- self.named_entities(text, config)
138
- end
139
-
140
71
  def self.fer(image, config = nil)
141
72
  size = (config != nil and config["detect"] == true) ? false : 48
142
73
  api_handler(preprocess(image, size, false), 'fer', config)
143
74
  end
144
75
 
145
- def self.batch_fer(image, config = nil)
146
- warn(
147
- "The `batch_fer` function will be deprecated in the next major upgrade. " +
148
- "Please call `fer` instead with the same arguments"
149
- )
150
- self.fer(image, config)
151
- end
152
-
153
-
154
76
  def self.facial_features(image, config = nil)
155
77
  api_handler(preprocess(image, 48, false), 'facialfeatures', config)
156
78
  end
157
79
 
158
- def self.batch_facial_features(image, config = nil)
159
- warn(
160
- "The `batch_facial_features` function will be deprecated in the next major upgrade. " +
161
- "Please call `facial_features` instead with the same arguments"
162
- )
163
- self.facial_features(image, config)
164
- end
165
-
166
80
  def self.facial_localization(image, config = nil)
167
81
  api_handler(preprocess(image, false, false), 'faciallocalization', config)
168
82
  end
169
83
 
170
- def self.batch_facial_localization(image, config = nil)
171
- warn(
172
- "The `batch_facial_localization` function will be deprecated in the next major upgrade. " +
173
- "Please call `facial_localization` instead with the same arguments"
174
- )
175
- self.facial_localization(image, config)
176
- end
177
-
178
- def self.image_features(image, config = nil)
84
+ def self.image_features(image, config = {})
85
+ unless config.key?(:v) or config.key?(:version)
86
+ config[:version] = "3"
87
+ end
179
88
  api_handler(preprocess(image, 144, true), 'imagefeatures', config)
180
89
  end
181
90
 
@@ -183,50 +92,95 @@ module Indico
183
92
  api_handler(preprocess(image, 144, true), 'imagerecognition', config)
184
93
  end
185
94
 
186
- def self.batch_image_features(image, config = nil)
187
- warn(
188
- "The `batch_image_features` function will be deprecated in the next major upgrade. " +
189
- "Please call `image_features` instead with the same arguments"
190
- )
191
- self.image_features(image, config)
192
- end
193
95
 
194
96
  def self.content_filtering(image, config = nil)
195
97
  api_handler(preprocess(image, 128, true), 'contentfiltering', config)
196
98
  end
197
99
 
198
- def self.batch_content_filtering(image, config = nil)
199
- warn(
200
- "The `batch_content_filtering` function will be deprecated in the next major upgrade. " +
201
- "Please call `content_filtering` instead with the same arguments"
202
- )
203
- self.content_filtering(image, config)
204
- end
205
-
206
100
  def self.analyze_image(face, apis = IMAGE_APIS, config = nil)
207
101
  api_hash = {apis:apis}
208
102
  multi(preprocess(face, 48, false), "image", apis, IMAGE_APIS, config ? config.update(api_hash) : api_hash)
209
103
  end
210
104
 
211
- def self.batch_analyze_image(image, apis = IMAGE_APIS, config = nil)
212
- warn(
213
- "The `batch_analyze_image` function will be deprecated in the next major upgrade. " +
214
- "Please call `analyze_image` instead with the same arguments"
215
- )
216
- self.analyze_image(image, apis, config)
217
- end
218
-
219
105
  def self.analyze_text(text, apis = TEXT_APIS, config = nil)
220
106
  api_hash = {apis:apis}
221
107
  multi(text, "text", apis, TEXT_APIS, config ? config.update(api_hash) : api_hash)
222
108
  end
223
109
 
224
- def self.batch_analyze_text(text, apis = TEXT_APIS, config = nil)
225
- warn(
226
- "The `batch_analyze_text` function will be deprecated in the next major upgrade. " +
227
- "Please call `analyze_text` instead with the same arguments"
228
- )
229
- self.analyze_text(text, apis, config)
110
+ def self.collections(config = nil)
111
+ Indico.api_handler(nil, 'custom', config, 'collections')
112
+ end
113
+
114
+ class Collection
115
+
116
+ def initialize(collection)
117
+ if collection.kind_of?(String)
118
+ @collection = collection
119
+ else
120
+ raise TypeError, "Collection must be initialized with a String name"
121
+ end
122
+ end
123
+
124
+ def add_data(data, config = nil)
125
+
126
+ is_batch = data[0].kind_of?(Array)
127
+ if is_batch
128
+ x, y = data.transpose
129
+ x = Indico::preprocess(x, 144, true)
130
+ data = x.zip(y)
131
+ else
132
+ data[0] = Indico::preprocess(data[0], 144, true)
133
+ end
134
+
135
+ if config.nil?
136
+ config = Hash.new()
137
+ end
138
+ config[:collection] = @collection
139
+ Indico.api_handler(data, 'custom', config, 'add_data')
140
+ end
141
+
142
+ def train(config = nil)
143
+ if config.nil?
144
+ config = Hash.new()
145
+ end
146
+ config[:collection] = @collection
147
+ Indico.api_handler(nil, 'custom', config, 'train')
148
+ end
149
+
150
+ def wait(interval = 1)
151
+ while info()['status'] != "ready" do
152
+ sleep(interval)
153
+ end
154
+ end
155
+
156
+ def info(interval = 1)
157
+ Indico.collections()[@collection]
158
+ end
159
+
160
+ def predict(data, config = nil)
161
+ data = Indico::preprocess(data, 144, true)
162
+ if config.nil?
163
+ config = Hash.new()
164
+ end
165
+ config[:collection] = @collection
166
+ Indico.api_handler(data, 'custom', config, 'predict')
167
+ end
168
+
169
+ def remove_example(data, config = nil)
170
+ data = Indico::preprocess(data, 144, true)
171
+ if config.nil?
172
+ config = Hash.new()
173
+ end
174
+ config[:collection] = @collection
175
+ Indico.api_handler(data, 'custom', config, 'remove_example')
176
+ end
177
+
178
+ def clear(config = nil)
179
+ if config.nil?
180
+ config = Hash.new()
181
+ end
182
+ config[:collection] = @collection
183
+ Indico.api_handler(nil, 'custom', config, 'clear_collection')
184
+ end
230
185
  end
231
-
232
186
  end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'set'
3
+
4
+ test_data = [['input 1', 'label 1'], ['input 2', 'label 2'], ['input 3', 'label 3'], ['input 4', 'label 4']]
5
+ text_collection = '__test_ruby_text__'
6
+
7
+ describe Indico do
8
+ before do
9
+ api_key = ENV['INDICO_API_KEY']
10
+ @config = { api_key: api_key}
11
+ end
12
+
13
+ after(:each) do
14
+ begin
15
+ collection = Indico::Collection.new(text_collection)
16
+ collection.clear()
17
+ rescue
18
+ # no op -- collection doesn't
19
+ end
20
+ end
21
+
22
+ it 'should instantiate a Collection object and add data to the collection' do
23
+ collection = Indico::Collection.new(text_collection)
24
+ collection.add_data(test_data)
25
+ end
26
+
27
+ it "should add data, train, and predict" do
28
+ collection = Indico::Collection.new(text_collection)
29
+ collection.add_data(test_data)
30
+ collection.train()
31
+ collection.wait()
32
+ result = collection.predict(test_data[0][0])
33
+ expect(result).to have_key(test_data[0][1])
34
+ end
35
+
36
+ it "should list collections" do
37
+ collection = Indico::Collection.new(text_collection)
38
+ collection.add_data(test_data)
39
+ collection.train()
40
+ collection.wait()
41
+ expect(Indico::collections()).to have_key(text_collection)
42
+ end
43
+
44
+ it "should clear an example" do
45
+ collection = Indico::Collection.new(text_collection)
46
+ collection.add_data(test_data)
47
+ collection.train()
48
+ collection.wait()
49
+ result = collection.predict(test_data[0][0])
50
+ expect(result).to have_key(test_data[0][1])
51
+ collection.remove_example(test_data[0][0])
52
+ collection.train()
53
+ collection.wait()
54
+ result = collection.predict(test_data[0][0])
55
+ expect(result).to_not have_key(test_data[0][1])
56
+ end
57
+
58
+ it "should clear a collection" do
59
+ collection = Indico::Collection.new(text_collection)
60
+ collection.add_data(test_data)
61
+ collection.train()
62
+ collection.wait()
63
+ expect(Indico::collections()).to have_key(text_collection)
64
+ collection.clear()
65
+ expect(Indico::collections()).to_not have_key(text_collection)
66
+ end
67
+
68
+ end
@@ -21,6 +21,27 @@ describe Indico do
21
21
  expect(Set.new(response[1].keys)).to eql(expected_keys)
22
22
  end
23
23
 
24
+ it 'should return personality values for text' do
25
+ expected_keys = Set.new(%w(openness extraversion conscientiousness agreeableness))
26
+
27
+ data = ['I love my friends!', 'I like to be alone']
28
+ response = Indico.personality(data)
29
+
30
+ expect(Set.new(response[0].keys)).to eql(expected_keys)
31
+ expect(Set.new(response[1].keys)).to eql(expected_keys)
32
+ end
33
+
34
+ it 'should return personas for text' do
35
+ expected_keys = Set.new(%w(architect mediator executive entertainer))
36
+ data = ['I love my friends!', 'I like to be alone']
37
+ response = Indico.personas(data)
38
+
39
+ expected_keys.each do |key|
40
+ expect(Set.new(response[0].keys)).to include(key)
41
+ expect(Set.new(response[1].keys)).to include(key)
42
+ end
43
+ end
44
+
24
45
  it 'should access a private cloud' do
25
46
  expected_keys = Set.new(%w(Conservative Green Liberal Libertarian))
26
47
  data = ['Guns don\'t kill people.', ' People kill people.']
@@ -172,8 +193,8 @@ describe Indico do
172
193
  test_image = File.dirname(__FILE__) + "/data/happy.png"
173
194
  silent_warnings do
174
195
  response = Indico.image_features([test_image, test_image], @config)
175
- expect(response[0].length).to eql(2048)
176
- expect(response[1].length).to eql(2048)
196
+ expect(response[0].length).to eql(4096)
197
+ expect(response[1].length).to eql(4096)
177
198
  end
178
199
  end
179
200
 
@@ -217,15 +238,13 @@ describe Indico do
217
238
  end
218
239
  end
219
240
 
241
+ it "should accept image urls" do
242
+ test_image = 'http://icons.iconarchive.com/icons/oxygen-icons.org/' +
243
+ 'oxygen/48/Emotes-face-smile-icon.png'
244
+ response = Indico.image_features([test_image, test_image],
245
+ @config)
220
246
 
221
- # Uncomment when frontend updated to accept image urls
222
- # it "should accept image urls" do
223
- # test_image = 'http://icons.iconarchive.com/icons/oxygen-icons.org/' +
224
- # 'oxygen/48/Emotes-face-smile-icon.png'
225
- # response = Indico.image_features([test_image, test_image],
226
- # @config)
227
-
228
- # expect(response[0].length).to eql(2048)
229
- # expect(response[1].length).to eql(2048)
230
- # end
247
+ expect(response[0].length).to eql(4096)
248
+ expect(response[1].length).to eql(4096)
249
+ end
231
250
  end
data/spec/indico_spec.rb CHANGED
@@ -16,6 +16,22 @@ describe Indico do
16
16
  expect(Set.new(response.keys)).to eql(expected_keys)
17
17
  end
18
18
 
19
+ it 'should return personality values for text' do
20
+ expected_keys = Set.new(%w(openness extraversion conscientiousness agreeableness))
21
+ response = Indico.personality('I love my friends!')
22
+
23
+ expect(Set.new(response.keys)).to eql(expected_keys)
24
+ end
25
+
26
+ it 'should return personas for text' do
27
+ expected_keys = Set.new(%w(architect mediator executive entertainer))
28
+ response = Indico.personas('I love my friends!')
29
+
30
+ expected_keys.each do |key|
31
+ expect(Set.new(response.keys)).to include(key)
32
+ end
33
+ end
34
+
19
35
  it 'should tag text with correct political tags' do
20
36
  expected_keys = Set.new(%w(Conservative Green Liberal Libertarian))
21
37
  data = 'Guns don\'t kill people. People kill people.'
@@ -180,7 +196,7 @@ describe Indico do
180
196
  test_image= File.dirname(__FILE__) + "/data/happy.png"
181
197
  silent_warnings do
182
198
  response = Indico.image_features(test_image)
183
- expect(response.length).to eql(2048)
199
+ expect(response.length).to eql(4096)
184
200
  end
185
201
  end
186
202
 
@@ -188,7 +204,7 @@ describe Indico do
188
204
  test_image= File.dirname(__FILE__) + "/data/dog.jpg"
189
205
  silent_warnings do
190
206
  response = Indico.image_features(test_image)
191
- expect(response.length).to eql(2048)
207
+ expect(response.length).to eql(4096)
192
208
  end
193
209
  end
194
210
 
@@ -196,7 +212,7 @@ describe Indico do
196
212
  test_image = File.open(File.dirname(__FILE__) + "/data/happy64.txt", 'rb') { |f| f.read }
197
213
  silent_warnings do
198
214
  response = Indico.image_features(test_image)
199
- expect(response.length).to eql(2048)
215
+ expect(response.length).to eql(4096)
200
216
  end
201
217
  end
202
218
 
@@ -282,7 +298,7 @@ describe Indico do
282
298
  response = Indico.image_features('http://icons.iconarchive.com/icons/' +
283
299
  'oxygen-icons.org/oxygen/48/' +
284
300
  'Emotes-face-smile-icon.png')
285
-
286
- expect(response.length).to eql(2048)
301
+
302
+ expect(response.length).to eql(4096)
287
303
  end
288
304
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indico
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Slater Victoroff
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-10-30 00:00:00.000000000 Z
14
+ date: 2015-11-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: inifile
@@ -109,6 +109,7 @@ files:
109
109
  - lib/indico/version.rb
110
110
  - spec/config/.indicorc.test
111
111
  - spec/config/.indicorc.test.2
112
+ - spec/custom_spec.rb
112
113
  - spec/data/dog.jpg
113
114
  - spec/data/happy.png
114
115
  - spec/data/happy64.txt