Esempio n. 1
0
def sentiment(comments):

    if not os.path.isfile('classifier.pickle'):
        tcl.training()

    fl = open('classifier.pickle', 'rb')
    classifier = pickle.load(fl)
    fl.close()

    pos = 0
    neg = 0
    for words in comments:
        comment = features(words)
        sentiment_value, confidence = VoteClassifier(classifier).classify(
            comment)
        if sentiment_value == 'positive':  # and confidence * 100 >= 60:
            pos += 1
        else:
            neg += 1

    print("Positive sentiment : ", (pos * 100.0 / len(comments)), "%")
    print("Negative sentiment : ", (neg * 100.0 / len(comments)), "%")

    a = (pos * 100.0 / len(comments))
    b = (neg * 100.0 / len(comments))

    sys.stdout.flush()

    import matplotlib.pyplot as plt

    plt.figure(figsize=[5, 5])
    labels = ["positive", "negative"]
    values = [a, b]
    plt.pie(values, labels=labels)
    plt.show()
def sentiment(comments):

    if not os.path.isfile('classifier.pickle'):
        tcl.training()

    fl = open('classifier.pickle', 'rb')
    classifier = pickle.load(fl)
    fl.close()

    pos = 0
    neg = 0

    for words in comments:
        comment = features(words)
        sentiment_value, confidence = VoteClassifier(classifier).classify(
            comment)
        if sentiment_value == 'positive':  # and confidence * 100 >= 60:
            pos += 1
            userpositive = open("userpositive.txt", "a", encoding="utf-8")
            x = words.split(":", 1)
            userpositive.write(x[0] + "\n")
            userpositive.close()
        else:
            neg += 1
            usernegative = open("usernegative.txt", "a", encoding="utf-8")
            y = words.split(":", 1)
            usernegative.write(y[0] + "\n")
            usernegative.close()

    print("Positive sentiment : ", (pos * 100.0 / len(comments)))
    print("Negative sentiment : ", (neg * 100.0 / len(comments)))
Esempio n. 3
0
def sentiment(comments):

    if not os.path.isfile('/home/faizollah/mysite/classifier.pickle'):
        tcl.training()

    fl = open('/home/faizollah/mysite/classifier.pickle', 'rb')
    classifier = pickle.load(fl)
    fl.close()

    pos = 0
    neg = 0
    for words in comments:
        comment = features(words)
        sentiment_value, confidence = VoteClassifier(classifier).classify(
            comment)
        if sentiment_value == 'positive':  # and confidence * 100 >= 60:
            pos += 1
        else:
            neg += 1

    #print ("Positive sentiment : ", (pos * 100.0 /len(comments)) )
    #print ("Negative sentiment : ", (neg * 100.0 /len(comments)) )
    psent = (pos * 100.0 / len(comments))
    nsent = (neg * 100.0 / len(comments))
    return psent, nsent
def sentiment(comments):

	if not os.path.isfile('classifier.pickle'):
		tcl.training()

	fl = open('classifier.pickle','rb')
	classifier = pickle.load(fl)
	fl.close()

	pos = 0
	neg = 0
	for words in comments:
		comment = features(words)
		sentiment_value, confidence = VoteClassifier(classifier).classify(comment)
        df1['Sentiment']=sentiment_value
		if sentiment_value == 'positive':# and confidence * 100 >= 60:
			pos += 1
		else:
			neg += 1
def sentiment(comments, language):
    if language == 0 and not os.path.isfile('chinese_classifier.pickle'):
        tcl.chinese_training()
    if language == 1 and not os.path.isfile('naive_bayes.pickle'):
        tcl.training()

    if language == 1:
        fl = open('naive_bayes.pickle', 'rb')
    else:
        fl = open('chinese_classifier.pickle', 'rb')

    naive_bayes_classifier = pickle.load(fl)
    fl.close()

    pos = 0
    neg = 0
    count = 0
    for words in comments:
        count += 1
        if language == 1:
            comment = features(words)
        else:
            comment = chinese_features(words)
        voted_classifier = VoteClassifier(naive_bayes_classifier)

        sentiment_value, confidence = voted_classifier.classify(comment)
        #if count <= 20:
        #print(count, sentiment_value, confidence)
        if sentiment_value == 'positive':  # and confidence * 100 >= 60:
            pos += 1
        else:
            neg += 1

    output = []
    output.append("Positive sentiment : " +
                  str(int(pos * 100.0 / len(comments))))
    output.append("Negative sentiment : " +
                  str(int(neg * 100.0 / len(comments))))
    return output
Esempio n. 6
0
def sentiment(comments):

    if not os.path.isfile('classifier.pickle'):
        tcl.training()

    fl = open('classifier.pickle', 'rb')
    classifier = pickle.load(fl)
    fl.close()

    pos = 0
    neg = 0
    for words in comments:
        # print(words)
        comment = features(words)
        sentiment_value, confidence = VoteClassifier(classifier).classify(
            comment)
        if sentiment_value == 'positive':  # and confidence * 100 >= 60:
            pos += 1
        else:
            neg += 1

    print("\nPositive sentiment : ", (pos * 100.0 / len(comments)))
    print("\nNegative sentiment : ", (neg * 100.0 / len(comments)))
def sentiment(comments):
    if not os.path.isfile('CommentSentimentData/classifier.pkl'):
        tcl.training()

    fl = open('CommentSentimentData/classifier.pkl', 'rb')
    classifier = pickle.load(fl)
    fl.close()

    with open('CommentSentimentData/bestwords.pkl', 'rb') as f:
        best_words = pickle.load(f)

    pos = 0
    neg = 0
    for words in comments:
        comment = features(words, best_words)
        sentiment_value, confidence = VoteClassifier(classifier).classify(
            comment)
        if sentiment_value == 'positive':  # and confidence * 100 >= 60:
            pos += 1
        else:
            neg += 1

    print("Positive sentiment : ", (pos * 100.0 / len(comments)))
    print("Negative sentiment : ", (neg * 100.0 / len(comments)))