Module: Monkeylearn::Classifiers
- Extended by:
- Requests
- Defined in:
- lib/monkeylearn/classifiers.rb
Class Method Summary collapse
- .build_endpoint(*args) ⇒ Object
- .classify(model_id, data, options = {}) ⇒ Object
- .create(name, options = {}) ⇒ Object
- .delete(module_id) ⇒ Object
- .deploy(module_id) ⇒ Object
- .detail(module_id) ⇒ Object
- .edit(module_id, options = {}) ⇒ Object
- .list(options = {}) ⇒ Object
- .tags ⇒ Object
- .train(module_id) ⇒ Object
- .upload_data(module_id, data) ⇒ Object
- .validate_batch_size(batch_size) ⇒ Object
Methods included from Requests
get_connection, get_exception_class, raise_for_status, request, throttled?
Class Method Details
.build_endpoint(*args) ⇒ Object
19 20 21 |
# File 'lib/monkeylearn/classifiers.rb', line 19 def build_endpoint(*args) File.join('classifiers', *args) + '/' end |
.classify(model_id, data, options = {}) ⇒ Object
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, = {}) [:batch_size] ||= Monkeylearn::Defaults.default_batch_size batch_size = [: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 .key? :production_model sliced_data[:production_model] = [:production_model] end request(:post, endpoint, sliced_data) end return Monkeylearn::MultiResponse.new(responses) else body = {data: data} if .key? :production_model body[:production_model] = [:production_model] end return request(:post, endpoint, body) end end |
.create(name, options = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/monkeylearn/classifiers.rb', line 69 def create(name, = {}) data = { name: name, description: [:description], algorithm: [:algorithm], language: [:language], max_features: [:max_features], ngram_range: [:ngram_range], use_stemming: [:use_stemming], preprocess_numbers: [:preprocess_numbers], preprocess_social_media: [:preprocess_social_media], normalize_weights: [:normalize_weights], stopwords: [:stopwords], whitelist: [:whitelist], }.delete_if { |k,v| v.nil? } request(:post, build_endpoint, data) end |
.delete(module_id) ⇒ Object
123 124 125 |
# File 'lib/monkeylearn/classifiers.rb', line 123 def delete(module_id) request(:delete, build_endpoint(module_id)) end |
.deploy(module_id) ⇒ Object
109 110 111 |
# File 'lib/monkeylearn/classifiers.rb', line 109 def deploy(module_id) request(:post, build_endpoint(module_id, 'deploy')) end |
.detail(module_id) ⇒ Object
105 106 107 |
# File 'lib/monkeylearn/classifiers.rb', line 105 def detail(module_id) request(:get, build_endpoint(module_id)) end |
.edit(module_id, options = {}) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/monkeylearn/classifiers.rb', line 87 def edit(module_id, = {}) data = { name: [:name], description: [:description], algorithm: [:algorithm], language: [:language], max_features: [:max_features], ngram_range: [:ngram_range], use_stemming: [:use_stemming], preprocess_numbers: [:preprocess_numbers], preprocess_social_media: [:preprocess_social_media], normalize_weights: [:normalize_weights], stopwords: [:stopwords], whitelist: [:whitelist], }.delete_if { |k,v| v.nil? } request(:patch, build_endpoint(module_id), data) end |
.list(options = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/monkeylearn/classifiers.rb', line 57 def list( = {}) if .key?(:order_by) [:order_by] = validate_order_by_param([:order_by]) end query_params = { page: [:page], per_page: [:per_page], order_by: [:order_by] }.delete_if { |k,v| v.nil? } request(:get, build_endpoint, nil, query_params) end |
.tags ⇒ Object
15 16 17 |
# File 'lib/monkeylearn/classifiers.rb', line 15 def return Tags end |
.train(module_id) ⇒ Object
113 114 115 |
# File 'lib/monkeylearn/classifiers.rb', line 113 def train(module_id) request(:post, build_endpoint(module_id, 'train')) end |
.upload_data(module_id, data) ⇒ Object
117 118 119 120 121 |
# File 'lib/monkeylearn/classifiers.rb', line 117 def upload_data(module_id, data) endpoint = build_endpoint(module_id, 'data') request(:post, endpoint, {data: data}) end |
.validate_batch_size(batch_size) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/monkeylearn/classifiers.rb', line 23 def validate_batch_size(batch_size) max_size = Monkeylearn::Defaults.max_batch_size if batch_size > max_size raise MonkeylearnError, "The param batch_size is too big, max value is #{max_size}." end true end |