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
@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);
}
@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: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)
{
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:82e841a77514708bae75
Created February 7, 2015 21:38
watson-developer-cloud and restify question answer service example
'use strict'
var wdc = require('watson-developer-cloud-alpha'),
restify = require('restify'),
server = restify.createServer(),
question_and_answer_travel = wdc.question_and_answer({
username: '[user name]',
password: '[password]',
version: 'v1',
dataset: 'travel'
@tankcdr
tankcdr / curltest
Last active August 29, 2015 14:14
Testing watson-developer-cloud and restify sample app
curl -H "Content-Type: application/json" -X POST http://127.0.0.1:8080/travel/ask \
-d '{"question": "Do I need a visa to enter Italy?"}'
@tankcdr
tankcdr / app.js
Created February 9, 2015 13:45
watson-developer-cloud and restify question answer service example that runs on Bluemix
use strict'
var wdc = require('watson-developer-cloud-alpha'),
restify = require('restify'),
server = restify.createServer(),
question_and_answer_travel = wdc.question_and_answer({
version: 'v1',
use_vcap_services: true,
dataset: 'travel'
})
cf create-service question_and_answer question_and_answer_free_plan cmmqa
applications:
- services:
-cmmqa
name: wdctravel
path: .
memory: 128M
use strict'
var wdc = require('watson-developer-cloud-alpha'),
restify = require('restify'),
server = restify.createServer(),
question_and_answer_travel = wdc.question_and_answer({
version: 'v1',
use_vcap_services: true,
dataset: 'travel'
})
server.use(restify.fullResponse())