Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from google.cloud import language
- from google.cloud.language import enums
- from google.cloud.language import types
- def get_sentiment_entity(document):
- output = {}
- client = language.LanguageServiceClient()
- document = types.Document(
- content=document,
- type=enums.Document.Type.PLAIN_TEXT)
- sentiment = client.analyze_sentiment(document=document).document_sentiment
- output["doc_sent"] = sentiment.score
- output["doc_mag"] = sentiment.magnitude
- entities = client.analyze_entity_sentiment(document=document)
- output['entities'] = list(set([e.name for e in entities.entities if (abs(e.sentiment.score >0))]))
- return output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement