Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
'''
Text Classifier
available classifiers in Texblob.classifies:
DecisionTreeClassifier
MaxEntClassifier
NaiveBayesClassifier
PositiveNaiveBayesClassifier
'''
#dataset from : https://www.kaggle.com/marklvl/sentiment-labelled-sentences-data-set/home
'''
def format_data():
#---This funtion is used to label sentences and should be ran once
import pandas as pd
import pickle
training_data=[]
dataset =pd.read_csv('data.csv')
content=dataset['content']
value=dataset['value']
text_list=[]
value_list=[]
training_data=[]
for text in content:
text_list.append(text)
for review in value:
value_list.append(str(review))
n=0
while n<len(text_list):
training_data.append((text_list[n],value[n])) #-- Creating turples
#-- because textblob classify want require them in this form
n=n+1
pickle.dump(training_data,open('training_data.p','wb'))
return training_data
'''
from textblob.classifiers import NaiveBayesClassifier
import pickle
def classify_text(text_to_classify):
train=pickle.load(open('training_data.p','rb'))
TESS_classify=NaiveBayesClassifier(train)
sentiment=(TESS_classify.classify(text_to_classify))
return sentiment
while True:
user=input('Enter some text and i will tell you if it is positive or not. Bear in mind i do not understand sarcasm yet > ').lower()
if user=='q':
print('exiting')
break
else:
if classify_text(user)==1:
print('positive sentence')
elif classify_text(user)==0 :
print('negative sentence')