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 端点的文档页面: Concept Expansion REST API for /result

据我所知,函数中从未传递过 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/