Skip to content
Merged
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
23 changes: 15 additions & 8 deletions watson_developer_cloud/language_translator_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, url=default_url, username=None, password=None):
use_vcap_services=True)

#########################
# translate
# Translate
#########################

def translate(self, text, model_id=None, source=None, target=None):
Expand Down Expand Up @@ -94,7 +94,7 @@ def translate(self, text, model_id=None, source=None, target=None):
return response

#########################
# identify
# Identify
#########################

def identify(self, text):
Expand Down Expand Up @@ -133,7 +133,7 @@ def list_identifiable_languages(self):
return response

#########################
# models
# Models
#########################

def create_model(self,
Expand Down Expand Up @@ -219,9 +219,10 @@ def delete_model(self, model_id):

def get_model(self, model_id):
"""
Get information about the given translation model, including training status.
Gets information about a translation model, including training status for custom
models.

:param str model_id: Model ID to use.
:param str model_id: Model ID of the model to get.
:return: A `dict` containing the `TranslationModel` response.
:rtype: dict
"""
Expand All @@ -233,15 +234,19 @@ def get_model(self, model_id):

def list_models(self, source=None, target=None, default_models=None):
"""
Lists available standard and custom models by source or target language.
Lists available translation models.

:param str source: Specify a language code to filter results by source language.
:param str target: Specify a language code to filter results by target language.
:param bool default_models: If the default_models parameter isn't specified, the service will return all models (default_models and non-default_models) for each language pair. To return only default_models models, set this to `true`. To return only non-default_models models, set this to `false`.
:param bool default_models: If the default parameter isn't specified, the service will return all models (default and non-default) for each language pair. To return only default models, set this to `true`. To return only non-default models, set this to `false`.
:return: A `dict` containing the `TranslationModels` response.
:rtype: dict
"""
params = {'source': source, 'target': target, 'default': default_models}
params = {
'source': source,
'target': target,
'default': default_models
}
url = '/v2/models'
response = self.request(
method='GET', url=url, params=params, accept_json=True)
Expand Down Expand Up @@ -543,6 +548,8 @@ def __init__(self, translation_output):
def _from_dict(cls, _dict):
"""Initialize a Translation object from a json dictionary."""
args = {}
if 'translation_output' in _dict:
args['translation_output'] = _dict['translation_output']
if 'translation' in _dict:
args['translation_output'] = _dict['translation']
else:
Expand Down