indico 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/lib/indico/helper.rb +4 -0
- data/lib/indico/image.rb +30 -46
- data/lib/indico/multi.rb +4 -1
- data/lib/indico/version.rb +1 -1
- data/lib/indico.rb +111 -27
- data/spec/indico_batch_spec.rb +39 -21
- data/spec/indico_spec.rb +44 -8
- metadata +23 -11
- checksums.yaml +0 -7
data/README.md
CHANGED
@@ -72,7 +72,7 @@ Each `Indico` method has a corresponding batch method for analyzing many example
|
|
72
72
|
|
73
73
|
=> "YOUR_API_KEY"
|
74
74
|
|
75
|
-
> Indico.
|
75
|
+
> Indico.sentiment(['Best day ever', 'Worst day ever'])
|
76
76
|
|
77
77
|
=> [0.9899001220871786, 0.005709885173415242]
|
78
78
|
```
|
@@ -99,7 +99,7 @@ Accepted image API names: `fer, facial_features, image_features`
|
|
99
99
|
|
100
100
|
=> {"sentiment"=>0.9899001220871786, "language"=>{"Swedish"=>0.0022464881013042294, "Vietnamese"=>9.887170914498351e-05, ...}}
|
101
101
|
|
102
|
-
> Indico.
|
102
|
+
> Indico.predict_text(["Best day ever", "Worst day ever"], ["sentiment", "language"])
|
103
103
|
|
104
104
|
=> {"sentiment"=>[0.9899001220871786, 0.005709885173415242], "language"=>[{"Swedish"=>0.0022464881013042294, "Vietnamese"=>9.887170914498351e-05, "Romanian"=>0.00010661175919993216, ...}, {"Swedish"=>0.4924352805804646, "Vietnamese"=>0.028574824174911372, "Romanian"=>0.004185623723173551, "Dutch"=>0.000717033819689362, "Korean"=>0.0030093489153785826, ...}]}
|
105
105
|
|
@@ -111,7 +111,7 @@ Accepted image API names: `fer, facial_features, image_features`
|
|
111
111
|
|
112
112
|
=> {"facial_features"=>[0.0, -0.026176479280200796, 0.20707644777495776, ...], "fer"=>{"Angry"=>0.08877494466353497, "Sad"=>0.3933999409104264, "Neutral"=>0.1910612654566151, "Surprise"=>0.0346146405941845, "Fear"=>0.17682159820518667, "Happy"=>0.11532761017005204}}
|
113
113
|
|
114
|
-
> Indico.
|
114
|
+
> Indico.predict_image([test_face, test_face], ["fer", "facial_features"])
|
115
115
|
|
116
116
|
=> {"facial_features"=>[[0.0, -0.026176479280200796, 0.20707644777495776, ...], [0.0, -0.026176479280200796, 0.20707644777495776, ...]], "fer"=>[{"Angry"=>0.08877494466353497, "Sad"=>0.3933999409104264, "Neutral"=>0.1910612654566151, "Surprise"=>0.0346146405941845, "Fear"=>0.17682159820518667, "Happy"=>0.11532761017005204}, {"Angry"=>0.08877494466353497, "Sad"=>0.3933999409104264, "Neutral"=>0.1910612654566151, "Surprise"=>0.0346146405941845, "Fear"=>0.17682159820518667, "Happy"=>0.11532761017005204}]}
|
117
117
|
```
|
data/lib/indico/helper.rb
CHANGED
data/lib/indico/image.rb
CHANGED
@@ -2,30 +2,50 @@ require 'oily_png'
|
|
2
2
|
require 'base64'
|
3
3
|
|
4
4
|
module Indico
|
5
|
-
def self.preprocess(image, size,
|
6
|
-
|
7
|
-
if
|
5
|
+
def self.preprocess(image, size, min_axis)
|
6
|
+
|
7
|
+
if image.class == String
|
8
|
+
decoded_image = handle_string_input(image)
|
9
|
+
elsif image.class == Array
|
8
10
|
# Batch Request
|
9
11
|
im_array = Array.new
|
10
12
|
|
11
13
|
# process each image
|
12
14
|
image.each do |_image|
|
13
|
-
im_array.push(preprocess(_image, size,
|
15
|
+
im_array.push(preprocess(_image, size, min_axis))
|
14
16
|
end
|
15
17
|
|
16
18
|
return im_array
|
19
|
+
else
|
20
|
+
raise Exception.new("Image input must be filename or base64 string")
|
17
21
|
end
|
18
22
|
|
19
|
-
if
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
if size
|
24
|
+
if min_axis
|
25
|
+
image = self.min_resize(decoded_image, size)
|
26
|
+
else
|
27
|
+
image = decoded_image.resize(size, size)
|
28
|
+
end
|
23
29
|
else
|
24
|
-
|
30
|
+
image = decoded_image
|
25
31
|
end
|
26
32
|
|
27
33
|
# Resize and export base64 encoded string
|
28
|
-
return
|
34
|
+
return image.to_data_url.gsub("data:image/png;base64," ,"")
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.min_resize(decoded_image, size)
|
38
|
+
img_size = [decoded_image.width, decoded_image.height]
|
39
|
+
min_idx, max_idx = img_size[0] < img_size[1] ? [0, 1] : [1, 0]
|
40
|
+
aspect = img_size[max_idx] / Float(img_size[min_idx])
|
41
|
+
if aspect > 10
|
42
|
+
warn("An aspect ratio greater than 10:1 is not recommended")
|
43
|
+
end
|
44
|
+
size_arr = [0, 0]
|
45
|
+
size_arr[min_idx] = size
|
46
|
+
size_arr[max_idx] = Integer(size * aspect)
|
47
|
+
image = decoded_image.resize(size_arr[0], size_arr[1])
|
48
|
+
return image
|
29
49
|
end
|
30
50
|
|
31
51
|
def self.handle_string_input(str)
|
@@ -44,42 +64,6 @@ module Indico
|
|
44
64
|
end
|
45
65
|
end
|
46
66
|
|
47
|
-
def self.handle_array_input(image)
|
48
|
-
# Handles properly formatting and loading array of pixels
|
49
|
-
# Single Request
|
50
|
-
warn "Warning! Array input as image will be deprecated in the next major release.\n Consider using filepaths or base64 encoded strings"
|
51
|
-
|
52
|
-
dimens = get_dimension(image)
|
53
|
-
isFloat = array_contains_float(image, dimens)
|
54
|
-
|
55
|
-
if dimens.size > 3
|
56
|
-
raise Exception.new("Nested array of image must be [[p, p, ...]] or [[[r,g,b], [r,g,b], ...]]")
|
57
|
-
end
|
58
|
-
|
59
|
-
decoded_image = ChunkyPNG::Image.new(dimens[0], dimens[1])
|
60
|
-
|
61
|
-
# Manually loading the pixels into the ChunkyImage object
|
62
|
-
(0..dimens[0] - 1).each do |x|
|
63
|
-
(0..dimens[1] - 1).each do |y|
|
64
|
-
pixel = image[x][y]
|
65
|
-
if pixel.is_a?(Array)
|
66
|
-
if isFloat
|
67
|
-
pixel.map! {|a| (255 * a).to_i}
|
68
|
-
end
|
69
|
-
decoded_image.set_pixel(x,y, ChunkyPNG::Color.rgb(pixel[0], pixel[1], pixel[2]))
|
70
|
-
else
|
71
|
-
if isFloat
|
72
|
-
pixel = (pixel * 255).to_i
|
73
|
-
end
|
74
|
-
decoded_image.set_pixel(x,y, ChunkyPNG::Color.rgb(pixel, pixel, pixel))
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
return decoded_image
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
67
|
def self.get_dimension(array)
|
84
68
|
return [] unless array.is_a?(Array)
|
85
69
|
return [array.size] + get_dimension(array[0])
|
data/lib/indico/multi.rb
CHANGED
@@ -8,9 +8,12 @@ module Indico
|
|
8
8
|
"language" => "language",
|
9
9
|
"text_tags" => "texttags",
|
10
10
|
"fer" => "fer",
|
11
|
+
"named_entities" => "named_entities",
|
12
|
+
"keywords" => "keywords",
|
11
13
|
"facial_features" => "facialfeatures",
|
12
14
|
"image_features" => "imagefeatures",
|
13
|
-
"content_filtering" => "contentfiltering"
|
15
|
+
"content_filtering" => "contentfiltering",
|
16
|
+
"twitter_engagement" => "twitterengagement"
|
14
17
|
}
|
15
18
|
|
16
19
|
SERVER_TO_CLIENT = CLIENT_TO_SERVER.invert
|
data/lib/indico/version.rb
CHANGED
data/lib/indico.rb
CHANGED
@@ -29,15 +29,23 @@ module Indico
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.batch_political(text, config = nil)
|
32
|
-
|
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)
|
33
37
|
end
|
34
38
|
|
35
39
|
def self.posneg(*args)
|
36
40
|
sentiment(*args)
|
37
41
|
end
|
38
42
|
|
39
|
-
def self.batch_posneg(
|
40
|
-
|
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)
|
41
49
|
end
|
42
50
|
|
43
51
|
def self.sentiment(text, config = nil)
|
@@ -45,7 +53,24 @@ module Indico
|
|
45
53
|
end
|
46
54
|
|
47
55
|
def self.batch_sentiment(text, config = nil)
|
48
|
-
|
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)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def self.twitter_engagement(text, config = nil)
|
65
|
+
api_handler(text, 'twitterengagement', config)
|
66
|
+
end
|
67
|
+
|
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)
|
49
74
|
end
|
50
75
|
|
51
76
|
def self.sentiment_hq(text, config = nil)
|
@@ -53,55 +78,101 @@ module Indico
|
|
53
78
|
end
|
54
79
|
|
55
80
|
def self.batch_sentiment_hq(text, config = nil)
|
56
|
-
|
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)
|
57
86
|
end
|
58
87
|
|
88
|
+
|
59
89
|
def self.language(text, config = nil)
|
60
90
|
api_handler(text, 'language', config)
|
61
91
|
end
|
62
92
|
|
63
93
|
def self.batch_language(text, config = nil)
|
64
|
-
|
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)
|
65
99
|
end
|
66
100
|
|
101
|
+
|
67
102
|
def self.text_tags(text, config = nil)
|
68
103
|
api_handler(text, 'texttags', config)
|
69
104
|
end
|
70
105
|
|
71
106
|
def self.batch_text_tags(text, config = nil)
|
72
|
-
|
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)
|
73
112
|
end
|
74
113
|
|
114
|
+
|
75
115
|
def self.keywords(text, config = nil)
|
76
116
|
api_handler(text, 'keywords', config)
|
77
117
|
end
|
78
118
|
|
79
119
|
def self.batch_keywords(text, config = nil)
|
80
|
-
|
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)
|
81
125
|
end
|
82
126
|
|
127
|
+
|
83
128
|
def self.named_entities(test_text, config = nil)
|
84
129
|
api_handler(test_text, 'namedentities', config)
|
85
130
|
end
|
86
131
|
|
87
|
-
def self.batch_named_entities(
|
88
|
-
|
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)
|
89
138
|
end
|
90
139
|
|
91
|
-
def self.fer(
|
92
|
-
|
140
|
+
def self.fer(image, config = nil)
|
141
|
+
size = (config != nil and config["detect"] == true) ? false : 48
|
142
|
+
api_handler(preprocess(image, size, false), 'fer', config)
|
93
143
|
end
|
94
144
|
|
95
145
|
def self.batch_fer(image, config = nil)
|
96
|
-
|
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)
|
97
151
|
end
|
98
152
|
|
153
|
+
|
99
154
|
def self.facial_features(image, config = nil)
|
100
155
|
api_handler(preprocess(image, 48, false), 'facialfeatures', config)
|
101
156
|
end
|
102
157
|
|
103
158
|
def self.batch_facial_features(image, config = nil)
|
104
|
-
|
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
|
+
def self.facial_localization(image, config = nil)
|
167
|
+
api_handler(preprocess(image, 128, false), 'faciallocalization', config)
|
168
|
+
end
|
169
|
+
|
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)
|
105
176
|
end
|
106
177
|
|
107
178
|
def self.image_features(image, config = nil)
|
@@ -109,15 +180,23 @@ module Indico
|
|
109
180
|
end
|
110
181
|
|
111
182
|
def self.batch_image_features(image, config = nil)
|
112
|
-
|
183
|
+
warn(
|
184
|
+
"The `batch_image_features` function will be deprecated in the next major upgrade. " +
|
185
|
+
"Please call `image_features` instead with the same arguments"
|
186
|
+
)
|
187
|
+
self.image_features(image, config)
|
113
188
|
end
|
114
189
|
|
115
190
|
def self.content_filtering(image, config = nil)
|
116
|
-
api_handler(preprocess(image, 128,
|
191
|
+
api_handler(preprocess(image, 128, true), 'contentfiltering', config)
|
117
192
|
end
|
118
193
|
|
119
194
|
def self.batch_content_filtering(image, config = nil)
|
120
|
-
|
195
|
+
warn(
|
196
|
+
"The `batch_content_filtering` function will be deprecated in the next major upgrade. " +
|
197
|
+
"Please call `content_filtering` instead with the same arguments"
|
198
|
+
)
|
199
|
+
self.content_filtering(image, config)
|
121
200
|
end
|
122
201
|
|
123
202
|
def self.predict_image(face, apis = IMAGE_APIS, config = nil)
|
@@ -125,20 +204,25 @@ module Indico
|
|
125
204
|
multi(preprocess(face, 48, false), "image", apis, IMAGE_APIS, config ? config.update(api_hash) : api_hash)
|
126
205
|
end
|
127
206
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
207
|
+
def self.batch_predict_image(image, config = nil)
|
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"
|
211
|
+
)
|
212
|
+
self.predict_image(image, config)
|
132
213
|
end
|
133
214
|
|
134
|
-
def self.
|
215
|
+
def self.predict_text(text, apis = TEXT_APIS, config = nil)
|
135
216
|
api_hash = {apis:apis}
|
136
|
-
multi(
|
217
|
+
multi(text, "text", apis, TEXT_APIS, config ? config.update(api_hash) : api_hash)
|
137
218
|
end
|
138
219
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
220
|
+
def self.batch_predict_text(text, config = nil)
|
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"
|
224
|
+
)
|
225
|
+
self.predict_text(text, config)
|
143
226
|
end
|
227
|
+
|
144
228
|
end
|
data/spec/indico_batch_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'set'
|
3
3
|
|
4
|
+
|
4
5
|
describe Indico do
|
5
6
|
before do
|
6
7
|
api_key = ENV['INDICO_API_KEY']
|
@@ -14,7 +15,7 @@ describe Indico do
|
|
14
15
|
it 'should tag text with correct political tags' do
|
15
16
|
expected_keys = Set.new(%w(Conservative Green Liberal Libertarian))
|
16
17
|
data = ['Guns don\'t kill people.', ' People kill people.']
|
17
|
-
response = Indico.
|
18
|
+
response = Indico.political(data, @config)
|
18
19
|
|
19
20
|
expect(Set.new(response[0].keys)).to eql(expected_keys)
|
20
21
|
expect(Set.new(response[1].keys)).to eql(expected_keys)
|
@@ -26,7 +27,7 @@ describe Indico do
|
|
26
27
|
|
27
28
|
# for mocking: use http instead of https to route requests to our public cloud
|
28
29
|
Indico.cloud_protocol = 'http://'
|
29
|
-
response = Indico.
|
30
|
+
response = Indico.political(data, @config_private_cloud)
|
30
31
|
Indico.cloud_protocol = 'https://'
|
31
32
|
|
32
33
|
expect(Set.new(response[0].keys)).to eql(expected_keys)
|
@@ -34,15 +35,22 @@ describe Indico do
|
|
34
35
|
end
|
35
36
|
|
36
37
|
it 'should tag text with correct sentiment tags' do
|
37
|
-
response = Indico.
|
38
|
+
response = Indico.sentiment(['Worst movie ever.'], @config)
|
38
39
|
expect(response[0] < 0.5).to eql(true)
|
39
40
|
end
|
40
41
|
|
41
42
|
it 'should tag text with correct sentiment_hq tags' do
|
42
|
-
response = Indico.
|
43
|
+
response = Indico.sentiment_hq(['Worst movie ever.'], @config)
|
43
44
|
expect(response[0] < 0.5).to eql(true)
|
44
45
|
end
|
45
46
|
|
47
|
+
it 'should tag text with correct twitter engagment tags' do
|
48
|
+
response = Indico.twitter_engagement(['#Breaking rt if you <3 pic.twitter.com @Startup'])
|
49
|
+
|
50
|
+
expect(response[0] < 1).to eql(true)
|
51
|
+
expect(response[0] > 0).to eql(true)
|
52
|
+
end
|
53
|
+
|
46
54
|
it 'should tag text with correct language tags' do
|
47
55
|
expected_keys = Set.new([
|
48
56
|
'English',
|
@@ -82,7 +90,7 @@ describe Indico do
|
|
82
90
|
])
|
83
91
|
|
84
92
|
data = ['Quis custodiet ipsos custodes', 'Clearly english, foo!']
|
85
|
-
response = Indico.
|
93
|
+
response = Indico.language(data, @config)
|
86
94
|
|
87
95
|
expect(Set.new(response[0].keys)).to eql(expected_keys)
|
88
96
|
expect(Set.new(response[1].keys)).to eql(expected_keys)
|
@@ -102,7 +110,7 @@ describe Indico do
|
|
102
110
|
fitness military realestate history))
|
103
111
|
|
104
112
|
data = ['Guns don\'t kill people.', 'People kill people.']
|
105
|
-
response = Indico.
|
113
|
+
response = Indico.text_tags(data, @config)
|
106
114
|
|
107
115
|
expect Set.new(response[0].keys).subset?(Set.new(expected_keys))
|
108
116
|
expect Set.new(response[1].keys).subset?(Set.new(expected_keys))
|
@@ -112,7 +120,7 @@ describe Indico do
|
|
112
120
|
expected_keys = Set.new(%w(people kill guns))
|
113
121
|
|
114
122
|
data = ['Guns don\'t kill people.', 'People kill people.']
|
115
|
-
response = Indico.
|
123
|
+
response = Indico.keywords(data, @config)
|
116
124
|
|
117
125
|
expect Set.new(response[0].keys).subset?(Set.new(expected_keys))
|
118
126
|
expect Set.new(response[1].keys).subset?(Set.new(expected_keys))
|
@@ -120,7 +128,7 @@ describe Indico do
|
|
120
128
|
|
121
129
|
it 'should return all named entities with category breakdowns' do
|
122
130
|
expected_keys = Set.new(%w(unknown organization location person))
|
123
|
-
response = Indico.
|
131
|
+
response = Indico.named_entities(['I want to move to New York City!'])
|
124
132
|
expect(response.length).to eql(1)
|
125
133
|
response = response[0]
|
126
134
|
|
@@ -134,7 +142,7 @@ describe Indico do
|
|
134
142
|
|
135
143
|
it 'should return no named entities when threshold is 1' do
|
136
144
|
config = { threshold: 1 }
|
137
|
-
response = Indico.
|
145
|
+
response = Indico.named_entities(['I want to move to New York City!'], config)
|
138
146
|
expect(response.length).to eql(1)
|
139
147
|
response = response[0]
|
140
148
|
expect(response.keys.length).to eql(0)
|
@@ -142,9 +150,9 @@ describe Indico do
|
|
142
150
|
|
143
151
|
it 'should tag face with correct facial expression' do
|
144
152
|
expected_keys = Set.new(%w(Angry Sad Neutral Surprise Fear Happy))
|
145
|
-
test_face =
|
153
|
+
test_face = File.dirname(__FILE__) + "/data/happy.png"
|
146
154
|
silent_warnings do
|
147
|
-
response = Indico.
|
155
|
+
response = Indico.fer([test_face, test_face], @config)
|
148
156
|
|
149
157
|
expect(Set.new(response[0].keys)).to eql(expected_keys)
|
150
158
|
expect(Set.new(response[1].keys)).to eql(expected_keys)
|
@@ -152,36 +160,46 @@ describe Indico do
|
|
152
160
|
end
|
153
161
|
|
154
162
|
it 'should tag face with correct facial features' do
|
155
|
-
test_face =
|
163
|
+
test_face = File.dirname(__FILE__) + "/data/happy.png"
|
156
164
|
silent_warnings do
|
157
|
-
response = Indico.
|
165
|
+
response = Indico.facial_features([test_face, test_face], @config)
|
158
166
|
expect(response[0].length).to eql(48)
|
159
167
|
expect(response[1].length).to eql(48)
|
160
168
|
end
|
161
169
|
end
|
162
170
|
|
163
171
|
it 'should tag image with correct image features' do
|
164
|
-
test_image =
|
172
|
+
test_image = File.dirname(__FILE__) + "/data/happy.png"
|
165
173
|
silent_warnings do
|
166
|
-
response = Indico.
|
174
|
+
response = Indico.image_features([test_image, test_image], @config)
|
167
175
|
expect(response[0].length).to eql(2048)
|
168
176
|
expect(response[1].length).to eql(2048)
|
169
177
|
end
|
170
178
|
end
|
171
179
|
|
180
|
+
it 'should locate a face in the image' do
|
181
|
+
test_image = File.dirname(__FILE__) + "/data/happy.png"
|
182
|
+
expected_keys = Set.new(%w(top_left_corner bottom_right_corner))
|
183
|
+
silent_warnings do
|
184
|
+
response = Indico.facial_localization([test_image, test_image], @config)
|
185
|
+
expect(Set.new(response[0][0].keys)).to eql(expected_keys)
|
186
|
+
expect(Set.new(response[1][0].keys)).to eql(expected_keys)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
172
190
|
it "should respond with all text apis called in batch" do
|
173
191
|
expected_keys = Set.new(TEXT_APIS)
|
174
|
-
response = Indico.
|
192
|
+
response = Indico.predict_text(["Worst movie ever."], TEXT_APIS)
|
175
193
|
|
176
194
|
expect(response.class).to eql(Hash)
|
177
195
|
expect(Set.new(response.keys)).to eql(expected_keys)
|
178
196
|
end
|
179
197
|
|
180
198
|
it "should respond with all image apis called in batch" do
|
181
|
-
test_image =
|
199
|
+
test_image = File.dirname(__FILE__) + "/data/happy.png"
|
182
200
|
expected_keys = Set.new(IMAGE_APIS)
|
183
201
|
silent_warnings do
|
184
|
-
response = Indico.
|
202
|
+
response = Indico.predict_image([test_image], IMAGE_APIS)
|
185
203
|
|
186
204
|
expect(response.class).to eql(Hash)
|
187
205
|
expect(Set.new(response.keys)).to eql(expected_keys)
|
@@ -189,10 +207,10 @@ describe Indico do
|
|
189
207
|
end
|
190
208
|
|
191
209
|
it "should respond with all image apis called on int array in batch" do
|
192
|
-
test_image =
|
210
|
+
test_image = File.dirname(__FILE__) + "/data/happy.png"
|
193
211
|
expected_keys = Set.new(IMAGE_APIS)
|
194
212
|
silent_warnings do
|
195
|
-
response = Indico.
|
213
|
+
response = Indico.predict_image([test_image], IMAGE_APIS)
|
196
214
|
|
197
215
|
expect(response.class).to eql(Hash)
|
198
216
|
expect(Set.new(response.keys)).to eql(expected_keys)
|
@@ -204,7 +222,7 @@ describe Indico do
|
|
204
222
|
# it "should accept image urls" do
|
205
223
|
# test_image = 'http://icons.iconarchive.com/icons/oxygen-icons.org/' +
|
206
224
|
# 'oxygen/48/Emotes-face-smile-icon.png'
|
207
|
-
# response = Indico.
|
225
|
+
# response = Indico.image_features([test_image, test_image],
|
208
226
|
# @config)
|
209
227
|
|
210
228
|
# expect(response[0].length).to eql(2048)
|
data/spec/indico_spec.rb
CHANGED
@@ -41,6 +41,13 @@ describe Indico do
|
|
41
41
|
expect(response < 0.5).to eql(true)
|
42
42
|
end
|
43
43
|
|
44
|
+
it 'should tag text with correct twitter engagment tags' do
|
45
|
+
response = Indico.twitter_engagement('#Breaking rt if you <3 pic.twitter.com @Startup')
|
46
|
+
|
47
|
+
expect(response < 1).to eql(true)
|
48
|
+
expect(response > 0).to eql(true)
|
49
|
+
end
|
50
|
+
|
44
51
|
it 'should tag text with correct language tags' do
|
45
52
|
expected_keys = Set.new([
|
46
53
|
'English',
|
@@ -107,6 +114,21 @@ describe Indico do
|
|
107
114
|
expect Set.new(response.keys).subset?(Set.new(expected_keys))
|
108
115
|
end
|
109
116
|
|
117
|
+
it 'should tag text with correct keywords for auto detect language' do
|
118
|
+
text = "La semaine suivante, il remporte sa premiere victoire, dans la descente de Val Gardena en Italie, près de cinq ans après la dernière victoire en Coupe du monde d'un Français dans cette discipline, avec le succès de Nicolas Burtin à Kvitfjell."
|
119
|
+
config = { "language" => "detect" }
|
120
|
+
response = Indico.keywords(text)
|
121
|
+
|
122
|
+
expect Set.new(response.keys).subset?(Set.new(text.gsub(/\s+/m, ' ').strip.split(" ")))
|
123
|
+
end
|
124
|
+
it 'should tag text with correct keywords for specified language' do
|
125
|
+
text = "La semaine suivante, il remporte sa premiere victoire, dans la descente de Val Gardena en Italie, près de cinq ans après la dernière victoire en Coupe du monde d'un Français dans cette discipline, avec le succès de Nicolas Burtin à Kvitfjell."
|
126
|
+
config = { "language" => "French" }
|
127
|
+
response = Indico.keywords(text)
|
128
|
+
|
129
|
+
expect Set.new(response.keys).subset?(Set.new(text.gsub(/\s+/m, ' ').strip.split(" ")))
|
130
|
+
end
|
131
|
+
|
110
132
|
it 'should return all named entities with category breakdowns' do
|
111
133
|
expected_keys = Set.new(%w(unknown organization location person))
|
112
134
|
response = Indico.named_entities('I want to move to New York City!')
|
@@ -120,14 +142,14 @@ describe Indico do
|
|
120
142
|
end
|
121
143
|
|
122
144
|
it 'should return no named entities when threshold is 1' do
|
123
|
-
config = { threshold
|
145
|
+
config = { "threshold" => 1 }
|
124
146
|
response = Indico.named_entities('I want to move to New York City!', config)
|
125
147
|
expect(response.keys.length).to eql(0)
|
126
148
|
end
|
127
149
|
|
128
150
|
it 'should tag face with correct facial expression' do
|
129
151
|
expected_keys = Set.new(%w(Angry Sad Neutral Surprise Fear Happy))
|
130
|
-
test_face
|
152
|
+
test_face= File.dirname(__FILE__) + "/data/happy.png"
|
131
153
|
silent_warnings do
|
132
154
|
response = Indico.fer(test_face)
|
133
155
|
expect(Set.new(response.keys)).to eql(expected_keys)
|
@@ -135,15 +157,21 @@ describe Indico do
|
|
135
157
|
end
|
136
158
|
|
137
159
|
it 'should tag face with correct facial features' do
|
138
|
-
test_face
|
160
|
+
test_face= File.dirname(__FILE__) + "/data/happy.png"
|
139
161
|
silent_warnings do
|
140
162
|
response = Indico.facial_features(test_face)
|
141
163
|
expect(response.length).to eql(48)
|
142
164
|
end
|
143
165
|
end
|
144
166
|
|
167
|
+
it 'should locate a face in the image' do
|
168
|
+
expected_keys = Set.new(%w(top_left_corner bottom_right_corner))
|
169
|
+
response = Indico.facial_localization(File.dirname(__FILE__) + "/data/happy.png")[0]
|
170
|
+
expect(Set.new(response.keys)).to eql(expected_keys)
|
171
|
+
end
|
172
|
+
|
145
173
|
it 'should tag noise as sfw' do
|
146
|
-
test_image
|
174
|
+
test_image= File.dirname(__FILE__) + "/data/happy.png"
|
147
175
|
silent_warnings do
|
148
176
|
response = Indico.content_filtering(test_image)
|
149
177
|
expect(response).to be < 0.5
|
@@ -151,7 +179,7 @@ describe Indico do
|
|
151
179
|
end
|
152
180
|
|
153
181
|
it 'should tag image with correct image features' do
|
154
|
-
test_image
|
182
|
+
test_image= File.dirname(__FILE__) + "/data/happy.png"
|
155
183
|
silent_warnings do
|
156
184
|
response = Indico.image_features(test_image)
|
157
185
|
expect(response.length).to eql(2048)
|
@@ -159,7 +187,7 @@ describe Indico do
|
|
159
187
|
end
|
160
188
|
|
161
189
|
it "should tag rgb image with correct image features" do
|
162
|
-
test_image =
|
190
|
+
test_image = File.open(File.dirname(__FILE__) + "/data/happy64.txt", 'rb') { |f| f.read }
|
163
191
|
silent_warnings do
|
164
192
|
response = Indico.image_features(test_image)
|
165
193
|
expect(response.length).to eql(2048)
|
@@ -199,7 +227,7 @@ describe Indico do
|
|
199
227
|
end
|
200
228
|
|
201
229
|
it "should respond with all image apis called" do
|
202
|
-
test_image =
|
230
|
+
test_image = File.open(File.dirname(__FILE__) + "/data/happy64.txt", 'rb') { |f| f.read }
|
203
231
|
expected_keys = Set.new(IMAGE_APIS)
|
204
232
|
silent_warnings do
|
205
233
|
response = Indico.predict_image(test_image, IMAGE_APIS)
|
@@ -210,7 +238,7 @@ describe Indico do
|
|
210
238
|
end
|
211
239
|
|
212
240
|
it "should respond with all image apis called on int array" do
|
213
|
-
test_image =
|
241
|
+
test_image = File.open(File.dirname(__FILE__) + "/data/happy64.txt", 'rb') { |f| f.read }
|
214
242
|
expected_keys = Set.new(IMAGE_APIS)
|
215
243
|
silent_warnings do
|
216
244
|
response = Indico.predict_image(test_image, IMAGE_APIS)
|
@@ -220,6 +248,14 @@ describe Indico do
|
|
220
248
|
end
|
221
249
|
end
|
222
250
|
|
251
|
+
it 'should properly resize an image with min_axis set' do
|
252
|
+
test_image = File.open(File.dirname(__FILE__) + "/data/happy64.txt", 'rb') { |f| f.read }
|
253
|
+
silent_warnings do
|
254
|
+
image = Indico.preprocess(test_image, 128, true)
|
255
|
+
image = ChunkyPNG::Image.from_data_url("data:image/png;base64," + image.gsub("data:image/png;base64," ,""))
|
256
|
+
expect(image.width).to eql(128)
|
257
|
+
end
|
258
|
+
end
|
223
259
|
|
224
260
|
# Uncomment when frontend updated to accept image urls
|
225
261
|
# it 'should accept image urls' do
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: indico
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Slater Victoroff
|
@@ -11,11 +12,12 @@ authors:
|
|
11
12
|
autorequire:
|
12
13
|
bindir: bin
|
13
14
|
cert_chain: []
|
14
|
-
date: 2015-07
|
15
|
+
date: 2015-08-07 00:00:00.000000000 Z
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
17
18
|
name: inifile
|
18
19
|
requirement: !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
19
21
|
requirements:
|
20
22
|
- - ~>
|
21
23
|
- !ruby/object:Gem::Version
|
@@ -23,6 +25,7 @@ dependencies:
|
|
23
25
|
type: :runtime
|
24
26
|
prerelease: false
|
25
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
26
29
|
requirements:
|
27
30
|
- - ~>
|
28
31
|
- !ruby/object:Gem::Version
|
@@ -30,6 +33,7 @@ dependencies:
|
|
30
33
|
- !ruby/object:Gem::Dependency
|
31
34
|
name: oily_png
|
32
35
|
requirement: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
33
37
|
requirements:
|
34
38
|
- - ~>
|
35
39
|
- !ruby/object:Gem::Version
|
@@ -37,6 +41,7 @@ dependencies:
|
|
37
41
|
type: :runtime
|
38
42
|
prerelease: false
|
39
43
|
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
40
45
|
requirements:
|
41
46
|
- - ~>
|
42
47
|
- !ruby/object:Gem::Version
|
@@ -44,6 +49,7 @@ dependencies:
|
|
44
49
|
- !ruby/object:Gem::Dependency
|
45
50
|
name: bundler
|
46
51
|
requirement: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
47
53
|
requirements:
|
48
54
|
- - ~>
|
49
55
|
- !ruby/object:Gem::Version
|
@@ -51,6 +57,7 @@ dependencies:
|
|
51
57
|
type: :development
|
52
58
|
prerelease: false
|
53
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
54
61
|
requirements:
|
55
62
|
- - ~>
|
56
63
|
- !ruby/object:Gem::Version
|
@@ -58,29 +65,33 @@ dependencies:
|
|
58
65
|
- !ruby/object:Gem::Dependency
|
59
66
|
name: rake
|
60
67
|
requirement: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
61
69
|
requirements:
|
62
|
-
- - '>='
|
70
|
+
- - ! '>='
|
63
71
|
- !ruby/object:Gem::Version
|
64
72
|
version: '0'
|
65
73
|
type: :development
|
66
74
|
prerelease: false
|
67
75
|
version_requirements: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
68
77
|
requirements:
|
69
|
-
- - '>='
|
78
|
+
- - ! '>='
|
70
79
|
- !ruby/object:Gem::Version
|
71
80
|
version: '0'
|
72
81
|
- !ruby/object:Gem::Dependency
|
73
82
|
name: rspec
|
74
83
|
requirement: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
75
85
|
requirements:
|
76
|
-
- - '>='
|
86
|
+
- - ! '>='
|
77
87
|
- !ruby/object:Gem::Version
|
78
88
|
version: '0'
|
79
89
|
type: :development
|
80
90
|
prerelease: false
|
81
91
|
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
82
93
|
requirements:
|
83
|
-
- - '>='
|
94
|
+
- - ! '>='
|
84
95
|
- !ruby/object:Gem::Version
|
85
96
|
version: '0'
|
86
97
|
description: A simple Ruby Wrapper for the indico set of APIs.
|
@@ -118,25 +129,26 @@ files:
|
|
118
129
|
homepage: https://github.com/IndicoDataSolutions/IndicoIo-ruby
|
119
130
|
licenses:
|
120
131
|
- MIT
|
121
|
-
metadata: {}
|
122
132
|
post_install_message:
|
123
133
|
rdoc_options: []
|
124
134
|
require_paths:
|
125
135
|
- lib
|
126
136
|
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
127
138
|
requirements:
|
128
|
-
- - '>='
|
139
|
+
- - ! '>='
|
129
140
|
- !ruby/object:Gem::Version
|
130
141
|
version: '0'
|
131
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
132
144
|
requirements:
|
133
|
-
- - '>='
|
145
|
+
- - ! '>='
|
134
146
|
- !ruby/object:Gem::Version
|
135
147
|
version: '0'
|
136
148
|
requirements: []
|
137
149
|
rubyforge_project:
|
138
|
-
rubygems_version:
|
150
|
+
rubygems_version: 1.8.23
|
139
151
|
signing_key:
|
140
|
-
specification_version:
|
152
|
+
specification_version: 3
|
141
153
|
summary: A simple Ruby Wrapper for the indico set of APIs.
|
142
154
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 5c9c674de4496664e06caa095548544c6c9a9ee5
|
4
|
-
data.tar.gz: dc041b9ee95a7179d8879d89f84e9951c06cbf92
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: d044d992744aa72502c645840eb7ec9c8848228e994cb71ab008715c265f206cd8af35b45b3636cf3cb2b6384d85f1b97f0c06a7f6adbf67259337b15ed4ff1e
|
7
|
-
data.tar.gz: 4e8f6f03198c4ceedc56c6fd72894e7a4679df19359bec18c7f8b0aae95289757c5dafcd7f3e84616c048d224ed8e1f110ad4ec3d2fe97f61e38556fb2c73e22
|