indico 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/indico/helper.rb CHANGED
@@ -21,12 +21,20 @@ module Indico
21
21
  unless config.nil?
22
22
  server = config[:cloud]
23
23
  api_key = config[:api_key]
24
- apis = config["apis"]
24
+ apis = config[:apis]
25
25
  d = d.merge(config)
26
26
  end
27
27
 
28
- url = url_join((server or Indico.config['cloud']), api) +
29
- (apis ? "?apis=" + apis.join(",") : "")
28
+ server = server or Indico.config['cloud']
29
+
30
+ #FIXME Remove when sentimenthq is publicly released
31
+ if !server
32
+ if api == 'sentimenthq' || (apis && apis.include?('sentimenthq'))
33
+ raise IndicoError, 'The high quality sentiment API is currently in private beta.'
34
+ end
35
+ end
36
+
37
+ url = url_join(server, api) + (apis ? "?apis=" + apis.join(",") : "")
30
38
 
31
39
  response = make_request(url, JSON.dump(d),
32
40
  add_api_key_to_header((api_key or Indico.config['auth'])))
data/lib/indico/multi.rb CHANGED
@@ -4,6 +4,7 @@ module Indico
4
4
  CLIENT_TO_SERVER = {
5
5
  "political" => "political",
6
6
  "sentiment" => "sentiment",
7
+ "sentiment_hq" => "sentimenthq",
7
8
  "language" => "language",
8
9
  "text_tags" => "texttags",
9
10
  "fer" => "fer",
@@ -26,7 +27,7 @@ module Indico
26
27
  config = {}
27
28
  end
28
29
 
29
- config["apis"] = converted_apis
30
+ config[:apis] = converted_apis
30
31
  response = api_handler(data, batch ? "apis/batch" : "apis", config)
31
32
  results = handle_multi(response)
32
33
 
@@ -39,7 +40,7 @@ module Indico
39
40
  if value.is_a?(Hash) && value.has_key?("results")
40
41
  converted_results[SERVER_TO_CLIENT[key]] = value["results"]
41
42
  else
42
- raise IndicoError, 'unexpected result from ' + key + '\n\t' + value.fetch("error", "")
43
+ raise IndicoError, 'unexpected result from ' + key + '. ' + value.fetch("error", "")
43
44
  end
44
45
  end
45
46
  converted_results
@@ -6,7 +6,7 @@ HEADERS = { 'Content-Type' => 'application/json',
6
6
  'client-lib' => 'ruby',
7
7
  'version-number' => Indico::VERSION }
8
8
  # APIS
9
- TEXT_APIS = ["political", "sentiment", "language", "text_tags"]
9
+ TEXT_APIS = ["political", "sentiment", "sentiment_hq", "language", "text_tags"]
10
10
  IMAGE_APIS = ["fer", "facial_features", "image_features"]
11
11
 
12
12
  module Indico
@@ -1,3 +1,3 @@
1
1
  module Indico
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
data/lib/indico.rb CHANGED
@@ -32,20 +32,28 @@ module Indico
32
32
  api_handler(test_text, 'political/batch', config)
33
33
  end
34
34
 
35
- def self.posneg(test_text, config = nil)
35
+ def self.posneg(*args)
36
+ sentiment(*args)
37
+ end
38
+
39
+ def self.batch_posneg(*args)
40
+ batch_sentiment(*args)
41
+ end
42
+
43
+ def self.sentiment(test_text, config = nil)
36
44
  api_handler(test_text, 'sentiment', config)
37
45
  end
38
46
 
39
- def self.batch_posneg(test_text, config = nil)
47
+ def self.batch_sentiment(test_text, config = nil)
40
48
  api_handler(test_text, 'sentiment/batch', config)
41
49
  end
42
50
 
43
- def self.sentiment(*args)
44
- posneg(*args)
51
+ def self.sentiment_hq(test_text, config = nil)
52
+ api_handler(test_text, 'sentimenthq', config)
45
53
  end
46
54
 
47
- def self.batch_sentiment(*args)
48
- batch_posneg(*args)
55
+ def self.batch_sentiment_hq(test_text, config = nil)
56
+ api_handler(test_text, 'sentimenthq/batch', config)
49
57
  end
50
58
 
51
59
  def self.language(test_text, config = nil)
@@ -89,22 +97,24 @@ module Indico
89
97
  end
90
98
 
91
99
  def self.predict_image(face, apis = IMAGE_APIS, config = nil)
92
- api_hash = {"apis" => apis}
100
+ api_hash = {apis:apis}
93
101
  multi(preprocess(face, 48, false), "image", apis, IMAGE_APIS, config ? config.update(api_hash) : api_hash)
94
102
  end
95
103
 
96
- def self.predict_text(test_text, apis = TEXT_APIS, config = nil)
97
- api_hash = {"apis" => apis}
104
+ # FIXME - use settings TEXT_APIS when sentimenthq is released
105
+ def self.predict_text(test_text, apis = ['political', 'sentiment', 'language', 'text_tags'], config = nil)
106
+ api_hash = {apis:apis}
98
107
  multi(test_text, "text", apis, TEXT_APIS, config ? config.update(api_hash) : api_hash)
99
108
  end
100
109
 
101
110
  def self.batch_predict_image(face, apis, config = nil)
102
- api_hash = {"apis" => apis}
111
+ api_hash = {apis:apis}
103
112
  multi(preprocess(face, 48, true), "image", apis, IMAGE_APIS, true, config ? config.update(api_hash) : api_hash)
104
113
  end
105
114
 
106
- def self.batch_predict_text(test_text, apis, config = nil)
107
- api_hash = {"apis" => apis}
115
+ # FIXME - use settings TEXT_APIS when sentimenthq is released
116
+ def self.batch_predict_text(test_text, apis = ['political', 'sentiment', 'language', 'text_tags'], config = nil)
117
+ api_hash = {apis:apis}
108
118
  multi(test_text, "text", apis, TEXT_APIS, true, config ? config.update(api_hash) : api_hash)
109
119
  end
110
120
  end
@@ -7,6 +7,8 @@ describe Indico do
7
7
  private_cloud = 'indico-test'
8
8
  @config_private_cloud = { api_key: api_key, cloud: private_cloud}
9
9
  @config = { api_key: api_key}
10
+ # FIXME Remove when sentiment_hq is released
11
+ TEXT_APIS.delete("sentiment_hq")
10
12
  end
11
13
 
12
14
  it 'should tag text with correct political tags' do
@@ -36,6 +38,11 @@ describe Indico do
36
38
  expect(response[0] < 0.5).to eql(true)
37
39
  end
38
40
 
41
+ # it 'should tag text with correct sentiment_hq tags' do
42
+ # response = Indico.batch_sentiment_hq(['Worst movie ever.'], @config)
43
+ # expect(response[0] < 0.5).to eql(true)
44
+ # end
45
+
39
46
  it 'should tag text with correct language tags' do
40
47
  expected_keys = Set.new([
41
48
  'English',
data/spec/indico_spec.rb CHANGED
@@ -6,6 +6,8 @@ describe Indico do
6
6
  before do
7
7
  api_key = ENV['INDICO_API_KEY']
8
8
  private_cloud = 'indico-test'
9
+ # FIXME - REMOVE WHEN SENTIMENTHQ RELEASE
10
+ TEXT_APIS.delete("sentiment_hq")
9
11
  @config = { api_key: api_key, cloud: private_cloud}
10
12
  end
11
13
 
@@ -33,6 +35,12 @@ describe Indico do
33
35
  expect(response < 0.5).to eql(true)
34
36
  end
35
37
 
38
+ # it 'should tag text with correct sentimenthq tags' do
39
+ # response = Indico.sentiment_hq('Worst movie ever.')
40
+ #
41
+ # expect(response < 0.5).to eql(true)
42
+ # end
43
+
36
44
  it 'should tag text with correct language tags' do
37
45
  expected_keys = Set.new([
38
46
  'English',
@@ -151,7 +159,7 @@ describe Indico do
151
159
 
152
160
  it "should respond with all text apis called by default" do
153
161
  expected_keys = Set.new(TEXT_APIS)
154
- response = Indico.predict_text("Worst movie ever.")
162
+ response = Indico.predict_text("Worst movie ever.", TEXT_APIS)
155
163
 
156
164
  expect(response.class).to eql(Hash)
157
165
  expect(Set.new(response.keys)).to eql(expected_keys)
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.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-06-11 00:00:00.000000000 Z
15
+ date: 2015-06-12 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: inifile