indico 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +6 -1
- data/lib/indico.rb +58 -34
- data/lib/indico/multi.rb +2 -1
- data/lib/indico/settings.rb +1 -1
- data/lib/indico/version.rb +1 -1
- data/spec/indico_batch_spec.rb +32 -0
- data/spec/indico_spec.rb +34 -1
- metadata +11 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c9c674de4496664e06caa095548544c6c9a9ee5
|
4
|
+
data.tar.gz: dc041b9ee95a7179d8879d89f84e9951c06cbf92
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d044d992744aa72502c645840eb7ec9c8848228e994cb71ab008715c265f206cd8af35b45b3636cf3cb2b6384d85f1b97f0c06a7f6adbf67259337b15ed4ff1e
|
7
|
+
data.tar.gz: 4e8f6f03198c4ceedc56c6fd72894e7a4679df19359bec18c7f8b0aae95289757c5dafcd7f3e84616c048d224ed8e1f110ad4ec3d2fe97f61e38556fb2c73e22
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ For API key registration and setup, checkout our [quickstart guide](http://docs.
|
|
24
24
|
|
25
25
|
Full Documentation
|
26
26
|
------------
|
27
|
-
Detailed documentation and further code examples are available at [indico.readme.io](http://indico.readme.io/v2.0/docs/ruby)
|
27
|
+
Detailed documentation, a full list of APIs, and further code examples are available at [indico.readme.io](http://indico.readme.io/v2.0/docs/ruby)
|
28
28
|
|
29
29
|
Examples
|
30
30
|
---------
|
@@ -50,6 +50,11 @@ Examples
|
|
50
50
|
|
51
51
|
=> { "food"=>0.3713687833244494, "cars"=>0.0037924017632370586, ...}
|
52
52
|
|
53
|
+
> Indico.keywords("Facebook blog posts about Android tech make better journalism than most news outlets.", {top_n: 3})
|
54
|
+
|
55
|
+
=> {"android"=>0.10602030910588661, "journalism"=>0.13466866170166855, "outlets"=>0.13930405357808642}
|
56
|
+
|
57
|
+
|
53
58
|
```
|
54
59
|
|
55
60
|
Batch API
|
data/lib/indico.rb
CHANGED
@@ -24,12 +24,12 @@ module Indico
|
|
24
24
|
config['cloud'] = cloud
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.political(
|
28
|
-
api_handler(
|
27
|
+
def self.political(text, config = nil)
|
28
|
+
api_handler(text, 'political', config)
|
29
29
|
end
|
30
30
|
|
31
|
-
def self.batch_political(
|
32
|
-
api_handler(
|
31
|
+
def self.batch_political(text, config = nil)
|
32
|
+
api_handler(text, 'political/batch', config)
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.posneg(*args)
|
@@ -40,60 +40,84 @@ module Indico
|
|
40
40
|
batch_sentiment(*args)
|
41
41
|
end
|
42
42
|
|
43
|
-
def self.sentiment(
|
44
|
-
api_handler(
|
43
|
+
def self.sentiment(text, config = nil)
|
44
|
+
api_handler(text, 'sentiment', config)
|
45
45
|
end
|
46
46
|
|
47
|
-
def self.batch_sentiment(
|
48
|
-
api_handler(
|
47
|
+
def self.batch_sentiment(text, config = nil)
|
48
|
+
api_handler(text, 'sentiment/batch', config)
|
49
49
|
end
|
50
50
|
|
51
|
-
def self.sentiment_hq(
|
52
|
-
api_handler(
|
51
|
+
def self.sentiment_hq(text, config = nil)
|
52
|
+
api_handler(text, 'sentimenthq', config)
|
53
53
|
end
|
54
54
|
|
55
|
-
def self.batch_sentiment_hq(
|
56
|
-
api_handler(
|
55
|
+
def self.batch_sentiment_hq(text, config = nil)
|
56
|
+
api_handler(text, 'sentimenthq/batch', config)
|
57
57
|
end
|
58
58
|
|
59
|
-
def self.language(
|
60
|
-
api_handler(
|
59
|
+
def self.language(text, config = nil)
|
60
|
+
api_handler(text, 'language', config)
|
61
61
|
end
|
62
62
|
|
63
|
-
def self.batch_language(
|
64
|
-
api_handler(
|
63
|
+
def self.batch_language(text, config = nil)
|
64
|
+
api_handler(text, 'language/batch', config)
|
65
65
|
end
|
66
66
|
|
67
|
-
def self.text_tags(
|
68
|
-
api_handler(
|
67
|
+
def self.text_tags(text, config = nil)
|
68
|
+
api_handler(text, 'texttags', config)
|
69
69
|
end
|
70
70
|
|
71
|
-
def self.batch_text_tags(
|
72
|
-
api_handler(
|
71
|
+
def self.batch_text_tags(text, config = nil)
|
72
|
+
api_handler(text, 'texttags/batch', config)
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.keywords(text, config = nil)
|
76
|
+
api_handler(text, 'keywords', config)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.batch_keywords(text, config = nil)
|
80
|
+
api_handler(text, 'keywords/batch', config)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.named_entities(test_text, config = nil)
|
84
|
+
api_handler(test_text, 'namedentities', config)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.batch_named_entities(test_text, config = nil)
|
88
|
+
api_handler(test_text, 'namedentities/batch', config)
|
73
89
|
end
|
74
90
|
|
75
91
|
def self.fer(test_image, config = nil)
|
76
92
|
api_handler(preprocess(test_image, 48, false), 'fer', config)
|
77
93
|
end
|
78
94
|
|
79
|
-
def self.batch_fer(
|
80
|
-
api_handler(preprocess(
|
95
|
+
def self.batch_fer(image, config = nil)
|
96
|
+
api_handler(preprocess(image, 48, true), 'fer/batch', config)
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.facial_features(image, config = nil)
|
100
|
+
api_handler(preprocess(image, 48, false), 'facialfeatures', config)
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.batch_facial_features(image, config = nil)
|
104
|
+
api_handler(preprocess(image, 48, true), 'facialfeatures/batch', config)
|
81
105
|
end
|
82
106
|
|
83
|
-
def self.
|
84
|
-
api_handler(preprocess(
|
107
|
+
def self.image_features(image, config = nil)
|
108
|
+
api_handler(preprocess(image, 64, false), 'imagefeatures', config)
|
85
109
|
end
|
86
110
|
|
87
|
-
def self.
|
88
|
-
api_handler(preprocess(
|
111
|
+
def self.batch_image_features(image, config = nil)
|
112
|
+
api_handler(preprocess(image, 64, true), 'imagefeatures/batch', config)
|
89
113
|
end
|
90
114
|
|
91
|
-
def self.
|
92
|
-
api_handler(preprocess(
|
115
|
+
def self.content_filtering(image, config = nil)
|
116
|
+
api_handler(preprocess(image, 128, false), 'contentfiltering', config)
|
93
117
|
end
|
94
118
|
|
95
|
-
def self.
|
96
|
-
api_handler(preprocess(
|
119
|
+
def self.batch_content_filtering(image, config = nil)
|
120
|
+
api_handler(preprocess(image, 128, true), 'contentfiltering/batch', config)
|
97
121
|
end
|
98
122
|
|
99
123
|
def self.predict_image(face, apis = IMAGE_APIS, config = nil)
|
@@ -102,9 +126,9 @@ module Indico
|
|
102
126
|
end
|
103
127
|
|
104
128
|
# FIXME - use settings TEXT_APIS when sentimenthq is released
|
105
|
-
def self.predict_text(
|
129
|
+
def self.predict_text(text, apis = ['political', 'sentiment', 'language', 'text_tags'], config = nil)
|
106
130
|
api_hash = {apis:apis}
|
107
|
-
multi(
|
131
|
+
multi(text, "text", apis, TEXT_APIS, config ? config.update(api_hash) : api_hash)
|
108
132
|
end
|
109
133
|
|
110
134
|
def self.batch_predict_image(face, apis, config = nil)
|
@@ -113,8 +137,8 @@ module Indico
|
|
113
137
|
end
|
114
138
|
|
115
139
|
# FIXME - use settings TEXT_APIS when sentimenthq is released
|
116
|
-
def self.batch_predict_text(
|
140
|
+
def self.batch_predict_text(text, apis = ['political', 'sentiment', 'language', 'text_tags'], config = nil)
|
117
141
|
api_hash = {apis:apis}
|
118
|
-
multi(
|
142
|
+
multi(text, "text", apis, TEXT_APIS, true, config ? config.update(api_hash) : api_hash)
|
119
143
|
end
|
120
144
|
end
|
data/lib/indico/multi.rb
CHANGED
@@ -9,7 +9,8 @@ module Indico
|
|
9
9
|
"text_tags" => "texttags",
|
10
10
|
"fer" => "fer",
|
11
11
|
"facial_features" => "facialfeatures",
|
12
|
-
"image_features" => "imagefeatures"
|
12
|
+
"image_features" => "imagefeatures",
|
13
|
+
"content_filtering" => "contentfiltering"
|
13
14
|
}
|
14
15
|
|
15
16
|
SERVER_TO_CLIENT = CLIENT_TO_SERVER.invert
|
data/lib/indico/settings.rb
CHANGED
@@ -7,7 +7,7 @@ HEADERS = { 'Content-Type' => 'application/json',
|
|
7
7
|
'version-number' => Indico::VERSION }
|
8
8
|
# APIS
|
9
9
|
TEXT_APIS = ["political", "sentiment", "sentiment_hq", "language", "text_tags"]
|
10
|
-
IMAGE_APIS = ["fer", "facial_features", "image_features"]
|
10
|
+
IMAGE_APIS = ["fer", "facial_features", "image_features", "content_filtering"]
|
11
11
|
|
12
12
|
module Indico
|
13
13
|
private
|
data/lib/indico/version.rb
CHANGED
data/spec/indico_batch_spec.rb
CHANGED
@@ -108,6 +108,38 @@ describe Indico do
|
|
108
108
|
expect Set.new(response[1].keys).subset?(Set.new(expected_keys))
|
109
109
|
end
|
110
110
|
|
111
|
+
it 'should tag text with correct keywords' do
|
112
|
+
expected_keys = Set.new(%w(people kill guns))
|
113
|
+
|
114
|
+
data = ['Guns don\'t kill people.', 'People kill people.']
|
115
|
+
response = Indico.batch_keywords(data, @config)
|
116
|
+
|
117
|
+
expect Set.new(response[0].keys).subset?(Set.new(expected_keys))
|
118
|
+
expect Set.new(response[1].keys).subset?(Set.new(expected_keys))
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should return all named entities with category breakdowns' do
|
122
|
+
expected_keys = Set.new(%w(unknown organization location person))
|
123
|
+
response = Indico.batch_named_entities(['I want to move to New York City!'])
|
124
|
+
expect(response.length).to eql(1)
|
125
|
+
response = response[0]
|
126
|
+
|
127
|
+
expect(response.keys.length > 0).to eql(true)
|
128
|
+
expect(response.values[0]['confidence']).to be >= 0.75
|
129
|
+
expect(Set.new(response.values[0]['categories'].keys)).to eql(expected_keys)
|
130
|
+
|
131
|
+
chance_sum = response.values[0]['categories'].values.inject{|sum,x| sum + x }
|
132
|
+
expect(chance_sum).to be > 0.9999
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should return no named entities when threshold is 1' do
|
136
|
+
config = { threshold: 1 }
|
137
|
+
response = Indico.batch_named_entities(['I want to move to New York City!'], config)
|
138
|
+
expect(response.length).to eql(1)
|
139
|
+
response = response[0]
|
140
|
+
expect(response.keys.length).to eql(0)
|
141
|
+
end
|
142
|
+
|
111
143
|
it 'should tag face with correct facial expression' do
|
112
144
|
expected_keys = Set.new(%w(Angry Sad Neutral Surprise Fear Happy))
|
113
145
|
test_face = Array.new(48) { Array.new(48) { rand(100) / 100.0 } }
|
data/spec/indico_spec.rb
CHANGED
@@ -37,7 +37,7 @@ describe Indico do
|
|
37
37
|
|
38
38
|
it 'should tag text with correct sentimenthq tags' do
|
39
39
|
response = Indico.sentiment_hq('Worst movie ever.')
|
40
|
-
|
40
|
+
|
41
41
|
expect(response < 0.5).to eql(true)
|
42
42
|
end
|
43
43
|
|
@@ -100,6 +100,31 @@ describe Indico do
|
|
100
100
|
expect Set.new(response.keys).subset?(Set.new(expected_keys))
|
101
101
|
end
|
102
102
|
|
103
|
+
it 'should tag text with correct keywords' do
|
104
|
+
expected_keys = Set.new(%w(guns kill people))
|
105
|
+
response = Indico.keywords('Guns don\'t kill people. People kill people.')
|
106
|
+
|
107
|
+
expect Set.new(response.keys).subset?(Set.new(expected_keys))
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should return all named entities with category breakdowns' do
|
111
|
+
expected_keys = Set.new(%w(unknown organization location person))
|
112
|
+
response = Indico.named_entities('I want to move to New York City!')
|
113
|
+
|
114
|
+
expect(response.keys.length > 0).to eql(true)
|
115
|
+
expect(response.values[0]['confidence']).to be >= 0.75
|
116
|
+
expect(Set.new(response.values[0]['categories'].keys)).to eql(expected_keys)
|
117
|
+
|
118
|
+
chance_sum = response.values[0]['categories'].values.inject{|sum,x| sum + x }
|
119
|
+
expect(chance_sum).to be > 0.9999
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should return no named entities when threshold is 1' do
|
123
|
+
config = { threshold: 1 }
|
124
|
+
response = Indico.named_entities('I want to move to New York City!', config)
|
125
|
+
expect(response.keys.length).to eql(0)
|
126
|
+
end
|
127
|
+
|
103
128
|
it 'should tag face with correct facial expression' do
|
104
129
|
expected_keys = Set.new(%w(Angry Sad Neutral Surprise Fear Happy))
|
105
130
|
test_face = Array.new(48) { Array.new(48) { rand(100) / 100.0 } }
|
@@ -117,6 +142,14 @@ describe Indico do
|
|
117
142
|
end
|
118
143
|
end
|
119
144
|
|
145
|
+
it 'should tag noise as sfw' do
|
146
|
+
test_image = Array.new(48) { Array.new(48) { rand(100) / 100.0 } }
|
147
|
+
silent_warnings do
|
148
|
+
response = Indico.content_filtering(test_image)
|
149
|
+
expect(response).to be < 0.5
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
120
153
|
it 'should tag image with correct image features' do
|
121
154
|
test_image = Array.new(48) { Array.new(48) { rand(100) / 100.0 } }
|
122
155
|
silent_warnings do
|
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
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Slater Victoroff
|
@@ -12,12 +11,11 @@ authors:
|
|
12
11
|
autorequire:
|
13
12
|
bindir: bin
|
14
13
|
cert_chain: []
|
15
|
-
date: 2015-07-
|
14
|
+
date: 2015-07-10 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
|
@@ -25,7 +23,6 @@ dependencies:
|
|
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
|
@@ -33,7 +30,6 @@ dependencies:
|
|
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
|
@@ -41,7 +37,6 @@ dependencies:
|
|
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
|
@@ -49,7 +44,6 @@ dependencies:
|
|
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
|
@@ -57,7 +51,6 @@ dependencies:
|
|
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
|
@@ -65,33 +58,29 @@ dependencies:
|
|
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.
|
@@ -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:
|
138
|
+
rubygems_version: 2.0.14
|
151
139
|
signing_key:
|
152
|
-
specification_version:
|
140
|
+
specification_version: 4
|
153
141
|
summary: A simple Ruby Wrapper for the indico set of APIs.
|
154
142
|
test_files: []
|