Skip to content

Instantly share code, notes, and snippets.

View tankcdr's full-sized avatar
🏠
Working from home

Chris Madison tankcdr

🏠
Working from home
View GitHub Profile
private void loadAnswerData(string question)
{
answerData.Clear();
//call Watson
var response = this.qaService.AskQuestion(question);
//parse JSON response
JArray payload = JArray.Parse(response);
//obtain answer items we are interested in
var answerList =
from p in payload[0]["question"]["evidencelist"]
@tankcdr
tankcdr / gist:baa9b9477027a2a2c737
Created January 6, 2015 14:52
AskQuestion-Receiving the response
try
{
WebResponse qaResponse = qaCall.GetResponse();
Stream requestStream = qaResponse.GetResponseStream();
StreamReader responseReader = new StreamReader(requestStream);
answers = responseReader.ReadToEnd();
responseReader.Close();
}
catch (System.Net.WebException e)
{
@tankcdr
tankcdr / gist:f3071f65a92eff274256
Created January 6, 2015 14:50
AskQuestion-Making the call
public string AskQuestion(string question)
{
string answers = null;
string data = "{\"question\" : { \"evidenceRequest\":{\"profile\":\"NO\"},\"questionText\" : \"" + question + "\"}}";
var qaCall = (HttpWebRequest)WebRequest.Create(url);
try
{
string auth = string.Format("{0}:{1}", this.uid, this.pwd);
string auth64 = Convert.ToBase64String(Encoding.ASCII.GetBytes(auth));
string credentials = string.Format("{0} {1}", "Basic", auth64);
@tankcdr
tankcdr / gist:3e78d4c65aa1e753dc55
Created January 6, 2015 14:40
WatsonQA Constructor
public WatsonQA(string corpus, string baseURL, string uid, string pwd)
{
this.url = baseURL + "/v1/question/" + corpus;
this.uid = uid;
this.pwd = pwd;
Console.WriteLine("url:" + this.url);
Console.WriteLine("uid:" + this.uid);
Console.WriteLine("pwd:" + this.pwd);
}