【问题标题】:Bluemix Node.js Watson Relationship Extraction using watson-developer-cloud moduleBluemix Node.js Watson 关系提取使用 watson-developer-cloud 模块
【发布时间】:2015-05-30 20:30:56
【问题描述】:

模块似乎坏了,尝试最简单的测试会导致错误。

我的代码:

var express = require('express'),
    app = express(),
    http = require('http'),
    util = require('util'),
    bluemix = require('./config/bluemix'),
    watson = require('watson-developer-cloud'),
    extend = require('util')._extend;

app.use(express.static(__dirname + '/public')); 
app.set('view engine', 'jade');
app.set('views', __dirname + '/views'); 

var port = process.env.PORT || 3000;

var credentials = extend({
  version: 'v1',
  username: '<username>',
  password: '<password>'
}, bluemix.getServiceCreds('relationship_extraction')); // VCAP_SERVICES


var watson_relation = watson.relationship_extraction({
      username: credentials.username,
      password: credentials.password,
      version: 'v1'
});


app.get('/', function(req, res){
    res.render('index');
});


app.get('/extract', function(req, res){
    //var qtext = req.query['qtext'];
    //console.log('qtext=' + qtext);

    watson_relation.extract({
        text: 'IBM Watson developer cloud',
        dataset: 'ie-en-news' },
        function (err, response) {
            if (err)
                console.log('error:', err);
            else
                console.log(JSON.stringify(response, null, 2));
    });

});

var server = require('http').createServer(app);

server.listen(port, function(){
    console.log('Express server listening on port ' + port);
    console.log('To view the example, point your favorite browser to: localhost:3000');
});

日志中的结果:

错误:[错误:结果格式错误]

该服务的旧 REST API 版本似乎运行良好,只是这个版本使用了 watson-developer-cloud 模块。

有人有什么想法吗?

【问题讨论】:

  • 关系提取服务更改了响应格式,包装器无法解析新的。我已经创建了一个问题 (github.com/watson-developer-cloud/nodejs-wrapper/issues/20) 并将着手解决这个问题。一旦 npm 模块更新,我会通知您。
  • 明白了,谢谢!我不介意同时使用 REST 版本...

标签: node.js ibm-cloud ibm-watson


【解决方案1】:

我修复了issue。该服务现在接受 format,它可以是 xmljson(默认情况下)
为了测试您可以执行的服务:

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

var relationship_extraction = watson.relationship_extraction({
  username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
  password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE',
  version: 'v1'
});

relationship_extraction.extract({
  text: 'IBM Watson developer cloud',
  dataset: 'ie-en-news' },
  function (err, response) {
    if (err)
      console.log('error:', err);
    else
      console.log(JSON.stringify(response, null, 2));
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多