(context, session)
| 46 | |
| 47 | |
| 48 | def onTrigger(context, session): |
| 49 | flow_file = session.get() |
| 50 | if flow_file is not None: |
| 51 | credentials_filename = context.getProperty("Credentials Path") |
| 52 | sentiment = ContentExtract() |
| 53 | session.read(flow_file,sentiment) |
| 54 | client = language.LanguageServiceClient.from_service_account_json(credentials_filename) |
| 55 | document = types.Document(content=sentiment.content,type=enums.Document.Type.PLAIN_TEXT) |
| 56 | |
| 57 | annotations = client.analyze_sentiment(document=document, retry = None,timeout=1.0 ) |
| 58 | score = annotations.document_sentiment.score |
| 59 | magnitude = annotations.document_sentiment.magnitude |
| 60 | |
| 61 | flow_file.addAttribute("score",str(score)) |
| 62 | flow_file.addAttribute("magnitude",str(magnitude)) |
| 63 | session.transfer(flow_file, REL_SUCCESS) |
| 64 |
nothing calls this directly
no test coverage detected