Skip to content

Commit ba3a77f

Browse files
authored
Merge pull request #376 from watson-developer-cloud/6677-tone-analyzer-v3-examples
Add Tone Analyzer V3 examples
2 parents 70e6d42 + ec79459 commit ba3a77f

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

IBM.Watson.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IBM.Watson.SpeechToText.v1.
115115
EndProject
116116
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IBM.Watson.TextToSpeech.v1.Examples", "examples\IBM.Watson.TextToSpeech.v1.Examples\IBM.Watson.TextToSpeech.v1.Examples.csproj", "{D8E0E626-B930-42A9-88E7-13C05A08B868}"
117117
EndProject
118+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IBM.Watson.ToneAnalyzer.v3.Examples", "examples\IBM.Watson.ToneAnalyzer.v3.Examples\IBM.Watson.ToneAnalyzer.v3.Examples.csproj", "{523AE6E0-11CD-40CA-ABB1-8010E35C416D}"
119+
EndProject
118120
Global
119121
GlobalSection(SolutionConfigurationPlatforms) = preSolution
120122
Debug|Any CPU = Debug|Any CPU
@@ -293,6 +295,10 @@ Global
293295
{D8E0E626-B930-42A9-88E7-13C05A08B868}.Debug|Any CPU.Build.0 = Debug|Any CPU
294296
{D8E0E626-B930-42A9-88E7-13C05A08B868}.Release|Any CPU.ActiveCfg = Release|Any CPU
295297
{D8E0E626-B930-42A9-88E7-13C05A08B868}.Release|Any CPU.Build.0 = Release|Any CPU
298+
{523AE6E0-11CD-40CA-ABB1-8010E35C416D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
299+
{523AE6E0-11CD-40CA-ABB1-8010E35C416D}.Debug|Any CPU.Build.0 = Debug|Any CPU
300+
{523AE6E0-11CD-40CA-ABB1-8010E35C416D}.Release|Any CPU.ActiveCfg = Release|Any CPU
301+
{523AE6E0-11CD-40CA-ABB1-8010E35C416D}.Release|Any CPU.Build.0 = Release|Any CPU
296302
EndGlobalSection
297303
GlobalSection(SolutionProperties) = preSolution
298304
HideSolutionNode = FALSE
@@ -340,6 +346,7 @@ Global
340346
{16DD6AAE-E14D-4F84-A9ED-C8A3F2545855} = {D65AC99F-4E63-4362-8765-EB6F15838CA0}
341347
{0F974417-CFC9-4B58-8D92-F4B5DB9005DA} = {254924C9-64CD-4902-97C4-5F9E48DCDF7F}
342348
{D8E0E626-B930-42A9-88E7-13C05A08B868} = {A86D4D5B-AECE-49F2-A2BC-F6897B3EB2E8}
349+
{523AE6E0-11CD-40CA-ABB1-8010E35C416D} = {C7873F44-7188-49BE-84C5-532BE4E07147}
343350
EndGlobalSection
344351
GlobalSection(ExtensibilityGlobals) = postSolution
345352
SolutionGuid = {B9D9D17B-1C17-402F-B701-DC671528690A}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
</PropertyGroup>
7+
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+
16+
</Project>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* Copyright 2019 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using IBM.Cloud.SDK.Core.Util;
19+
using IBM.Watson.ToneAnalyzer.v3.Model;
20+
using System;
21+
using System.Collections.Generic;
22+
23+
namespace IBM.Watson.ToneAnalyzer.v3.Examples
24+
{
25+
public class ServiceExample
26+
{
27+
string apikey = "{apikey}";
28+
string url = "{url}";
29+
private string versionDate = "{versionDate}";
30+
31+
static void Main(string[] args)
32+
{
33+
ServiceExample example = new ServiceExample();
34+
35+
example.Tone();
36+
example.ToneChat();
37+
38+
Console.WriteLine("Examples complete. Press any key to close the application.");
39+
Console.ReadKey();
40+
}
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
99+
}
100+
}

0 commit comments

Comments
 (0)