找出一个句子的意见是肯定的还是否定的 [英] to find the opinion of a sentence as positive or negative

查看:70
本文介绍了找出一个句子的意见是肯定的还是否定的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到网站中给出的某些评论的意见.我为此使用了sentiwordnet.我首先将包含所有评论的文件发送到 POS Tagger.

i need to find the opinion of certain reviews given in websites. i am using sentiwordnet for this. i first send the file containing all the reviews to POS Tagger.

tokens=nltk.word_tokenize(line) #tokenization for line in file
tagged=nltk.pos_tag(tokens) #for POSTagging
print tagged

除了将其视为 2 个单独的单词外,是否还有其他准确的标记方法将其视为 1 个单词.

Is there any other accurate way of tokenizing which considers not good as 1 word other than considering it as 2 separate words.

现在我必须对标记化的单词给出正分和负分,然后计算总分.sentiwordnet 中是否有任何功能.请帮忙.

Now i have to give postive and negative score to the tokenized words and then calculate the total score. Is there any function in sentiwordnet for this. please help.

推荐答案

See First Extract Adverbs and Adjectives from review例如:

See First Extract Adverbs and Adjectives from review for example:

import nltk
from nltk.tokenize import sent_tokenize, word_tokenize
import csv

para = "What can I say about this place. The staff of the restaurant is nice and the eggplant is not bad. Apart from that, very uninspired food, lack of atmosphere and too expensive. I am a staunch vegetarian and was sorely dissapointed with the veggie options on the menu. Will be the last time I visit, I recommend others to avoid"

sentense = word_tokenize(para)
word_features = []

for i,j in nltk.pos_tag(sentense):
    if j in ['JJ', 'JJR', 'JJS', 'RB', 'RBR', 'RBS']: 
        word_features.append(i)

rating = 0

for i in word_features:
    with open('words.txt', 'rt') as f:
        reader = csv.reader(f, delimiter=',')
        for row in reader:
            if i == row[0]:
                print i, row[1]
                if row[1] == 'pos':
                    rating = rating + 1
                elif row[1] == 'neg':
                    rating = rating - 1
print  rating

现在你必须有一个外部的 csv 文件,你应该在其中包含正面和负面的词

Now you must have a external csv file in which you should have positive and negative words

喜欢:皱纹,负皱巴巴的,否定的皱纹,否定巧妙地,pos杰作,pos杰作,pos

like : wrinkle,neg wrinkled,neg wrinkles,neg masterfully,pos masterpiece,pos masterpieces,pos

上述脚本的工作如下:

1.读句子2 .提取副词和形容词3 .与 CVS 的正面和负面词比较4 .然后给句子打分

1 . read sentence 2 . extract adverb and adjectives 3 . compare to CVS for positive and negative words 4 . and then rate the sentence

上述脚本的结果是:

nice pos  
bad neg  
expensive neg  
sorely neg  
-2

根据您的需要更改结果.对不起我的英语:P

change result as per your need. and sorry for my english :P

这篇关于找出一个句子的意见是肯定的还是否定的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆