您好我正在尝试使用情感分类器包对某些文本文件进行分类。以下程序适用于单句,即。
from senti_classifier import senti_classifier
sentences = ['i love u']
pos_score, neg_score = senti_classifier.polarity_scores(sentences)
print pos_score, neg_score
但是当通过使用xls文件对每条记录进行分类时,通过以下方式完成,结果对于正面和负面分数都是0.0。 请帮帮我。
import openpyxl
from senti_classifier import senti_classifier
wb = openpyxl.load_workbook('sentiment2.xlsx')
sheet = wb.active
sheet.columns[0]
for cellObj in sheet.columns[0]:
sentences = cellObj.value
print(sentences)
pos_score, neg_score = senti_classifier.polarity_scores(sentences)
print pos_score, neg_score
答案 0 :(得分:1)
senti_classifier.polarity_scores()
function期望字符串列表作为参数,但是您传递的是一个字符串。把它放到列表中:
pos_score, neg_score = senti_classifier.polarity_scores([sentences])