|
4 | 4 | from watson_developer_cloud import ToneAnalyzerV3 |
5 | 5 |
|
6 | 6 | tone_analyzer = ToneAnalyzerV3( |
7 | | - username='YOUR SERVICE USERNAME', |
8 | | - password='YOUR SERVICE PASSWORD', |
| 7 | + username='6e9af982-31bf-45c4-99b0-51f6b576e433', |
| 8 | + password='2dXhAyPQjxD5', |
| 9 | + # username='YOUR SERVICE USERNAME', |
| 10 | + # password='YOUR SERVICE PASSWORD', |
9 | 11 | version='2016-05-19') |
10 | 12 |
|
11 | 13 | print("\ntone_chat() example 1:\n") |
12 | | -utterances = [{'text': 'I am very happy', 'user': 'glenn'}] |
| 14 | +utterances = [{'text': 'I am very happy.', 'user': 'glenn'}, |
| 15 | + {'text': 'It is a good day.', 'user': 'glenn'}] |
13 | 16 | print(json.dumps(tone_analyzer.tone_chat(utterances), indent=2)) |
14 | 17 |
|
15 | 18 | print("\ntone() example 1:\n") |
|
19 | 22 | print("\ntone() example 2:\n") |
20 | 23 | with open(join(dirname(__file__), |
21 | 24 | '../resources/tone-example.json')) as tone_json: |
22 | | - tone = tone_analyzer.tone(json.load(tone_json)['text'], |
23 | | - tones='emotion') |
| 25 | + tone = tone_analyzer.tone(json.load(tone_json)['text'], 'emotion') |
24 | 26 | print(json.dumps(tone, indent=2)) |
25 | 27 |
|
26 | 28 | print("\ntone() example 3:\n") |
27 | 29 | with open(join(dirname(__file__), |
28 | 30 | '../resources/tone-example.json')) as tone_json: |
29 | | - tone = tone_analyzer.tone(json.load(tone_json)['text'], |
30 | | - content_type='text/plain', tones='emotion') |
| 31 | + tone = tone_analyzer.tone(json.load(tone_json)['text'], 'emotion', |
| 32 | + True, 'text/plain') |
31 | 33 | print(json.dumps(tone, indent=2)) |
32 | 34 |
|
33 | 35 | print("\ntone() example 4:\n") |
34 | 36 | with open(join(dirname(__file__), |
35 | 37 | '../resources/tone-example.json')) as tone_json: |
36 | | - tone = tone_analyzer.tone(json.load(tone_json), |
37 | | - content_type='application/json', tones='emotion') |
| 38 | + tone = tone_analyzer.tone(json.load(tone_json), 'emotion', |
| 39 | + content_type='application/json', ) |
38 | 40 | print(json.dumps(tone, indent=2)) |
39 | 41 |
|
40 | 42 | print("\ntone() example 5:\n") |
41 | 43 | with open(join(dirname(__file__), |
42 | 44 | '../resources/tone-example-html.json')) as tone_json: |
43 | | - tone = tone_analyzer.tone(json.load(tone_json)['text'], |
44 | | - content_type='text/html', tones='emotion') |
| 45 | + tone = tone_analyzer.tone(json.load(tone_json)['text'], 'emotion', |
| 46 | + content_type='text/html') |
45 | 47 | print(json.dumps(tone, indent=2)) |
0 commit comments