@@ -25,19 +25,25 @@ class ToneAnalyzerV3(WatsonDeveloperCloudService):
2525 default_url = 'https://gateway.watsonplatform.net/tone-analyzer/api'
2626 latest_version = '2016-05-19'
2727
28- def __init__ (self , version = latest_version , url = default_url , username = None , password = None , use_vcap_services = True ):
28+ def __init__ (self , version , url = default_url , username = None , password = None , use_vcap_services = True ):
2929 WatsonDeveloperCloudService .__init__ (
3030 self , 'tone_analyzer' , url , username , password , use_vcap_services )
3131 self .version = version
3232
33- def tone (self , text , params = None ):
33+ def tone (self , text , tones = None , sentences = None ):
3434 """
3535 The tone API is the main API call: it analyzes the "tone" of a piece of text. The message is analyzed from
3636 several tones (social tone, emotional tone, writing tone), and for each of them various traits are derived
3737 (such as conscientiousness, agreeableness, openness).
3838 :param text: Text to analyze
39+ :param sentences: If "false", sentence-level analysis is omitted
40+ :param tones: Can be one or more of 'social', 'language', 'emotion'; comma-separated.
3941 """
40- args = copy .copy (params ) if params is not None else {}
41- args ['version' ] = self .version
42+ queryArgs = {}
43+ queryArgs ['version' ] = self .version
44+ if tones is not None :
45+ queryArgs ['tones' ] = tones
46+ if sentences is not None :
47+ queryArgs ['sentences' ] = str (sentences ).lower () # Cast boolean to "false" / "true"
4248 data = {'text' : text }
43- return self .request (method = 'POST' , url = '/v3/tone' , params = args , json = data , accept_json = True )
49+ return self .request (method = 'POST' , url = '/v3/tone' , params = queryArgs , json = data , accept_json = True )
0 commit comments