1

現在、watson-developer-cloud Node.js SDKを使用してNode.jsと作業しています。エンティティを含む。Node.js(watson-developer-cloudモジュール)を使用したAlchemyData Newsクエリの送信

これは私のコードです:

// require watson's node sdk and fs 
var watson = require('watson-developer-cloud'); 
var fs = require('fs'); 

// Define output file 
var outputJSONFile = '/home/vagrant/Desktop/node/dir/data.json'; 

// Create alchemy_data_news object using our api_key 
var alchemy_data_news = watson.alchemy_data_news({ 
    api_key: '' 
}); 

// Define params for the query and what values to return 
// Accepted returne values: 
// docs.alchemyapi.com/v1.0/docs/full-list-of-supported-news-api-fields 
var params = { 
    start: 'now-1m', 
    end: 'now', 
    count: 2, 
    qs: ['q.enriched.url.enrichedTitle.entities.entity.text=apple'], 
    return: ['enriched.url.url,enriched.url.title'] 
}; 

// Call getNews method and return json 
alchemy_data_news.getNews(params, function (err, news) { 
    if (err) { 
    console.log('error:', err); 
    } else { 
    fs.writeFile(outputJSONFile, JSON.stringify(news, null, 2), function(err) { 
     if (err) { 
     console.log('WriteFile Error:', err); 
     } else { 
     console.log("JSON saved to " + outputJSONFile); 
     } 
    }); 
    } 
}); 

私はまだのparamsオブジェクトを使用してエンティティのパラメータを送信する方法を把握しようとしています。

私はqsに出くわしたので、テストするために使ってきましたが、私は全く成功しませんでした。

ご意見をいただければ幸いです。

PS:私は合格しようとしている:
q.enriched.url.enrichedTitle.entities.entity.text =リンゴ q.enriched.url.enrichedTitle.entities.entity.type =会社を

+0

コードが正しく動作するようになりました。この変更と同じように思え: のvarのparams = { ... を... 「q.enriched.url.enrichedTitleを.entity.entity.text ':' Apple '、 ' q.enriched.url.enrichedTitle.entities.entity.type ':' company '、 ... }; もっと良い方法がある場合は、教えてください。ありがとう! – Paul

答えて

2

node-sdk source code for AlchemyDataNewsを見ると、トップレベルのパラメータがクエリ文字列として送信されていることがわかります。
その後paramsマップは次のようになります。

var params = { 
    start: 'now-1m', 
    end: 'now', 
    count: 2, 
    return: ['enriched.url.url,enriched.url.title'], 
    // fields here 
    'q.enriched.url.enrichedTitle.entities.entity.text': 'apple', 
    'q.enriched.url.enrichedTitle.entities.entity.type': 'company' 
}; 
+0

ありがとうございました! – Paul

関連する問題