Created
December 9, 2019 16:10
-
-
Save micseydel/aa4b79ba5a8814bdcc54d713e1853ef1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
from urllib.request import urlopen | |
# python3 -m pip install --user textblob | |
# python3 -m textblob.download_corpora | |
from textblob import TextBlob | |
def relevant_words(): | |
# https://github.com/dwyl/english-words/blob/master/words.txt | |
resp = urlopen("https://raw.githubusercontent.com/dwyl/english-words/master/words.txt") | |
for word in resp: | |
if word.startswith((b'dis', b'de')): | |
yield word.decode() | |
positive = 0 | |
negative = 0 | |
neutral = 0 | |
for word in relevant_words(): | |
analysis = TextBlob(word) | |
if analysis.sentiment.polarity > 0: | |
positive += 1 | |
elif analysis.sentiment.polarity == 0: | |
neutral += 1 | |
else: | |
negative += 1 | |
total = positive + neutral + negative | |
print("Positive: {:.1f}%".format(positive / total * 100)) | |
print("Negative: {:.1f}%".format(negative / total * 100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment