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

Function nlp_processing

process.py:173–197  ·  view source on GitHub ↗
(row, ret_doc=False)

Source from the content-addressed store, hash-verified

171nlp = spacy.load("en_core_web_lg")
172
173def nlp_processing(row, ret_doc=False):
174 tickers_ment = row['tickers']
175
176 if(len(tickers_ment) == 0):
177 return None, None
178
179 sentence = row['body'].strip()
180
181 tk_spans = []
182
183 doc = nlp(sentence)
184
185 sid = SentimentIntensityAnalyzer()
186 sentiment = sid.polarity_scores(doc.text)
187
188 if(len(tickers_ment) > 1):
189 for ticker in tickers_ment:
190 pos = doc.text.find(ticker)
191 span = doc.char_span(pos, pos + len(ticker), label="ORG")
192 try:
193 doc.ents = [span if e.text == ticker else e for e in doc.ents]
194 except Exception as e:
195 print(e)
196
197 return doc, sentiment
198
199def sum_(x):
200 return sum(x)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected