Skip to content

Commit 5a0d7a0

Browse files
author
Mike Kistler
committed
lint examples and fix lint errors
1 parent 79dce16 commit 5a0d7a0

4 files changed

Lines changed: 58 additions & 69 deletions

File tree

examples/conversation_tone_analyzer_integration/tone_detection.py

Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,20 @@
3131
WRITING_TONE_LABEL = 'writing_tone'
3232
SOCIAL_TONE_LABEL = 'social_tone'
3333

34-
"""
35-
updateUserTone processes the Tone Analyzer payload to pull out the emotion,
36-
writing and social tones, and identify the meaningful tones (i.e.,
37-
those tones that meet the specified thresholds).
38-
The conversationPayload json object is updated to include these tones.
39-
@param conversationPayload json object returned by the Watson Conversation
40-
Service
41-
@param toneAnalyzerPayload json object returned by the Watson Tone Analyzer
42-
Service
43-
@returns conversationPayload where the user object has been updated with tone
44-
information from the toneAnalyzerPayload
45-
"""
46-
4734

4835
def updateUserTone(conversationPayload, toneAnalyzerPayload, maintainHistory):
36+
"""
37+
updateUserTone processes the Tone Analyzer payload to pull out the emotion,
38+
writing and social tones, and identify the meaningful tones (i.e.,
39+
those tones that meet the specified thresholds).
40+
The conversationPayload json object is updated to include these tones.
41+
@param conversationPayload json object returned by the Watson Conversation
42+
Service
43+
@param toneAnalyzerPayload json object returned by the Watson Tone Analyzer
44+
Service
45+
@returns conversationPayload where the user object has been updated with tone
46+
information from the toneAnalyzerPayload
47+
"""
4948
emotionTone = None
5049
writingTone = None
5150
socialTone = None
@@ -80,18 +79,15 @@ def updateUserTone(conversationPayload, toneAnalyzerPayload, maintainHistory):
8079
return conversationPayload
8180

8281

83-
'''
84-
initToneContext initializes a user object containing tone data (from the
85-
Watson Tone Analyzer)
86-
@returns user json object with the emotion, writing and social tones. The
87-
current
88-
tone identifies the tone for a specific conversation turn, and the history
89-
provides the conversation for
90-
all tones up to the current tone for a conversation instance with a user.
91-
'''
92-
93-
9482
def initUser():
83+
"""
84+
initUser initializes a user object containing tone data (from the
85+
Watson Tone Analyzer)
86+
@returns user json object with the emotion, writing and social tones. The
87+
current tone identifies the tone for a specific conversation turn, and the
88+
history provides the conversation for all tones up to the current tone for a
89+
conversation instance with a user.
90+
"""
9591
return {
9692
'user': {
9793
'tone': {
@@ -109,19 +105,18 @@ def initUser():
109105
}
110106

111107

112-
'''
113-
updateEmotionTone updates the user emotion tone with the primary emotion -
114-
the emotion tone that has
115-
a score greater than or equal to the EMOTION_SCORE_THRESHOLD; otherwise
116-
primary emotion will be 'neutral'
117-
@param user a json object representing user information (tone) to be used in
118-
conversing with the Conversation Service
119-
@param emotionTone a json object containing the emotion tones in the payload
120-
returned by the Tone Analyzer
121-
'''
122108

123109

124110
def updateEmotionTone(user, emotionTone, maintainHistory):
111+
"""
112+
updateEmotionTone updates the user emotion tone with the primary emotion -
113+
the emotion tone that has a score greater than or equal to the
114+
EMOTION_SCORE_THRESHOLD; otherwise primary emotion will be 'neutral'
115+
@param user a json object representing user information (tone) to be used in
116+
conversing with the Conversation Service
117+
@param emotionTone a json object containing the emotion tones in the payload
118+
returned by the Tone Analyzer
119+
"""
125120
maxScore = 0.0
126121
primaryEmotion = None
127122
primaryEmotionScore = None
@@ -148,17 +143,15 @@ def updateEmotionTone(user, emotionTone, maintainHistory):
148143
})
149144

150145

151-
'''
152-
updateWritingTone updates the user with the writing tones interpreted based
153-
on the specified thresholds
154-
@param: user a json object representing user information (tone) to be used
155-
in conversing with the Conversation Service
156-
@param: writingTone a json object containing the writing tones in the
157-
payload returned by the Tone Analyzer
158-
'''
159-
160-
161146
def updateWritingTone(user, writingTone, maintainHistory):
147+
"""
148+
updateWritingTone updates the user with the writing tones interpreted based
149+
on the specified thresholds
150+
@param: user a json object representing user information (tone) to be used
151+
in conversing with the Conversation Service
152+
@param: writingTone a json object containing the writing tones in the
153+
payload returned by the Tone Analyzer
154+
"""
162155
currentWriting = []
163156
currentWritingObject = []
164157

@@ -189,21 +182,18 @@ def updateWritingTone(user, writingTone, maintainHistory):
189182
if maintainHistory:
190183
if 'history' not in user['tone']['writing']:
191184
user['tone']['writing']['history'] = []
192-
user['tone']['writing']['history'].append(currentWritingObject) # TODO -
193-
# is this the correct location??? AW
194-
195-
196-
"""
197-
updateSocialTone updates the user with the social tones interpreted based on
198-
the specified thresholds
199-
@param user a json object representing user information (tone) to be used in
200-
conversing with the Conversation Service
201-
@param socialTone a json object containing the social tones in the payload
202-
returned by the Tone Analyzer
203-
"""
185+
user['tone']['writing']['history'].append(currentWritingObject)
204186

205187

206188
def updateSocialTone(user, socialTone, maintainHistory):
189+
"""
190+
updateSocialTone updates the user with the social tones interpreted based on
191+
the specified thresholds
192+
@param user a json object representing user information (tone) to be used in
193+
conversing with the Conversation Service
194+
@param socialTone a json object containing the social tones in the payload
195+
returned by the Tone Analyzer
196+
"""
207197
currentSocial = []
208198
currentSocialObject = []
209199

examples/personality_insights_v3.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
"""
2+
The example returns a JSON response whose content is the same as that in
3+
../resources/personality-v3-expect2.txt
4+
"""
15
from __future__ import print_function
26
import json
37
from os.path import join, dirname
48
from watson_developer_cloud import PersonalityInsightsV3
59

6-
"""
7-
The example returns a JSON response whose content is the same as that in
8-
../resources/personality-v3-expect2.txt
9-
"""
10-
1110
personality_insights = PersonalityInsightsV3(
1211
version='2016-10-20',
1312
username='YOUR SERVICE USERNAME',

pylint.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
PYTHON_VERSION=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
55
echo "Python version: $PYTHON_VERSION"
66
if [ $PYTHON_VERSION = '2.7' ]; then
7-
pylint watson_developer_cloud
8-
pylint test
7+
pylint watson_developer_cloud test examples
98
fi

test/test_watson_service.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# coding=utf-8
22
import json
33

4-
import watson_developer_cloud
54
from watson_developer_cloud import WatsonService
65

76
import responses
@@ -31,8 +30,9 @@ def op_with_path_params(self, path0, path1):
3130
params = {'version': self.version}
3231
url = '/v1/foo/{0}/bar/{1}/baz'.format(
3332
*self._encode_path_vars(path0, path1))
34-
self.request(method='GET', url=url, params=params, accept_json=True)
35-
return None
33+
response = self.request(
34+
method='GET', url=url, params=params, accept_json=True)
35+
return response
3636

3737

3838
@responses.activate
@@ -51,12 +51,13 @@ def test_url_encoding():
5151

5252
responses.add(responses.GET,
5353
test_url,
54-
status = 200,
55-
body = json.dumps({"foobar": "baz"}),
56-
content_type = 'application/json')
54+
status=200,
55+
body=json.dumps({"foobar": "baz"}),
56+
content_type='application/json')
5757

5858
response = service.op_with_path_params(path0, path1)
5959

60+
assert response is not None
6061
assert len(responses.calls) == 1
6162
assert path_encoded in responses.calls[0].request.url
6263
assert 'version=2017-07-07' in responses.calls[0].request.url

0 commit comments

Comments
 (0)