Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions monkeylearn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@
from __future__ import (
print_function, unicode_literals, division, absolute_import)

from monkeylearn.settings import DEFAULT_BASE_ENDPOINT
from monkeylearn.classification import Classification
from monkeylearn.extraction import Extraction
from monkeylearn.pipelines import Pipelines

class MonkeyLearn(object):

def __init__(self, token):
def __init__(self, token, base_endpoint=DEFAULT_BASE_ENDPOINT):
self.token = token
self.base_endpoint = base_endpoint

@property
def classifiers(self):
return Classification(self.token)
return Classification(token=self.token,
base_endpoint=self.base_endpoint)

@property
def extractors(self):
return Extraction(self.token)
return Extraction(token=self.token,
base_endpoint=self.base_endpoint)

@property
def pipelines(self):
return Pipelines(self.token)
return Pipelines(token=self.token,
base_endpoint=self.base_endpoint)
6 changes: 3 additions & 3 deletions monkeylearn/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from six.moves import range

from monkeylearn.utils import SleepRequestsMixin, MonkeyLearnResponse, HandleErrorsMixin
from monkeylearn.settings import CLASSIFICATION_ENDPOINT, DEFAULT_BATCH_SIZE
from monkeylearn.settings import DEFAULT_BASE_ENDPOINT, DEFAULT_BATCH_SIZE


class Classification(SleepRequestsMixin, HandleErrorsMixin):

def __init__(self, token):
def __init__(self, token, base_endpoint=DEFAULT_BASE_ENDPOINT):
self.token = token
self.endpoint = CLASSIFICATION_ENDPOINT
self.endpoint = base_endpoint + 'classifiers/'

@property
def categories(self):
Expand Down
6 changes: 3 additions & 3 deletions monkeylearn/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from six.moves import range

from monkeylearn.utils import SleepRequestsMixin, MonkeyLearnResponse, HandleErrorsMixin
from monkeylearn.settings import EXTRACTION_ENDPOINT, DEFAULT_BATCH_SIZE
from monkeylearn.settings import DEFAULT_BASE_ENDPOINT, DEFAULT_BATCH_SIZE

class Extraction(SleepRequestsMixin, HandleErrorsMixin):

def __init__(self, token):
def __init__(self, token, base_endpoint=DEFAULT_BASE_ENDPOINT):
self.token = token
self.endpoint = EXTRACTION_ENDPOINT
self.endpoint = base_endpoint + 'extractors/'

def extract(self, module_id, text_list, batch_size=DEFAULT_BATCH_SIZE,
sleep_if_throttled=True):
Expand Down
6 changes: 3 additions & 3 deletions monkeylearn/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
print_function, unicode_literals, division, absolute_import)

from monkeylearn.utils import SleepRequestsMixin, MonkeyLearnResponse, HandleErrorsMixin
from monkeylearn.settings import PIPELINES_ENDPOINT
from monkeylearn.settings import DEFAULT_BASE_ENDPOINT
from monkeylearn.exceptions import MonkeyLearnException

class Pipelines(SleepRequestsMixin, HandleErrorsMixin):

def __init__(self, token):
def __init__(self, token, base_endpoint=DEFAULT_BASE_ENDPOINT):
self.token = token
self.endpoint = PIPELINES_ENDPOINT
self.endpoint = base_endpoint + 'pipelines/'

def run(self, module_id, data, sandbox=False, sleep_if_throttled=True):
if not isinstance(data, dict):
Expand Down
5 changes: 1 addition & 4 deletions monkeylearn/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@
DEFAULT_BATCH_SIZE = 200
MAX_BATCH_SIZE = 500
MIN_BATCH_SIZE = 100
BASE_ENDPOINT = 'https://api.monkeylearn.com/v2/'
CLASSIFICATION_ENDPOINT = BASE_ENDPOINT + 'classifiers/'
EXTRACTION_ENDPOINT = BASE_ENDPOINT + 'extractors/'
PIPELINES_ENDPOINT = BASE_ENDPOINT + 'pipelines/'
DEFAULT_BASE_ENDPOINT = 'https://api.monkeylearn.com/v2/'