Skip to content

Commit

Permalink
fix(examples): update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkowa committed Nov 12, 2020
1 parent 3fa3309 commit 5e85f39
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 58 deletions.
25 changes: 14 additions & 11 deletions examples/IBM.Watson.Assistant.v1.Examples/ServiceExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -852,24 +852,27 @@ public void UpdateDialogNode()
AssistantService service = new AssistantService("2019-02-28", authenticator);
service.SetServiceUrl("{serviceUrl}");

DialogNodeOutputGenericDialogNodeOutputResponseTypeText typeText =
new DialogNodeOutputGenericDialogNodeOutputResponseTypeText();
typeText.ResponseType = "text";
typeText.Values = new List<DialogNodeOutputTextValuesElement>()
{
new DialogNodeOutputTextValuesElement()
{
Text = "Hello! What can I do for you?"
}
};



var result = service.UpdateDialogNode(
workspaceId: "{workspaceId}",
dialogNode: "greeting",
newOutput: new DialogNodeOutput()
{
Generic = new List<DialogNodeOutputGeneric>()
{
new DialogNodeOutputGeneric()
{
ResponseType = "text",
Values = new List<DialogNodeOutputTextValuesElement>()
{
new DialogNodeOutputTextValuesElement()
{
Text = "Hello! What can I do for you?"
}
}
}
typeText
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void MessageWithContext()
AssistantService service = new AssistantService("2020-04-01", authenticator);
service.SetServiceUrl("{serviceUrl}");

MessageContextSkills skills = new MessageContextSkills();
Dictionary<string, MessageContextSkill> skills = new Dictionary<string, MessageContextSkill>();
MessageContextSkill skill = new MessageContextSkill();
Dictionary<string, object> userDefinedDictionary = new Dictionary<string, object>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void AnalyzeWithMetadata()
url: "www.ibm.com",
features: new Features()
{
Metadata = new MetadataOptions()
Metadata = new FeaturesResultsMetadata()
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,22 @@ public void Profile()
PersonalityInsightsService service = new PersonalityInsightsService("2017-10-13", authenticator);
service.SetServiceUrl("{serviceUrl}");

Content content = null;
content = JsonConvert.DeserializeObject<Content>(File.ReadAllText("profile.json"));

var result = service.Profile(
content: content,
contentType: "application/json",
rawScores: true,
consumptionPreferences: true
);

Console.WriteLine(result.Response);
using (FileStream fs = File.OpenRead("profile.json"))
{
using (MemoryStream ms = new MemoryStream())
{
fs.CopyTo(ms);

var result = service.Profile(
content: ms,
contentType: "application/json",
rawScores: true,
consumptionPreferences: true
);
Console.WriteLine(result.Response);

}
}
}

public void ProfileAsCsv()
Expand All @@ -71,24 +76,28 @@ public void ProfileAsCsv()
apikey: "{apikey}");

PersonalityInsightsService service = new PersonalityInsightsService("2017-10-13", authenticator);
service.SetServiceUrl("{serviceUrl}");

Content content = null;
content = JsonConvert.DeserializeObject<Content>(File.ReadAllText("profile.json"));

var result = service.ProfileAsCsv(
content: content,
contentType: "application/json",
consumptionPreferences: true,
rawScores: true,
csvHeaders: true
);

using (FileStream fs = File.Create("output.csv"))
{
result.Result.WriteTo(fs);
fs.Close();
result.Result.Close();
service.SetServiceUrl("{serviceUrl}");

using (FileStream fs = File.OpenRead("profile.json"))
{
using (MemoryStream ms = new MemoryStream())
{
fs.CopyTo(ms);
var result = service.ProfileAsCsv(
content: ms,
contentType: "application/json",
consumptionPreferences: true,
rawScores: true,
csvHeaders: true
);

using (FileStream fsOutput = File.Create("output.csv"))
{
result.Result.WriteTo(fsOutput);
fsOutput.Close();
result.Result.Close();
}
}
}
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void Recognize()
service.SetServiceUrl("{serviceUrl}");

var result = service.Recognize(
audio: File.ReadAllBytes("audio-file2.flac"),
audio: new MemoryStream(File.ReadAllBytes("audio-file2.flac")),
contentType: "audio/flac",
wordAlternativesThreshold: 0.9f,
keywords: new List<string>()
Expand Down Expand Up @@ -209,7 +209,7 @@ public void CreateJob()
var result = service.CreateJob(
callbackUrl: "http://{user_callback_path}/job_results",
userToken: "job25",
audio: File.ReadAllBytes("audio-file.flac"),
audio: new MemoryStream(File.ReadAllBytes("audio-file.flac")),
contentType: "audio/flac",
timestamps: true
);
Expand Down Expand Up @@ -586,7 +586,7 @@ public void AddGrammar()

var result = service.AddGrammar(
customizationId: "{customizationId}",
grammarFile: File.ReadAllText("list.abnf"),
grammarFile: new MemoryStream(File.ReadAllBytes("list.abnf")),
grammarName: "list-abnf",
contentType: "application/srgs"
);
Expand Down Expand Up @@ -768,7 +768,7 @@ public void AddAudio()
var result = service.AddAudio(
customizationId: "{customizationId}",
contentType: "audio/wav",
audioResource: File.ReadAllBytes("audio1.wav"),
audioResource: new MemoryStream(File.ReadAllBytes("audio1.wav")),
audioName: "audio1"
);

Expand Down
10 changes: 5 additions & 5 deletions examples/IBM.Watson.TextToSpeech.v1.Examples/ServiceExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void ListVoiceModels()
TextToSpeechService service = new TextToSpeechService(authenticator);
service.SetServiceUrl("{serviceUrl}");

var result = service.ListVoiceModels();
var result = service.ListCustomModels();

Console.WriteLine(result.Result);
}
Expand All @@ -152,7 +152,7 @@ public void CreateVoiceModel()
TextToSpeechService service = new TextToSpeechService(authenticator);
service.SetServiceUrl("{serviceUrl}");

var result = service.CreateVoiceModel(
var result = service.CreateCustomModel(
name: "First Model",
language: "en-US",
description: "First custom voice model"
Expand All @@ -171,7 +171,7 @@ public void GetVoiceModel()
TextToSpeechService service = new TextToSpeechService(authenticator);
service.SetServiceUrl("{serviceUrl}");

var result = service.GetVoiceModel(
var result = service.GetCustomModel(
customizationId: "{customizationId}"
);

Expand Down Expand Up @@ -200,7 +200,7 @@ public void UpdateVoiceModel()
}
};

var result = service.UpdateVoiceModel(
var result = service.UpdateCustomModel(
customizationId: "{customizationId}",
name: "First Model Update",
description: "First custom voice model update",
Expand All @@ -218,7 +218,7 @@ public void DeleteVoiceModel()
TextToSpeechService service = new TextToSpeechService(authenticator);
service.SetServiceUrl("{serviceUrl}");

var result = service.DeleteVoiceModel(
var result = service.DeleteCustomModel(
customizationId: "{customizationId}"
);

Expand Down
13 changes: 8 additions & 5 deletions examples/IBM.Watson.ToneAnalyzer.v3.Examples/ServiceExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
using IBM.Watson.ToneAnalyzer.v3.Model;
using System;
using System.Collections.Generic;

using System.IO;
using System.Text;

namespace IBM.Watson.ToneAnalyzer.v3.Examples
{
public class ServiceExample
Expand Down Expand Up @@ -48,10 +50,11 @@ public void Tone()
ToneAnalyzerService service = new ToneAnalyzerService("2017-09-21", authenticator);
service.SetServiceUrl("{serviceUrl}");

ToneInput toneInput = new ToneInput()
{
Text = "Team, I know that times are tough! Product sales have been disappointing for the past three quarters. We have a competitive product, but we need to do a better job of selling it!"
};
byte[] bytes = Encoding.ASCII.GetBytes("Team, I know that times are tough! " +
"Product sales have been disappointing for the past three quarters. " +
"We have a competitive product, but we need to do a better job of selling it!");
MemoryStream toneInput = new MemoryStream(bytes);


var result = service.Tone(
toneInput: toneInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,12 @@ public void GetTrainingUsage()

VisualRecognitionService service = new VisualRecognitionService("2019-02-11", authenticator);

var dateStartTime = DateTime.Parse("2019-01-01");
var dateEndTime = DateTime.Parse("2019-01-31");

var result = service.GetTrainingUsage(
startTime: "2019-01-01",
endTime: "2019-01-31"
startTime: dateStartTime,
endTime: dateEndTime
);

Console.WriteLine(result.Response);
Expand Down

0 comments on commit 5e85f39

Please sign in to comment.