Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NewsHeadlineListener in cli #28

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions sentiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@ def __init__(self, url=None, frequency=120):
print("\n------------------------------> (news headlines: %s, filtered: %s, filter-ratio: %s)" \
% (self.count, self.count_filtered, str(round(self.count_filtered/self.count*100,2))+"%"))
print("Date: " + datenow)
print("News Headline: " + htext)
print("News Headline: " + htext.string)
print("Location (url): " + htext_url)

# create tokens of words in text using nltk
text_for_tokens = re.sub(
r"[\%|\$|\.|\,|\!|\:|\@]|\(|\)|\#|\+|(``)|('')|\?|\-", "", htext)
r"[\%|\$|\.|\,|\!|\:|\@]|\(|\)|\#|\+|(``)|('')|\?|\-", "", htext.string)
tokens = nltk.word_tokenize(text_for_tokens)
print("NLTK Tokens: " + str(tokens))

Expand All @@ -308,20 +308,22 @@ def __init__(self, url=None, frequency=120):
logger.info("Text contains token from ignore list, not adding")
self.count_filtered+=1
continue
# check required tokens from config
tokenspass = False
for t in nltk_tokens_required:
if t in tokens:
tokenspass = True
break
if not tokenspass:
logger.info("Text does not contain token from required list, not adding")
self.count_filtered+=1
continue

# Comment reason: for headlines, filtering based on the tokens is not required since the URL is already queried using the given symbol
# # check required tokens from config
# tokenspass = False
# for t in nltk_tokens_required:
# if t in tokens:
# tokenspass = True
# break
# if not tokenspass:
# logger.info("Text does not contain token from required list, not adding")
# self.count_filtered+=1
# continue

# get sentiment values
polarity, subjectivity, sentiment = sentiment_analysis(htext)

polarity, subjectivity, sentiment = sentiment_analysis(htext.string)
logger.info("Adding news headline to elasticsearch")
# add news headline data and sentiment info to elasticsearch
es.index(index=args.index,
Expand Down