Created
January 8, 2019 11:20
-
-
Save TudorGruian/53fd9991dbdcb17f3146b77b3a877e74 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
from google.cloud import language_v1 | |
from google.cloud.language_v1 import enums | |
import six | |
def sample_analyze_sentiment(content): | |
client = language_v1.LanguageServiceClient() | |
# content = 'Your text to analyze, e.g. Hello, world!' | |
if isinstance(content, six.binary_type): | |
content = content.decode('utf-8') | |
type_ = enums.Document.Type.PLAIN_TEXT | |
document = {'type': type_, 'content': content} | |
response = client.analyze_sentiment(document) | |
sentiment = response.document_sentiment | |
print('Score: {}'.format(sentiment.score)) | |
print('Magnitude: {}'.format(sentiment.magnitude)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment