|
| 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