monkeylearn 0.2.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +535 -65
- data/lib/monkeylearn.rb +0 -1
- data/lib/monkeylearn/classifiers.rb +79 -58
- data/lib/monkeylearn/configurable.rb +7 -10
- data/lib/monkeylearn/defaults.rb +12 -12
- data/lib/monkeylearn/exceptions.rb +74 -0
- data/lib/monkeylearn/extractors.rb +24 -9
- data/lib/monkeylearn/requests.rb +82 -19
- data/lib/monkeylearn/response.rb +20 -7
- data/monkeylearn.gemspec +3 -2
- metadata +11 -12
- data/lib/monkeylearn/pipelines.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5addabb40cdb543517a969991894fbf1a833c933
|
4
|
+
data.tar.gz: b7980f04ec4011551fe6a789325207546520a861
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e3fcfba44c7c887a838ea0ea63f6494b0addc235d5299234863b9dd7d690c09a37c2259f37cbe3c91a016233b3c197d2c51697bbe797c068466b0e12f00b21d
|
7
|
+
data.tar.gz: 53407844c2ddb14fe783128072a3365be769d76372bff931ca32979e5889630ef944046c1fac04c3ae0558bf679ea154e27c593804b8080b08d63798b0f246b8
|
data/README.md
CHANGED
@@ -3,20 +3,26 @@
|
|
3
3
|
Official Ruby client for the MonkeyLearn API. Build and consume machine learning models for language processing from your Ruby apps.
|
4
4
|
|
5
5
|
Installation
|
6
|
-
|
6
|
+
---------------
|
7
7
|
|
8
8
|
Install with rubygems:
|
9
9
|
|
10
|
-
|
10
|
+
```bash
|
11
|
+
$ gem install monkeylearn
|
12
|
+
```
|
11
13
|
|
12
14
|
Or add this line to your Gemfile
|
13
15
|
|
14
|
-
|
16
|
+
```bash
|
17
|
+
$ gem "monkeylearn", "~> 3"
|
18
|
+
```
|
19
|
+
|
20
|
+
Usage
|
21
|
+
------
|
15
22
|
|
16
|
-
|
17
|
-
-----------
|
23
|
+
First, require and configure the lib:
|
18
24
|
|
19
|
-
|
25
|
+
Before making requests to the API, you need to set your [account API Key](https://app.monkeylearn.com/main/my-account/tab/api-keys/):
|
20
26
|
|
21
27
|
```ruby
|
22
28
|
require 'monkeylearn'
|
@@ -27,119 +33,583 @@ Monkeylearn.configure do |c|
|
|
27
33
|
end
|
28
34
|
```
|
29
35
|
|
30
|
-
|
36
|
+
|
37
|
+
### Requests
|
38
|
+
|
39
|
+
From the Monkeylearn module, you can call any endpoint (check the [available endpoints](#available-endpoints) below). For example, you can [classify](#classify) a list of texts using the public [Sentiment analysis classifier](https://app.monkeylearn.com/main/classifiers/cl_oJNMkt2V/):
|
40
|
+
|
31
41
|
|
32
42
|
```ruby
|
33
|
-
|
34
|
-
|
35
|
-
|
43
|
+
classifier_model_id='cl_Jx8qzYJh'
|
44
|
+
data = [
|
45
|
+
'Great hotel with excellent location',
|
46
|
+
'This is the worst hotel ever.'
|
47
|
+
]
|
48
|
+
|
49
|
+
response = Monkeylearn.classifiers.classify(classifier_model_id, data)
|
36
50
|
```
|
37
51
|
|
38
|
-
|
52
|
+
### Responses
|
53
|
+
|
54
|
+
The response object returned by every endpoint call is a `MonkeylearnResponse` object. The `body` attribute has the parsed response from the API:
|
39
55
|
|
40
56
|
```ruby
|
41
|
-
|
42
|
-
|
43
|
-
# =>
|
57
|
+
puts response.body
|
58
|
+
# => [
|
59
|
+
# => {
|
60
|
+
# => "text" => "Great hotel with excellent location",
|
61
|
+
# => "external_id" => nil,
|
62
|
+
# => "error" => false,
|
63
|
+
# => "classifications" => [
|
64
|
+
# => {
|
65
|
+
# => "tag_name" => "Positive",
|
66
|
+
# => "tag_id" => 1994,
|
67
|
+
# => "confidence" => 0.922,
|
68
|
+
# => }
|
69
|
+
# => ]
|
70
|
+
# => },
|
71
|
+
# => {
|
72
|
+
# => "text" => "This is the worst hotel ever.",
|
73
|
+
# => "external_id" => nil,
|
74
|
+
# => "error" => false,
|
75
|
+
# => "classifications" => [
|
76
|
+
# => {
|
77
|
+
# => "tag_name" => "Negative",
|
78
|
+
# => "tag_id" => 1941,
|
79
|
+
# => "confidence" => 0.911,
|
80
|
+
# => }
|
81
|
+
# => ]
|
82
|
+
# => }
|
83
|
+
# => ]
|
44
84
|
```
|
45
85
|
|
46
|
-
|
86
|
+
You can also access other attributes in the response object to get information about the queries used or available:
|
47
87
|
|
48
88
|
```ruby
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# =>
|
89
|
+
puts response.plan_queries_allowed
|
90
|
+
# => 300
|
91
|
+
|
92
|
+
puts response.plan_queries_remaining
|
93
|
+
# => 240
|
94
|
+
|
95
|
+
puts response.request_queries_used
|
96
|
+
# => 2
|
57
97
|
```
|
58
98
|
|
59
|
-
|
60
|
-
-----------------------------
|
99
|
+
### Errors
|
61
100
|
|
62
|
-
|
101
|
+
Endpoint calls may raise exceptions. Here is an example on how to handle them:
|
63
102
|
|
64
103
|
```ruby
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
104
|
+
begin
|
105
|
+
response = Monkeylearn.classifiers.classify("[MODEL_ID]", ["My text"])
|
106
|
+
rescue PlanQueryLimitError => d
|
107
|
+
puts "#{d.error_code}: #{d.detail}"
|
108
|
+
end
|
69
109
|
```
|
70
110
|
|
71
|
-
|
111
|
+
Available exceptions:
|
112
|
+
|
113
|
+
| class | Description |
|
114
|
+
|-----------------------------|-------------|
|
115
|
+
| `MonkeylearnError` | Base class for each exception below. |
|
116
|
+
| `RequestParamsError` | An invalid parameter was sent. Check the exception message or response object for more information. |
|
117
|
+
| `AuthenticationError` | Authentication failed, usually because an invalid token was provided. Check the exception message. More about [Authentication](https://monkeylearn.com/api/v3/#authentication). |
|
118
|
+
| `ForbiddenError` | You don't have permissions to perform the action on the given resource. |
|
119
|
+
| `ModelLimitError` | You have reached the custom model limit for your plan. |
|
120
|
+
| `ModelNotFound` | The model does not exist. Check the `model_id`. |
|
121
|
+
| `TagNotFound` | The tag does not exist. Check the `tag_id` parameter. |
|
122
|
+
| `PlanQueryLimitError` | You have reached the monthly query limit for your plan. Consider upgrading your plan. More about [Plan query limits](https://monkeylearn.com/api/v3/#query-limits). |
|
123
|
+
| `PlanRateLimitError` | You have sent too many requests in the last minute. Check the exception details. More about [Plan rate limit](https://monkeylearn.com/api/v3/#plan-rate-limit). |
|
124
|
+
| `ConcurrencyRateLimitError` | You have sent too many requests in the last second. Check the exception details. More about [Concurrency rate limit](https://monkeylearn.com/api/v3/#concurrecy-rate-limit). |
|
125
|
+
| `ModuleStateError` | The state of the module is invalid. Check the exception details. |
|
126
|
+
|
127
|
+
### Handling batching and throttled responses manually
|
128
|
+
|
129
|
+
[Classify](#classify) and [Extract](#extract) endpoints may require more than one request to the MonkeyLearn API in order to process every text in the `data` parameter. If the `auto_batch` config is `true` (which is the default value) you don't have to keep the `data` length below the max allowed value (200), you can just pass the full list and the library will handle the bactching making multiple requests if necessary.
|
130
|
+
|
131
|
+
If you want to handle this yourself you can set `auto_batch` to `false` and slice the data yourself:
|
72
132
|
|
73
133
|
```ruby
|
74
|
-
|
75
|
-
|
134
|
+
require 'monkeylearn'
|
135
|
+
|
136
|
+
Monkeylearn.configure do |c|
|
137
|
+
c.token = 'INSERT_YOUR_API_TOKEN_HERE'
|
138
|
+
c.auto_batch = false
|
139
|
+
end
|
140
|
+
|
141
|
+
data = ['Text to classify'] * 300
|
142
|
+
batch_size = 200
|
143
|
+
model_id = '[MODULE_ID]'
|
144
|
+
|
145
|
+
responses = (0...data.length).step(batch_size).collect do |start_idx|
|
146
|
+
sliced_data = data[start_idx, batch_size]
|
147
|
+
Monkeylearn.classifiers.classify(model_id, sliced_data, batch_size: batch_size)
|
148
|
+
end
|
149
|
+
|
150
|
+
multi_response = Monkeylearn::MultiResponse.new(responses)
|
151
|
+
|
152
|
+
puts multi_response.body
|
76
153
|
```
|
77
154
|
|
78
|
-
|
155
|
+
Also, any API calls might be throttled (see [Rate limiting](https://monkeylearn.com/api/v3/#rate-limiting)). If the `retry_if_throttled` config is `true` (which is the default value) any throttled request will be retried after waiting (`sleep`) the required time.
|
156
|
+
|
157
|
+
You can control this manually if you need to:
|
79
158
|
|
80
159
|
```ruby
|
81
|
-
|
82
|
-
positive_category_id = r.result['result']['category']['id']
|
160
|
+
require 'monkeylearn'
|
83
161
|
|
84
|
-
|
85
|
-
|
162
|
+
Monkeylearn.configure do |c|
|
163
|
+
c.token = 'INSERT_YOUR_API_TOKEN_HERE'
|
164
|
+
c.auto_batch = false
|
165
|
+
c.retry_if_throttled = false
|
166
|
+
end
|
167
|
+
|
168
|
+
data = ['Text to classify'] * 300
|
169
|
+
batch_size = 200
|
170
|
+
model_id = '[MODULE_ID]'
|
171
|
+
|
172
|
+
responses = (0...data.length).step(batch_size).collect do |start_idx|
|
173
|
+
sliced_data = data[start_idx, batch_size]
|
174
|
+
throttled = true
|
175
|
+
while throttled
|
176
|
+
begin
|
177
|
+
response = Monkeylearn.classifiers.classify(model_id, sliced_data, batch_size: batch_size)
|
178
|
+
throttled = false
|
179
|
+
rescue ConcurrencyRateLimitError
|
180
|
+
sleep 2
|
181
|
+
rescue PlanRateLimitError => e
|
182
|
+
match = /([\d]+) seconds/.match(e.detail)
|
183
|
+
seconds = if match then match[1].to_i else 60 end
|
184
|
+
sleep seconds
|
185
|
+
end
|
186
|
+
end
|
187
|
+
response
|
188
|
+
end
|
189
|
+
|
190
|
+
multi_response = Monkeylearn::MultiResponse.new(responses)
|
191
|
+
|
192
|
+
puts multi_response.body
|
86
193
|
```
|
87
194
|
|
88
|
-
|
195
|
+
This way you'll be able to control every request that is sent to the MonkeyLearn API.
|
196
|
+
|
197
|
+
Available endpoints
|
198
|
+
------------------------
|
199
|
+
|
200
|
+
The following are all the endpoints of the API. For more information about each endpoint, check out the [API documentation](https://monkeylearn.com/api/v3/).
|
201
|
+
|
202
|
+
### Classifiers
|
203
|
+
|
204
|
+
#### [Classify](https://monkeylearn.com/api/v3/?shell#classify)
|
205
|
+
|
89
206
|
|
90
207
|
```ruby
|
91
|
-
|
92
|
-
['Nice beatiful', positive_category_id],
|
93
|
-
['awesome excelent', positive_category_id],
|
94
|
-
['Awful bad', negative_category_id],
|
95
|
-
['sad pale', negative_category_id],
|
96
|
-
['happy sad both multilabel', [positive_category_id, negative_category_id]]
|
97
|
-
]
|
98
|
-
r = Monkeylearn.classifiers.upload_samples(classifier_id, samples)
|
208
|
+
Monkeylearn.classifiers.classify(model_id, data, options = {})
|
99
209
|
```
|
100
210
|
|
101
|
-
|
211
|
+
Parameters:
|
212
|
+
|
213
|
+
| Parameter |Type | Description |
|
214
|
+
|--------------------|-------------------|-----------------------------------------------------------|
|
215
|
+
|*model_id* |`String` |Classifier ID. It always starts with `'cl'`, for example `'cl_oJNMkt2V'`. |
|
216
|
+
|*data* |`Array[String or Hash]`|A list of up to 200 data elements to classify. Each element must be a *String* with the text or a *Hash* with the required `text` key and the text as the value. You can provide an optional `external_id` key with a string that will be included in the response. |
|
217
|
+
|*options* |`Hash` | Optional parameters, see below. The hash always expects symbols as keys.
|
218
|
+
|
219
|
+
Optional parameters:
|
220
|
+
|
221
|
+
| Parameter |Type |Default | Description |
|
222
|
+
|--------------------|-------------------|----------------------|-----------------------------------------------------------|
|
223
|
+
|*production_model* |`Boolean` | `False` | Indicates if the classifications are performed by the production model. Only use this parameter with *custom models* (not with the public ones). Note that you first need to deploy your model to production either from the UI model settings or by using the [Classifier deploy endpoint](#deploy). |
|
224
|
+
|*batch_size* |`Integer` | `200` | Max amount of texts each request will send to Monkeylearn. A number from 1 to 200. |
|
225
|
+
|
226
|
+
|
227
|
+
Example:
|
102
228
|
|
103
229
|
```ruby
|
104
|
-
|
230
|
+
data = ["First text", {text: "Second text", external_id: "2"}]
|
231
|
+
response = Monkeylearn.classifiers.classify("[MODEL_ID]", data)
|
105
232
|
```
|
106
233
|
|
107
|
-
|
234
|
+
<br>
|
235
|
+
|
236
|
+
#### [Classifier detail](https://monkeylearn.com/api/v3/?shell#classifier-detail)
|
237
|
+
|
108
238
|
|
109
239
|
```ruby
|
110
|
-
|
111
|
-
r.result
|
112
|
-
# => [[{"probability"=>0.998, "label"=>"Positive"}]]
|
240
|
+
Monkeylearn.classifiers.detail(model_id)
|
113
241
|
```
|
114
242
|
|
115
|
-
|
243
|
+
Parameters:
|
244
|
+
|
245
|
+
| Parameter |Type | Description |
|
246
|
+
|--------------------|-------------------|-----------------------------------------------------------|
|
247
|
+
|*model_id* |`String` |Classifier ID. It always starts with `'cl'`, for example, `'cl_oJNMkt2V'`. |
|
248
|
+
|
249
|
+
Example:
|
116
250
|
|
117
251
|
```ruby
|
118
|
-
Monkeylearn.classifiers.
|
252
|
+
response = Monkeylearn.classifiers.detail("[MODEL_ID]")
|
119
253
|
```
|
120
254
|
|
121
|
-
|
255
|
+
<br>
|
256
|
+
|
257
|
+
#### [Create Classifier](https://monkeylearn.com/api/v3/?shell#create-classifier)
|
258
|
+
|
122
259
|
|
123
260
|
```ruby
|
124
|
-
|
125
|
-
r.result
|
126
|
-
# => [[{"probability"=>0.998, "label"=>"Positive"}]]
|
261
|
+
Monkeylearn.classifiers.create(name, options = {})
|
127
262
|
```
|
128
263
|
|
129
|
-
|
264
|
+
Parameters:
|
265
|
+
|
266
|
+
Parameter | Type | Description
|
267
|
+
----------|----------|----------------------------
|
268
|
+
name | `String` | The name of the model.
|
269
|
+
options | `Hash` | Optional parameters, see below. The hash always expects symbols as keys.
|
270
|
+
|
271
|
+
Optional parameters:
|
272
|
+
|
273
|
+
| Parameter |Type |Default | Description |
|
274
|
+
|--------------------|-------------------|----------------------|-----------------------------------------------------------|
|
275
|
+
description | `String` | `''` | The description of the model.
|
276
|
+
algorithm | `String` | `'nb'` | The [algorithm](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-changing-the-algorithm) used when training the model. It can either be "nb" or "svm".
|
277
|
+
language | `String` | `'en'` | The [language](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-language) of the model. Full list of [supported languages](https://monkeylearn.com/api/v3/#classifier-detail).
|
278
|
+
max_features | `Integer` | `10000` | The [maximum number of features](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-max-features) used when training the model. Between 10 and 100000.
|
279
|
+
ngram_range | `Array` | `[1,1]` | Indicates which [n-gram range](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-n-gram-range) is used when training the model. It's a list of two numbers between 1 and 3. They indicate the minimum and the maximum n for the n-grams used, respectively.
|
280
|
+
use_stemming | `Boolean`| `true`| Indicates whether [stemming](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-stemming) is used when training the model.
|
281
|
+
preprocess_numbers | `Boolean` | `true` | Indicates whether [number preprocessing](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-preprocess-numbers) is done when training the model.
|
282
|
+
preprocess_social_media | `Boolean` | `false` | Indicates whether [preprocessing of social media](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-social-media-preprocessing-and-regular-expressions) is done when training the model.
|
283
|
+
normalize_weights | `Boolean` | `true` | Indicates whether [weights will be normalized](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-normalize-weights) when training the model.
|
284
|
+
stopwords | `Boolean or Array` | `true` | The list of [stopwords](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-filter-stopwords) used when training the model. Use *false* for no stopwords, *true* for the default stopwords, or an array of strings for custom stopwords.
|
285
|
+
whitelist | `Array` | `[]` | The [whitelist](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-whitelist) of words used when training the model.
|
286
|
+
|
287
|
+
Example:
|
288
|
+
|
289
|
+
```ruby
|
290
|
+
response = Monkeylearn.classifiers.create("New classifier name", algorithm: "svm", ngram_range: [1, 2])
|
291
|
+
```
|
292
|
+
|
293
|
+
<br>
|
294
|
+
|
295
|
+
#### [Edit Classifier](https://monkeylearn.com/api/v3/?shell#edit-classifier)
|
296
|
+
|
297
|
+
|
298
|
+
```ruby
|
299
|
+
Monkeylearn.classifiers.edit(model_id, options = {})
|
300
|
+
```
|
301
|
+
|
302
|
+
Parameters:
|
303
|
+
|
304
|
+
Parameter |Type |Description
|
305
|
+
-----------|---------|-----------
|
306
|
+
*model_id* |`String` |Classifier ID. It always starts with `'cl'`, for example, `'cl_oJNMkt2V'`. |
|
307
|
+
*options* |`Hash` |Optional parameters, see below. The hash always expects symbols as keys.
|
308
|
+
|
309
|
+
Optional parameters:
|
310
|
+
|
311
|
+
| Parameter |Type | Description |
|
312
|
+
|--------------------|-------------------|-----------------------------------------------------------|
|
313
|
+
name | `String` | The name of the model.
|
314
|
+
description | `String` | The description of the model.
|
315
|
+
algorithm | `String` | The [algorithm](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-changing-the-algorithm) used when training the model. It can either be "nb" or "svm".
|
316
|
+
language | `String` | The [language](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-language) of the model. Full list of [supported languages](https://monkeylearn.com/api/v3/#classifier-detail).
|
317
|
+
max_features | `Integer` | The [maximum number of features](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-max-features) used when training the model. Between 10 and 100000.
|
318
|
+
ngram_range | `Array` | Indicates which [n-gram range](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-n-gram-range) used when training the model. A list of two numbers between 1 and 3. They indicate the minimum and the maximum n for the n-grams used, respectively.
|
319
|
+
use_stemming | `Boolean`| Indicates whether [stemming](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-stemming) is used when training the model.
|
320
|
+
preprocess_numbers | `Boolean` | Indicates whether [number preprocessing](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-preprocess-numbers) is done when training the model.
|
321
|
+
preprocess_social_media | `Boolean` | Indicates whether [preprocessing of social media](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-social-media-preprocessing-and-regular-expressions) is done when training the model.
|
322
|
+
normalize_weights | `Boolean` | Indicates whether [weights will be normalized](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-normalize-weights) when training the model.
|
323
|
+
stopwords | `Boolean or Array` | The list of [stopwords](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-filter-stopwords) used when training the model. Use *false* for no stopwords, *true* for the default stopwords, or an array of strings for custom stopwords.
|
324
|
+
whitelist | `Array` | The [whitelist](http://help.monkeylearn.com/tips-and-tricks-for-custom-modules/parameters-whitelist) of words used when training the model.
|
325
|
+
|
326
|
+
Example:
|
130
327
|
|
131
328
|
```ruby
|
132
|
-
|
329
|
+
response = Monkeylearn.classifiers.edit("[MODEL_ID]", name: "New classifier name", algorithm: "nb")
|
133
330
|
```
|
331
|
+
<br>
|
332
|
+
|
333
|
+
#### [Delete classifier](https://monkeylearn.com/api/v3/?shell#delete-classifier)
|
134
334
|
|
135
|
-
Delete a category:
|
136
335
|
|
137
336
|
```ruby
|
138
|
-
|
337
|
+
Monkeylearn.classifiers.delete(model_id)
|
139
338
|
```
|
140
339
|
|
141
|
-
|
340
|
+
Parameters:
|
341
|
+
|
342
|
+
| Parameter |Type | Description |
|
343
|
+
|--------------------|-------------------|-----------------------------------------------------------|
|
344
|
+
|*model_id* |`String` |Classifier ID. It always starts with `'cl'`, for example, `'cl_oJNMkt2V'`. |
|
345
|
+
|
346
|
+
Example:
|
347
|
+
|
348
|
+
```ruby
|
349
|
+
Monkeylearn.classifiers.delete('[MODEL_ID]')
|
350
|
+
```
|
351
|
+
|
352
|
+
<br>
|
353
|
+
|
354
|
+
#### [List Classifiers](https://monkeylearn.com/api/v3/?shell#list-classifiers)
|
355
|
+
|
356
|
+
|
357
|
+
```ruby
|
358
|
+
Monkeylearn.classifiers.list(page: 1, per_page: 20)
|
359
|
+
```
|
360
|
+
|
361
|
+
Optional parameters:
|
362
|
+
|
363
|
+
|Parameter |Type |Default | Description |
|
364
|
+
|--------------------|-------------------|-------------------|-------------|
|
365
|
+
|*page* |`Integer` | `1` | Specifies which page to get.|
|
366
|
+
|*per_page* |`Integer` | `20` | Specifies how many items per page will be returned. |
|
367
|
+
|
368
|
+
Example:
|
369
|
+
|
370
|
+
```ruby
|
371
|
+
response = Monkeylearn.classifiers.list(page: 1, per_page: 5)
|
372
|
+
```
|
373
|
+
|
374
|
+
<br>
|
375
|
+
|
376
|
+
#### [Deploy](https://monkeylearn.com/api/v3/?shell#deploy)
|
377
|
+
|
378
|
+
|
379
|
+
```ruby
|
380
|
+
Monkeylearn.classifiers.deploy(model_id)
|
381
|
+
```
|
382
|
+
|
383
|
+
Parameters:
|
384
|
+
|
385
|
+
| Parameter |Type | Description |
|
386
|
+
|--------------------|-------------------|-----------------------------------------------------------|
|
387
|
+
|*model_id* |`String` |Classifier ID. It always starts with `'cl'`, for example, `'cl_oJNMkt2V'`. |
|
388
|
+
|
389
|
+
Example:
|
390
|
+
|
391
|
+
```ruby
|
392
|
+
Monkeylearn.classifiers.deploy('[MODEL_ID]')
|
393
|
+
```
|
394
|
+
|
395
|
+
<br>
|
396
|
+
|
397
|
+
#### [Tag detail](https://monkeylearn.com/api/v3/?shell#classify)
|
398
|
+
|
399
|
+
|
400
|
+
```ruby
|
401
|
+
Monkeylearn.classifiers.tags.detail(model_id, tag_id)
|
402
|
+
```
|
403
|
+
|
404
|
+
Parameters:
|
405
|
+
|
406
|
+
| Parameter |Type | Description |
|
407
|
+
|--------------------|-------------------|-----------------------------------------------------------|
|
408
|
+
|*model_id* |`String` |Classifier ID. It always starts with `'cl'`, for example, `'cl_oJNMkt2V'`. |
|
409
|
+
|*tag_id* |`Integer` |Tag ID. |
|
410
|
+
|
411
|
+
Example:
|
412
|
+
|
413
|
+
``` ruby
|
414
|
+
response = Monkeylearn.classifiers.tags.detail("[MODEL_ID]", TAG_ID)
|
415
|
+
```
|
416
|
+
|
417
|
+
<br>
|
418
|
+
|
419
|
+
#### [Create tag](https://monkeylearn.com/api/v3/?shell#create-tag)
|
420
|
+
|
421
|
+
|
422
|
+
```ruby
|
423
|
+
Monkeylearn.classifiers.tags.create(model_id, name, options = {})
|
424
|
+
```
|
425
|
+
|
426
|
+
Parameters:
|
427
|
+
|
428
|
+
| Parameter |Type | Description |
|
429
|
+
|--------------------|----------|-----------------------------------------------------------|
|
430
|
+
|*model_id* |`String |Classifier ID. It always starts with `'cl'`, for example, `'cl_oJNMkt2V'`. |
|
431
|
+
|*name* |`String` |The name of the new tag. |
|
432
|
+
|*options* |`Hash` |Optional parameters, see below. The hash always expects symbols as keys. |
|
433
|
+
|
434
|
+
Optional parameters:
|
435
|
+
|
436
|
+
| Parameter |Type | Description |
|
437
|
+
|--------------------|-------------------|-----------------------------------------------------------|
|
438
|
+
|*parent_id* |`Integer` |**DEPRECATED**. The ID of the parent tag.
|
439
|
+
|
440
|
+
Example:
|
441
|
+
|
442
|
+
```ruby
|
443
|
+
response = Monkeylearn.classifiers.tags.create("[MODEL_ID]", "Positive")
|
444
|
+
```
|
445
|
+
|
446
|
+
<br>
|
447
|
+
|
448
|
+
#### [Edit tag](https://monkeylearn.com/api/v3/?shell#edit-tag)
|
449
|
+
|
450
|
+
|
451
|
+
```ruby
|
452
|
+
Monkeylearn.classifiers.tags.edit(model_id, tag_id, options = {})
|
453
|
+
```
|
454
|
+
|
455
|
+
Parameters:
|
456
|
+
|
457
|
+
| Parameter |Type | Description |
|
458
|
+
|--------------------|-------------------|-----------------------------------------------------------|
|
459
|
+
|*model_id* |`String` |Classifier ID. It always starts with `'cl'`, for example, `'cl_oJNMkt2V'`. |
|
460
|
+
|*tag_id* |`Integer` |Tag ID. |
|
461
|
+
|*options* |`Hash` |Optional parameters, see below. The hash always expects symbols as keys. |
|
462
|
+
|
463
|
+
Optional parameters:
|
464
|
+
|
465
|
+
| Parameter |Type | Description |
|
466
|
+
|--------------------|-------------------|-----------------------------------------------------------|
|
467
|
+
|*name* |`String` |The new name of the tag. |
|
468
|
+
|*parent_id* |`Integer` |**DEPRECATED**. The new parent tag ID.
|
469
|
+
|
470
|
+
Example:
|
471
|
+
|
472
|
+
```ruby
|
473
|
+
response = Monkeylearn.classifiers.tags.edit("[MODEL_ID]", TAG_ID, name: "New name")
|
474
|
+
```
|
475
|
+
|
476
|
+
<br>
|
477
|
+
|
478
|
+
#### [Delete tag](https://monkeylearn.com/api/v3/?shell#delete-tag)
|
479
|
+
|
480
|
+
|
481
|
+
```ruby
|
482
|
+
Monkeylearn.classifiers.tags.delete(model_id, tag_id, options = {})
|
483
|
+
```
|
484
|
+
|
485
|
+
Parameters:
|
486
|
+
|
487
|
+
| Parameter |Type | Description |
|
488
|
+
|---------------|-------------------|-----------------------------------------------------------|
|
489
|
+
|*model_id* |`String` |Classifier ID. It always starts with `'cl'`, for example, `'cl_oJNMkt2V'`. |
|
490
|
+
|*tag_id* |`Integer` |Tag ID. |
|
491
|
+
|*options* |`Hash` |Optional parameters, see below. The hash always expects symbols as keys. |
|
492
|
+
|
493
|
+
Optional parameters:
|
494
|
+
|
495
|
+
| Parameter |Type |Default | Description |
|
496
|
+
|--------------------|-------------------|----------------------|-----------------------------------------------------------|
|
497
|
+
|*move_data_to* |`int` |`nil` |An optional tag ID. If provided, data associated with the tag to be deleted will be moved to the specified tag before deletion. |
|
498
|
+
|
499
|
+
Example:
|
500
|
+
|
501
|
+
```ruby
|
502
|
+
Monkeylearn.classifiers.tags.delete("[MODEL_ID]", TAG_ID)
|
503
|
+
```
|
504
|
+
|
505
|
+
<br>
|
506
|
+
|
507
|
+
#### [Upload data](https://monkeylearn.com/api/v3/?shell#upload-data)
|
508
|
+
|
509
|
+
|
510
|
+
```ruby
|
511
|
+
Monkeylearn.classifiers.upload_data(model_id, data)
|
512
|
+
```
|
513
|
+
|
514
|
+
Parameters:
|
515
|
+
|
516
|
+
| Parameter |Type | Description |
|
517
|
+
|--------------------|-------------------|-----------------------------------------------------------|
|
518
|
+
|*model_id* |`String` |Classifier ID. It always starts with `'cl'`, for example, `'cl_oJNMkt2V'`. |
|
519
|
+
|*data* |`Array[Hash]` |A list of hashes with the keys described below.
|
520
|
+
|
521
|
+
`data` hash keys:
|
522
|
+
|
523
|
+
|Key | Description |
|
524
|
+
|--------- | ----------- |
|
525
|
+
|text | A *String* of the text to upload.|
|
526
|
+
|tags | An optional *Array* of tags that can be refered to by their numeric ID or their name. The text will be tagged with each tag in the *list* when created (in case it doesn't already exist on the model). Otherwise, its tags will be updated to the new ones. New tags will be created if they don't already exist.||
|
527
|
+
|marks | An optional *Array* of *String*. Each one represents a mark that will be associated with the text. New marks will be created if they don't already exist.|
|
528
|
+
|
529
|
+
|
530
|
+
Example:
|
531
|
+
|
532
|
+
```ruby
|
533
|
+
response = Monkeylearn.classifiers.upload_data(
|
534
|
+
"[MODEL_ID]",
|
535
|
+
[{text: "text 1", tags: [TAG_ID_1, "[tag_name]"]},
|
536
|
+
{text: "text 2", tags: [TAG_ID_1, TAG_ID_2]}]
|
537
|
+
)
|
538
|
+
```
|
539
|
+
|
540
|
+
<br>
|
541
|
+
|
542
|
+
### Extractors
|
543
|
+
|
544
|
+
|
545
|
+
#### [Extract](https://monkeylearn.com/api/v3/?shell#extract)
|
546
|
+
|
547
|
+
|
548
|
+
```ruby
|
549
|
+
Monkeylearn.extractors.extract(model_id, data, options = {})
|
550
|
+
```
|
551
|
+
|
552
|
+
Parameters:
|
553
|
+
|
554
|
+
| Parameter |Type | Description |
|
555
|
+
|--------------------|-------------------|-----------------------------------------------------------|
|
556
|
+
|*model_id* |`String` |Extractor ID. It always starts with `'ex'`, for example, `'ex_oJNMkt2V'`. |
|
557
|
+
|*data* |`Array[String or Hash]`|A list of up to 200 data elements to extract from. Each element must be a *string* with the text or a *dict* with the required `text` key and the text as the value. You can also provide an optional `external_id` key with a string that will be included in the response. |
|
558
|
+
|*options* |`Hash` | Optional parameters, see below. The hash always expects symbols as keys.
|
559
|
+
|
560
|
+
Optional parameters:
|
561
|
+
|
562
|
+
| Parameter |Type |Default | Description |
|
563
|
+
|--------------------|-------------------|----------------------|-----------------------------------------------------------|
|
564
|
+
|*production_model* |`Boolean` | `False` | Indicates if the extractions are performed by the production model. Only use this parameter with *custom models* (not with the public ones). Note that you first need to deploy the model to production either from the UI model settings or by using the [Classifier deploy endpoint](#deploy). |
|
565
|
+
|*batch_size* |`Integer` | 200 | Max number of texts each request will send to MonkeyLearn. A number from 1 to 200. |
|
566
|
+
|
567
|
+
Example:
|
568
|
+
|
569
|
+
```ruby
|
570
|
+
data = ["First text", {"text": "Second text", "external_id": "2"}]
|
571
|
+
response = Monkeylearn.extractors.extract("[MODEL_ID]", data)
|
572
|
+
```
|
573
|
+
|
574
|
+
<br>
|
575
|
+
|
576
|
+
#### [Extractor detail](https://monkeylearn.com/api/v3/?shell#extractor-detail)
|
577
|
+
|
578
|
+
|
579
|
+
```ruby
|
580
|
+
Monkeylearn.extractors.detail(model_id)
|
581
|
+
```
|
582
|
+
|
583
|
+
Parameters:
|
584
|
+
|
585
|
+
| Parameter |Type | Description |
|
586
|
+
|--------------------|-------------------|-----------------------------------------------------------|
|
587
|
+
|*model_id* |`String` |Extractor ID. It always starts with `'ex'`, for example, `'ex_oJNMkt2V'`. |
|
588
|
+
|
589
|
+
Example:
|
590
|
+
|
591
|
+
```ruby
|
592
|
+
response = Monkeylearn.extractors.detail("[MODEL_ID]")
|
593
|
+
```
|
594
|
+
|
595
|
+
<br>
|
596
|
+
|
597
|
+
#### [List extractors](https://monkeylearn.com/api/v3/?shell#list-extractors)
|
598
|
+
|
599
|
+
|
600
|
+
```ruby
|
601
|
+
Monkeylearn.extractors.list(options = {})
|
602
|
+
```
|
603
|
+
|
604
|
+
Parameters:
|
605
|
+
|
606
|
+
|Parameter |Type |Default | Description |
|
607
|
+
|--------------------|-------------------|-------------------|-------------|
|
608
|
+
|*page* |`Integer` | `1` | Specifies which page to get.|
|
609
|
+
|*per_page* |`Integer` | `20` | Specifies how many items per page will be returned. |
|
610
|
+
|
611
|
+
Example:
|
142
612
|
|
143
613
|
```ruby
|
144
|
-
|
614
|
+
response = Monkeylearn.extractors.list(page: 1)
|
145
615
|
```
|