MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / onTrigger

Function onTrigger

extensions/pythonprocessors/google/SentimentAnalyzer.py:48–63  ·  view source on GitHub ↗
(context, session)

Source from the content-addressed store, hash-verified

46
47
48def 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

Callers

nothing calls this directly

Calls 6

ContentExtractClass · 0.70
getMethod · 0.45
getPropertyMethod · 0.45
readMethod · 0.45
addAttributeMethod · 0.45
transferMethod · 0.45

Tested by

no test coverage detected