indico 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Indico
2
- VERSION = '0.7.1'
2
+ VERSION = '0.8.0'
3
3
  end
data/lib/indico.rb CHANGED
@@ -3,6 +3,7 @@ require 'indico/helper'
3
3
  require 'indico/image'
4
4
  require 'indico/multi'
5
5
  require 'indico/settings'
6
+ require 'indico/errors'
6
7
  require 'uri'
7
8
  require 'json'
8
9
  require 'net/https'
@@ -56,12 +57,23 @@ module Indico
56
57
  api_handler(text, 'language', config)
57
58
  end
58
59
 
60
+ def self.emotion(text, config = nil)
61
+ api_handler(text, 'emotion', config)
62
+ end
63
+
59
64
  def self.text_tags(text, config = nil)
60
65
  api_handler(text, 'texttags', config)
61
66
  end
62
67
 
63
68
  def self.keywords(text, config = nil)
69
+ unless !config or config.key?(:v) or config.key?(:version)
70
+ config[:version] = "2"
71
+ end
72
+ if config and config.key?(:language) and config[:language] != "english"
73
+ config[:version] = "1"
74
+ end
64
75
  api_handler(text, 'keywords', config)
76
+
65
77
  end
66
78
 
67
79
  def self.named_entities(test_text, config = nil)
@@ -137,9 +149,10 @@ module Indico
137
149
 
138
150
  class Collection
139
151
 
140
- def initialize(collection)
152
+ def initialize(collection, config = nil)
141
153
  if collection.kind_of?(String)
142
154
  @collection = collection
155
+ @domain = config.nil? ? nil : config["domain"]
143
156
  else
144
157
  raise TypeError, "Collection must be initialized with a String name"
145
158
  end
@@ -150,16 +163,17 @@ module Indico
150
163
  is_batch = data[0].kind_of?(Array)
151
164
  if is_batch
152
165
  x, y = data.transpose
153
- x = Indico::preprocess(x, 144, true)
166
+ x = Indico::preprocess(x, 512, true)
154
167
  data = x.zip(y)
155
168
  else
156
- data[0] = Indico::preprocess(data[0], 144, true)
169
+ data[0] = Indico::preprocess(data[0], 512, true)
157
170
  end
158
171
 
159
172
  if config.nil?
160
173
  config = Hash.new()
161
174
  end
162
175
  config[:collection] = @collection
176
+ config[:domain] = @domain || config["domain"]
163
177
  Indico.api_handler(data, 'custom', config, 'add_data')
164
178
  end
165
179
 
@@ -172,7 +186,14 @@ module Indico
172
186
  end
173
187
 
174
188
  def wait(interval = 1)
175
- while info()['status'] != "ready" do
189
+ while true do
190
+ status = info()['status']
191
+ if status == "ready"
192
+ break
193
+ elsif status != "training"
194
+ raise IndicoError, "Collection training ended with failure: " + status
195
+ break
196
+ end
176
197
  sleep(interval)
177
198
  end
178
199
  end
@@ -182,16 +203,17 @@ module Indico
182
203
  end
183
204
 
184
205
  def predict(data, config = nil)
185
- data = Indico::preprocess(data, 144, true)
206
+ data = Indico::preprocess(data, 512, true)
186
207
  if config.nil?
187
208
  config = Hash.new()
188
209
  end
189
210
  config[:collection] = @collection
211
+ config[:domain] = @domain || config["domain"]
190
212
  Indico.api_handler(data, 'custom', config, 'predict')
191
213
  end
192
214
 
193
215
  def remove_example(data, config = nil)
194
- data = Indico::preprocess(data, 144, true)
216
+ data = Indico::preprocess(data, 512, true)
195
217
  if config.nil?
196
218
  config = Hash.new()
197
219
  end
@@ -21,6 +21,15 @@ describe Indico do
21
21
  expect(Set.new(response[1].keys)).to eql(expected_keys)
22
22
  end
23
23
 
24
+ it 'should tag text with correct emotion tags' do
25
+ expected_keys = Set.new(%w(anger fear joy sadness surprise))
26
+ data = "I did it. I got into Grad School. Not just any program, but a GREAT program. :-)"
27
+
28
+ response = Indico.emotion([data, data])
29
+ expect(Set.new(response[0].keys)).to eql(expected_keys)
30
+ expect(Set.new(response[1].keys)).to eql(expected_keys)
31
+ end
32
+
24
33
  it 'should return personality values for text' do
25
34
  expected_keys = Set.new(%w(openness extraversion conscientiousness agreeableness))
26
35
 
data/spec/indico_spec.rb CHANGED
@@ -43,6 +43,14 @@ describe Indico do
43
43
  expect(Set.new(response.keys)).to eql(expected_keys)
44
44
  end
45
45
 
46
+ it 'should tag text with correct emotion tags' do
47
+ expected_keys = Set.new(%w(anger fear joy sadness surprise))
48
+ data = "I did it. I got into Grad School. Not just any program, but a GREAT program. :-)"
49
+
50
+ response = Indico.emotion(data)
51
+ expect(Set.new(response.keys)).to eql(expected_keys)
52
+ end
53
+
46
54
  it 'should tag text with correct sentiment tags' do
47
55
  response = Indico.sentiment('Worst movie ever.')
48
56
 
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.7.1
4
+ version: 0.8.0
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: 2016-02-11 00:00:00.000000000 Z
15
+ date: 2016-03-22 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: inifile