Last active
November 21, 2019 05:42
-
-
Save shinchit/493a41c1420027688649cd5c6a66ca6d to your computer and use it in GitHub Desktop.
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
const language = require('@google-cloud/language'); | |
async function isPositive(text) { | |
// If you want to know detail of LanguageServiceClient, | |
// See also | |
// https://cloud.google.com/natural-language/docs/basics#interpreting_sentiment_analysis_values | |
const lsclient = new language.LanguageServiceClient(); | |
const document = { | |
content: text, | |
type: 'PLAIN_TEXT', | |
}; | |
// The value returned by the then function can be received in a variable with await. | |
let sentiment = await lsclient.analyzeSentiment({document}) | |
.then(([result]) => { | |
const sentiment = result.documentSentiment; | |
return sentiment; | |
}) | |
.catch((err) => { | |
throw err; | |
}); | |
if (sentiment.score > 0.0) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
let positive = await isPositive('I love you'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment