情感分析不使用其他库

时间:2017-02-18 05:13:24

标签: python twitter sentiment-analysis

我尝试评估推文的分数。除了numpy之外,不允许使用其他python库。这是我试过的:

corpus = {}
with open("corpus.txt") as f:
    value=f.readlines()
    for line in value:
       (key, val) = line.strip("\n").split("\t")
       corpus[key] = int(val)
print(corpus)

{'limited': -1, 'suicidal': -2, 'pardon': 2, 'desirable': 2, 'protest': -2, 'lurking': -1, 'controversial': -2, 'hating': -3, 'ridiculous': -3, 'hate': -3,......} 

sub=('strength reassuring responsible reassuring elation elation dupe dupe')
sub=bag_of_words (sub)
print(sub)

{'dupe': 2, 'elation': 2, 'strength': 1, 'responsible': 1, 'reassuring': 2}

for k,v in sub.iteritems:
    v=v*corpus[k] if k in corpus
print(sub)

score=sum(sub.value())/len(sub)

理想情况下,结果将是:

对于

score=(v1+v2...+vi)/i

任何人都可以帮我弄清楚解决比赛和得分的代码是什么?感谢。

0 个答案:

没有答案