簡體   English   中英

Bluemix:Node.js + Watson概念擴展API

[英]Bluemix: Node.js + Watson Concept Expansion API

我正在嘗試使用IBM DevOps Services的CE文檔頁面上列出的Watson Concept Expansion示例應用程序。

該應用嘗試檢索結果時會生成錯誤,我想我明白了原因,但不確定如何處理:

以下是用於檢索結果的適用代碼:

 // Get the job result by calling PUT to '/result' with the jobid var job_result_async = function(jobid, onSuccess, onError) { // create a new map with the defaault https params var params = extend({},default_params); params.path += '/result'; params.method = 'PUT'; var watson_req = https.request(params, function(result) { var response_string = ''; result.on('data', function(chunk) { response_string += chunk; }); result.on('end', function() { var result_json = JSON.parse(response_string); // format results if exists if (util.isArray(result_json.return_seeds)) { var result_clean = result_json.return_seeds.map(function(e) { return { 'result' : clean_string(e.result), 'prevalence': e.prevalence } }); result_json.return_seeds = result_clean; } onSuccess(result_json); }) }); watson_req.on('error', function(e) { onError(e) }); // send the data watson_req.write(JSON.stringify({'jobid': jobid})); watson_req.end(); }; 

這是/ result REST API端點的文檔頁面:/ result的概念擴展REST API

據我所知,在函數中從未傳遞Jobid。 我懷疑這是問題所在,但是如果有人可以確認這一點很好,而且我也不清楚如何將Jobid傳遞給/ result API以能夠檢索結果。

感謝您的協助! -安迪

您幾天前嘗試使用該服務時遇到了問題。 查看您的代碼,它應該可以工作。 如果您想嘗試該服務,則可以使用watson-developer-cloud npm模塊,如下所述:

var watson = require('watson-developer-cloud');

var concept_expansion = watson.concept_expansion({
  username: '<username>',
  password: '<password>',
  version: 'v1'
});

var params = {
  seeds: ['motrin','tylenol','aspirin'],
  dataset: 'mtsamples',
  label: 'medications'
};

concept_expansion.expand(params, function (err, response) {
  if (err)
    console.log('error:', err);
  else
    console.log(JSON.stringify(response, null, 2));
});

我運行上面的代碼並得到:

{
  "return_seeds": [
    {
      "prevalence": "2.803636",
      "result": "penicillin"
    },
    {
      "prevalence": "2.748252",
      "result": "plan: 1"
    },
    {
      "prevalence": "2.685714",
      "result": "actos"
    },
    {
      "prevalence": "2.670330",
      "result": "lipitor"
    },
    {
      "prevalence": "2.649351",
      "result": "zocor"
    },
    {
      "prevalence": "1.400000",
      "result": "ibuprofen 200 mg three pills"
    },
    ...
  ]
}

概念擴展演示: http//watson-ce-demo.mybluemix.net/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM