Skip to content
Snippets Groups Projects
Commit edf62ab1 authored by Austin Frey's avatar Austin Frey Committed by Alex Ellis
Browse files

updated sentiment analysis function to handle multiple sentences and fix decoding issue

Added MakerShift to community.md

Update community.md

commented reload(sys)
parent fbb96463
No related branches found
No related tags found
No related merge requests found
import sys
import json
from textblob import TextBlob
# set default encoding to UTF-8 to eliminate decoding errors
reload(sys)
sys.setdefaultencoding('utf8')
def get_stdin():
buf = ""
for line in sys.stdin:
buf = buf + line
return buf
return buf
if(__name__ == "__main__"):
st = get_stdin()
blob = TextBlob(st)
out =""
res = {
"polarity": 0,
"subjectivity": 0
}
for sentence in blob.sentences:
out = out + "Polarity: " + str(sentence.sentiment.polarity) + " Subjectivity: " + str(sentence.sentiment.subjectivity) + "\n"
print(out)
res["subjectivity"] = res["subjectivity"] + sentence.sentiment.subjectivity
res["polarity"] = res["polarity"] + sentence.sentiment.polarity
total = len(blob.sentences)
res["sentence_count"] = total
res["polarity"] = res["polarity"] / total
res["subjectivity"] = res["subjectivity"] / total
print(json.dumps(res))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment