MCPcopy Create free account
hub / github.com/GonVas/tickerrain / nlp_processing

Function nlp_processing

test.py:115–139  ·  view source on GitHub ↗
(row, ret_doc=False)

Source from the content-addressed store, hash-verified

113
114
115def nlp_processing(row, ret_doc=False):
116 tickers_ment = row['tickers']
117
118 if(len(tickers_ment) == 0):
119 return None, None
120
121 sentence = row['body'].strip()
122
123 tk_spans = []
124
125 doc = nlp(sentence)
126
127 sid = SentimentIntensityAnalyzer()
128 sentiment = sid.polarity_scores(doc.text)
129
130 if(len(tickers_ment) > 1):
131 for ticker in tickers_ment:
132 pos = doc.text.find(ticker)
133 span = doc.char_span(pos, pos + len(ticker), label="ORG")
134 try:
135 doc.ents = [span if e.text == ticker else e for e in doc.ents]
136 except Exception as e:
137 print(e)
138
139 return doc, sentiment
140
141
142def filter_hour(row, day=2):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected