2015-03-31 33 views
3

我需要一点点帮助在这里,我需要找出否定词,如“不好”,“不坏”,然后确定极性的sentiment.I的(正或负)做了除了处理否定之外的所有事情。我只是想知道我可以如何包含否定。我该怎么办呢?否定处理

谢谢。

回答

0

它已经有一段时间,因为我已经在情感分析的工作,所以不知道这方面的情况是什么,现在,在任何情况下,我从来没有使用NLTK这一点。所以我不能指出你有什么。但总的来说,我认为可以肯定地说这是一个活跃的研究领域,也是NLP的重要组成部分。而且这肯定不是已经被“解决”的问题。它是NLP中更精细,更有趣的领域之一,涉及反讽,讽刺,范围(否定)。通常,提出正确的分析意味着解释大量的上下文/领域/话语信息。这根本不简单。 你可能想看看这个话题:Can an algorithm detect sarcasm。一些谷歌搜索可能会给你更多的信息。

总之;你的问题太广泛了,不能提出具体的答案。

而且,我不知道你的意思:“我所做的一切,除了处理否定”的内容。你的意思是你确定了'消极'的话?你是否认为这些信息比单词not,no等传达得更多?考虑例如“你的解决方案不好”与“你的解决方案不理想”。 你究竟在寻找什么,在你的情况下什么能够满足,显然取决于上下文和应用领域。 这可能不是你所希望看到的答案,但我建议你做一个多一点的研究(如很多聪明的东西都被聪明的人在这一领域已经完成)。

+0

对不起的是非常vague.I很新的这个领域和我的全部,而无需任何挖苦她输入一些简单的句子,当现在越来越积极和消极情绪/ irony.Right现在,我正在寻找包括一些常见的否定,不涉及我的代码。这是我到现在为止。 – user1565960 2015-04-03 15:31:33

4

否定的处理是一个相当广泛的领域,有许多不同的潜在的实现。在这里,我可以提供示例代码,用于排除文本序列,并在not_表单中存储否定uni/bi/trigrams。请注意,这里不使用nltk来支持简单的文本处理。

# negate_sequence(text) 
# text: sentence to process (creation of uni/bi/trigrams 
# is handled here) 
# 
# Detects negations and transforms negated words into 'not_' form 
# 
def negate_sequence(text): 
    negation = False 
    delims = "?.,!:;" 
    result = [] 
    words = text.split() 
    prev = None 
    pprev = None 
    for word in words: 
     stripped = word.strip(delims).lower() 
     negated = "not_" + stripped if negation else stripped 
     result.append(negated) 
     if prev: 
      bigram = prev + " " + negated 
      result.append(bigram) 
      if pprev: 
       trigram = pprev + " " + bigram 
       result.append(trigram) 
      pprev = prev 
     prev = negated 

     if any(neg in word for neg in ["not", "n't", "no"]): 
      negation = not negation 

     if any(c in word for c in delims): 
      negation = False 

    return result 

如果我们在样品输入text = "I am not happy today, and I am not feeling well"运行该程序,我们得到unigram进行,二元语法的以下序列,和卦:

[ 'i', 
    'am', 
    'i am', 
    'not', 
    'am not', 
    'i am not', 
    'not_happy', 
    'not not_happy', 
    'am not not_happy', 
    'not_today', 
    'not_happy not_today', 
    'not not_happy not_today', 
    'and', 
    'not_today and', 
    'not_happy not_today and', 
    'i', 
    'and i', 
    'not_today and i', 
    'am', 
    'i am', 
    'and i am', 
    'not', 
    'am not', 
    'i am not', 
    'not_feeling', 
    'not not_feeling', 
    'am not not_feeling', 
    'not_well', 
    'not_feeling not_well', 
    'not not_feeling not_well'] 

我们可以随后这些卦保存以备将来retreival阵列和分析。将not_字处理为您为其对应方定义的[情感,极性]的否定。