via this tutorial |10-6-19
from textblob import TextBlob
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 text in positive_alltext:
obj = TextBlob(text)
sentiment = obj.sentiment.polarity
print(sentiment)
for text in negative_alltext:
obj = TextBlob(text)
sentiment = obj.sentiment.polarity
print(sentiment)
negative = os.listdir('NEG/')
positive = os.listdir('POS/')
positive_alltext = []
for file in positive:
f=open('POS/'+file)
content=f.read()
positive_alltext.append(content)
f.close()
negative_alltext = []
for file in negative:
f=open('NEG/'+file)
content=f.read()
negative_alltext.append(content)
f.close()
for text in positive_alltext:
obj = TextBlob(text)
sentiment = obj.sentiment.polarity
print(sentiment)
for text in negative_alltext:
obj = TextBlob(text)
sentiment = obj.sentiment.polarity
print(sentiment)