Created
December 7, 2018 13:02
-
-
Save jgwill/74dda2287c58eb813ff65df8f08c786c to your computer and use it in GitHub Desktop.
@stcgoal Learn the sentiment of a string using Google Cloud Language API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Imports the Google Cloud client library | |
const language = require('@google-cloud/language'); | |
// Instantiates a client | |
const client = new language.LanguageServiceClient(); | |
// The text to analyze | |
const text = 'Afelia stopped working and is crashed!'; | |
const document = { | |
content: text, | |
type: 'PLAIN_TEXT', | |
}; | |
// Detects the sentiment of the text | |
client | |
.analyzeSentiment({ document: document }) | |
.then(results => { | |
const sentiment = results[0].documentSentiment; | |
console.log(`Text: ${text}`); | |
console.log(`Sentiment score: ${sentiment.score}`); | |
console.log(`Sentiment magnitude: ${sentiment.magnitude}`); | |
}) | |
.catch(err => { | |
console.error('ERROR:', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment