"entities": [ { "name": "Rowling", "type": "PERSON", "metadata": { "wikipedia_url": "http://en.wikipedia.org/wiki/J._K._Rowling" }, "salience": 0.58328295, "mentions": [ { "text": { "content": "J. K.", "beginOffset": -1 } }, { "text": { "content": "Rowling", "beginOffset": -1 } } ] }, { "name": "LONDON", "type": "LOCATION", "metadata": { "wikipedia_url": "http://en.wikipedia.org/wiki/London" }, "salience": 0.13440432, "mentions": [ { "text": { "content": "LONDON", "beginOffset": -1 } } ] }, { "name": "Harry Potter", "type": "PERSON", "metadata": { "wikipedia_url": "http://en.wikipedia.org/wiki/Harry_Potter" }, "salience": 0.05211971, "mentions": [ { "text": { "content": "Harry Potter", "beginOffset": -1 } }, { "text": { "content": "Harry Potter", "beginOffset": -1 } } ] }]
var requestUrl = "https://language.googleapis.com/v1beta1/documents:analyzeEntities?key=MY_API_K EY" var requestBody = { "document": { "type": "PLAIN_TEXT", "content": nytText } } var options = { url: requestUrl, method: "POST", body: requestBody, json: true } request(options, function(err, resp, body) { if (!err && resp.statusCode == 200) { var entities = body.entities; for (index in entities) { var entity = entities[index]; console.log(entity); } } else { console.log('NL API error: ', err); } }
{ "name": "Rowling", "type": "PERSON", "metadata": { "wikipedia_url": "http://en.wikipedia.org/wiki/J._K._Rowling" }, "salience": 0.58328295, "mentions": [ { "text": { "content": "J. K.", "beginOffset": -1 } }, { "text": { "content": "Rowling", "beginOffset": -1 } } ] }
var gcloud = require('gcloud')({ keyFilename: 'your-keyfile.json', projectId: 'YOUR-PROJECT-ID' }); var bigquery = gcloud.bigquery(); var dataset = bigquery.dataset('your-BigQuery-dataset-name'); var table = dataset.table('your-BigQuery-table-name');
var row = { entity_wiki_url: wiki_url, entity_name: entity.name, entity_type: entity.type, article_section: article.section, article_created_date: article.created_date, article_url: article.url, article_abstract: article.abstract } table.insert(row, function(error, insertError, apiResponse) { if (error || insertErr.length != 0) { // Handle error } else { // Successfully inserted into our table! } });
SELECT entity_wiki_url, COUNT(entity_wiki_url) as entity_count FROM [sara-bigquery:nytdata.entities_from_abstracts] GROUP BY entity_wiki_url ORDER BY entity_count DESC
var sentimentUrl = "https://language.googleapis.com/v1beta1/documents:analyzeSentiment?key=MY_API_ KEY";
{ "documentSentiment": { "polarity": 1, "magnitude": 0.9 } }
{ "documentSentiment": { "polarity": -1, "magnitude": 0.4 } }
SELECT AVG(polarity * magnitude) as avg_sentiment FROM [sara-bigquery:nytdata.article_sentiment]
SELECT section, COUNT(section) as num_articles_per_section, ROUND(AVG(polarity * magnitude), 2) as avg_section_sentiment FROM [sara-bigquery:nytdata.article_sentiment] GROUP BY section ORDER BY num_articles_per_section DESC
0 件のコメント :
コメントを投稿