This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try | |
{ | |
WebResponse qaResponse = qaCall.GetResponse(); | |
Stream requestStream = qaResponse.GetResponseStream(); | |
StreamReader responseReader = new StreamReader(requestStream); | |
answers = responseReader.ReadToEnd(); | |
responseReader.Close(); | |
} | |
catch (System.Net.WebException e) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cf create-service question_and_answer question_and_answer_free_plan cmmqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
applications: | |
- services: | |
-cmmqa | |
name: wdctravel | |
path: . | |
memory: 128M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
OlderNewer