Skip to content

Commit ac2512d

Browse files
author
rsteca
committed
Merge pull request #8 from amartinezuy/debug-option-classify
add debug option to classifiers.classify
2 parents 2e39bab + 62d7129 commit ac2512d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

monkeylearn/classification.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
import six
66
from six.moves import range
7+
try:
8+
from urllib import urlencode
9+
except: # For Python 3
10+
from urllib.parse import urlencode
711

812
from monkeylearn.utils import SleepRequestsMixin, MonkeyLearnResponse, HandleErrorsMixin
913
from monkeylearn.settings import DEFAULT_BASE_ENDPOINT, DEFAULT_BATCH_SIZE
@@ -21,12 +25,20 @@ def categories(self):
2125
return Categories(self.token, self.endpoint)
2226

2327
def classify(self, module_id, text_list, sandbox=False,
24-
batch_size=DEFAULT_BATCH_SIZE, sleep_if_throttled=True):
28+
batch_size=DEFAULT_BATCH_SIZE, sleep_if_throttled=True,
29+
debug=False):
2530
text_list = list(text_list)
2631
self.check_batch_limits(text_list, batch_size)
2732
url = self.endpoint + module_id + '/classify/'
33+
34+
url_params = {}
2835
if sandbox:
29-
url += '?sandbox=1'
36+
url_params['sandbox'] = 1
37+
if debug:
38+
url_params['debug'] = 1
39+
if url_params:
40+
url += '?{}'.format(urlencode(url_params))
41+
3042
res = []
3143
responses = []
3244
for i in range(0, len(text_list), batch_size):

0 commit comments

Comments
 (0)