Skip to content

Commit 9a7913f

Browse files
committed
chore(Tone Analyzer V3): Add examples
1 parent 2c3b04c commit 9a7913f

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

examples/IBM.Watson.ToneAnalyzer.v3.Examples/IBM.Watson.ToneAnalyzer.v3.Examples.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@
55
<TargetFramework>netcoreapp2.1</TargetFramework>
66
</PropertyGroup>
77

8+
<ItemGroup>
9+
<PackageReference Include="IBM.Cloud.SDK.Core" Version="0.7.1" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\IBM.Watson.ToneAnalyzer.v3\IBM.Watson.ToneAnalyzer.v3.csproj" />
14+
</ItemGroup>
15+
816
</Project>

examples/IBM.Watson.ToneAnalyzer.v3.Examples/ServiceExample.cs

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,86 @@
1515
*
1616
*/
1717

18+
using IBM.Cloud.SDK.Core.Util;
19+
using IBM.Watson.ToneAnalyzer.v3.Model;
1820
using System;
21+
using System.Collections.Generic;
1922

2023
namespace IBM.Watson.ToneAnalyzer.v3.Examples
2124
{
2225
public class ServiceExample
2326
{
2427
string apikey = "{apikey}";
2528
string url = "{url}";
26-
private string versionDate = "2016-05-19";
29+
private string versionDate = "{versionDate}";
2730

2831
static void Main(string[] args)
2932
{
3033
ServiceExample example = new ServiceExample();
3134

35+
example.Tone();
36+
example.ToneChat();
37+
3238
Console.WriteLine("Examples complete. Press any key to close the application.");
3339
Console.ReadKey();
3440
}
41+
42+
#region Analyze Tone
43+
public void Tone()
44+
{
45+
TokenOptions tokenOptions = new TokenOptions()
46+
{
47+
IamApiKey = apikey,
48+
ServiceUrl = url
49+
};
50+
51+
ToneAnalyzerService service = new ToneAnalyzerService(tokenOptions, versionDate);
52+
53+
ToneInput toneInput = new ToneInput()
54+
{
55+
Text = "Hello! Welcome to IBM Watson! How can I help you?"
56+
};
57+
58+
var result = service.Tone(
59+
toneInput: toneInput,
60+
contentType: "text/html",
61+
sentences: true,
62+
contentLanguage: "en-US",
63+
acceptLanguage: "en-US"
64+
);
65+
66+
Console.WriteLine(result.Response);
67+
}
68+
#endregion
69+
70+
#region Analyze Customer Engagment Tone
71+
public void ToneChat()
72+
{
73+
TokenOptions tokenOptions = new TokenOptions()
74+
{
75+
IamApiKey = apikey,
76+
ServiceUrl = url
77+
};
78+
79+
ToneAnalyzerService service = new ToneAnalyzerService(tokenOptions, versionDate);
80+
81+
var utterances = new List<Utterance>()
82+
{
83+
new Utterance()
84+
{
85+
Text = "Hello! Welcome to IBM Watson! How can I help you?",
86+
User = "testChatUser"
87+
}
88+
};
89+
90+
var result = service.ToneChat(
91+
utterances: utterances,
92+
contentLanguage: "en-US",
93+
acceptLanguage: "en-US"
94+
);
95+
96+
Console.WriteLine(result.Response);
97+
}
98+
#endregion
3599
}
36100
}

0 commit comments

Comments
 (0)