31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/monkeylearn/classifiers.rb', line 31
def classify(model_id, data, options = {})
options[:batch_size] ||= Monkeylearn::Defaults.default_batch_size
batch_size = options[:batch_size]
validate_batch_size batch_size
endpoint = build_endpoint(model_id, 'classify')
if Monkeylearn.auto_batch
responses = (0...data.length).step(batch_size).collect do |start_idx|
sliced_data = { data: data[start_idx, batch_size] }
if options.key? :production_model
sliced_data[:production_model] = options[:production_model]
end
request(:post, endpoint, sliced_data)
end
return Monkeylearn::MultiResponse.new(responses)
else
body = {data: data}
if options.key? :production_model
body[:production_model] = options[:production_model]
end
return request(:post, endpoint, body)
end
end
|