Python SentiStrength 二进制分数仅输出 1 个分数

Python SentiStrength binary score outputs only 1 score

我目前正在通过命令 result = senti.getSentiment(cs, score='binary') 使用 SentiStrength python 库进行文本分析。首先,我在 Jupyter notebook 中 运行 它并且运行良好。它输出 2 个分数,分别是正面和负面的情绪分数,例如 [(2,-1)]。但是,当我尝试在 anaconda 提示符或 spyder 中 运行 它时。它只输出 1 个值,如 [1],我不明白为什么。我想这是因为我 运行 它在不同的环境中。我想问一下如何在anaconda提示符或其他IDE中运行这个命令才能正确输出结果?还是我做错了什么。

    if score == 'scale': # Returns from -1 to 1
        senti_score = [sum(senti_score[i:i+2])/4 for i in range(0, len(senti_score), 3)]
    elif score == 'binary': # Return 1 if positive and -1 if negative
        senti_score = [1 if senti_score[i] >= abs(senti_score[i+1]) else -1 for i in range(0, len(senti_score), 3)]
    elif score == 'trinary': # Return Positive and Negative Score and Neutral Score
        senti_score = [tuple(senti_score[i:i+3]) for i in range(0, len(senti_score), 3)]
    elif score == 'dual': # Return Positive and Negative Score
        senti_score = [tuple(senti_score[i:i+2]) for i in range(0, len(senti_score), 3)]
    else:
        return "Argument 'score' takes in either 'scale' (between -1 to 1) or 'binary' (two scores, positive and negative rating)"
    return senti_score

遇到了同样的问题,查看源代码发现文档错误。您应该使用 'dual' 作为分数类型。