(via these docs) | 10-06-19
from nltk.sentiment.vader import SentimentIntensityAnalyzer
sid = SentimentIntensityAnalyzer()
import os
import pandas as pd
negative = os.listdir('AI_NEG/')
positive = os.listdir('AI_POS/')
positive_alltext = []
for file in positive:
f=open('AI_POS/'+file)
content=f.read()
positive_alltext.append(content)
f.close()
negative_alltext = []
for file in negative:
f=open('AI_NEG/'+file)
content=f.read()
negative_alltext.append(content)
f.close()
for sentence in positive_alltext:
print(sentence)
ss = sid.polarity_scores(sentence)
for k in sorted(ss):
print('{0}: {1}, '.format(k, ss[k]), end="")
print()
for sentence in negative_alltext:
print(sentence)
ss = sid.polarity_scores(sentence)
for k in sorted(ss):
print('{0}: {1}, '.format(k, ss[k]), end="")
print()