Skip to content

Commit 7b9de7c

Browse files
Merge pull request #391 from watson-developer-cloud/codegen/tone-analyzer
Regenerate tone analyzer
2 parents 179dfe9 + 25108e2 commit 7b9de7c

2 files changed

Lines changed: 17 additions & 23 deletions

File tree

test/unit/test_tone_analyzer_v3.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_tone():
2222
with open(os.path.join(os.path.dirname(__file__), '../../resources/personality.txt')) as tone_text:
2323
tone_analyzer = watson_developer_cloud.ToneAnalyzerV3("2016-05-19",
2424
username="username", password="password")
25-
tone_analyzer.tone(tone_text.read())
25+
tone_analyzer.tone(tone_text.read(), 'application/json')
2626

2727
assert responses.calls[0].request.url == tone_url + tone_args
2828
assert responses.calls[0].response.text == tone_response
@@ -46,7 +46,7 @@ def test_tone_with_args():
4646
with open(os.path.join(os.path.dirname(__file__), '../../resources/personality.txt')) as tone_text:
4747
tone_analyzer = watson_developer_cloud.ToneAnalyzerV3("2016-05-19",
4848
username="username", password="password")
49-
tone_analyzer.tone(tone_text.read(), sentences=False)
49+
tone_analyzer.tone(tone_text.read(), 'application/json', sentences=False)
5050

5151
assert responses.calls[0].request.url.split('?')[0] == tone_url
5252
# Compare args. Order is not deterministic!
@@ -134,7 +134,7 @@ def test_error():
134134
username="username", password="password")
135135
text = "Team, I know that times are tough!"
136136
try:
137-
tone_analyzer.tone(text)
137+
tone_analyzer.tone(text, 'application/json')
138138
except WatsonException as ex:
139139
assert len(responses.calls) == 1
140140
assert isinstance(ex, WatsonApiException)

watson_developer_cloud/tone_analyzer_v3.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
"""
17-
### Service Overview
1817
The IBM Watson Tone Analyzer service uses linguistic analysis to detect emotional and
1918
language tones in written text. The service can analyze tone at both the document and
2019
sentence levels. You can use the service to understand how your written communications are
@@ -81,12 +80,12 @@ def __init__(self, version, url=default_url, username=None, password=None):
8180
self.version = version
8281

8382
#########################
84-
# tone
83+
# Methods
8584
#########################
8685

8786
def tone(self,
8887
tone_input,
89-
content_type='application/json',
88+
content_type,
9089
sentences=None,
9190
tones=None,
9291
content_language=None,
@@ -98,8 +97,8 @@ def tone(self,
9897
:param str content_type: The type of the input: application/json, text/plain, or text/html. A character encoding can be specified by including a `charset` parameter. For example, 'text/plain;charset=utf-8'.
9998
:param bool sentences: Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If `true` (the default), the service returns results for each sentence.
10099
:param list[str] tones: **`2017-09-21`:** Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response. **`2016-05-19`:** A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.
101-
:param str content_language: The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, `en-US` is interpreted as `en`. The input content must match the specified language. Do not submit content that contains both languages. You can specify any combination of languages for `content_language` and `Accept-Language`. * **`2017-09-21`:** Accepts `en` or `fr`. * **`2016-05-19`:** Accepts only `en`.
102-
:param str accept_language: The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, `en-US` is interpreted as `en`. You can specify any combination of languages for `Content-Language` and `accept_language`.
100+
:param str content_language: The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, `en-US` is interpreted as `en`. The input content must match the specified language. Do not submit content that contains both languages. You can specify any combination of languages for `Content-Language` and `Accept-Language`. * **`2017-09-21`:** Accepts `en` or `fr`. * **`2016-05-19`:** Accepts only `en`.
101+
:param str accept_language: The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, `en-US` is interpreted as `en`. You can specify any combination of languages for `Content-Language` and `Accept-Language`.
103102
:return: A `dict` containing the `ToneAnalysis` response.
104103
:rtype: dict
105104
"""
@@ -131,30 +130,26 @@ def tone(self,
131130
accept_json=True)
132131
return response
133132

134-
def tone_chat(self, utterances, accept_language=None):
133+
def tone_chat(self,
134+
utterances,
135+
content_language=None,
136+
accept_language=None):
135137
"""
136138
Analyze customer engagement tone.
137139
138-
Use the customer engagement endpoint to analyze the tone of customer service and
139-
customer support conversations. For each utterance of a conversation, the method
140-
reports the most prevalent subset of the following seven tones: sad, frustrated,
141-
satisfied, excited, polite, impolite, and sympathetic. If you submit more than
142-
50 utterances, the service returns a warning for the overall content and analyzes
143-
only the first 50 utterances. If you submit a single utterance that contains more
144-
than 500 characters, the service returns an error for that utterance and does not
145-
analyze the utterance. The request fails if all utterances have more than 500
146-
characters. Per the JSON specification, the default character encoding for JSON
147-
content is effectively always UTF-8.
148-
149140
:param list[Utterance] utterances: An array of `Utterance` objects that provides the input content that the service is to analyze.
141+
:param str content_language: The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, `en-US` is interpreted as `en`. The input content must match the specified language. Do not submit content that contains both languages. You can specify any combination of languages for `Content-Language` and `Accept-Language`. * **`2017-09-21`:** Accepts `en` or `fr`. * **`2016-05-19`:** Accepts only `en`.
150142
:param str accept_language: The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, `en-US` is interpreted as `en`.
151143
:return: A `dict` containing the `UtteranceAnalyses` response.
152144
:rtype: dict
153145
"""
154146
if utterances is None:
155147
raise ValueError('utterances must be provided')
156-
utterances = [self._convert_model(x) for x in utterances]
157-
headers = {'Accept-Language': accept_language}
148+
utterances = [self._convert_model(x, Utterance) for x in utterances]
149+
headers = {
150+
'Content-Language': content_language,
151+
'Accept-Language': accept_language
152+
}
158153
params = {'version': self.version}
159154
data = {'utterances': utterances}
160155
url = '/v3/tone_chat'
@@ -167,7 +162,6 @@ def tone_chat(self, utterances, accept_language=None):
167162
accept_json=True)
168163
return response
169164

170-
171165
##############################################################################
172166
# Models
173167
##############################################################################

0 commit comments

Comments
 (0)