【问题标题】:POS tagging base form of noun词性标注名词的基本形式
【发布时间】:2014-07-13 12:17:19
【问题描述】:

我想根据任何形式的名词的存在来搜索句子。当我查看非常大的文本并搜索名词 NN、NNS、NNPS、NNS(可能还有其他)的所有不同的 POS 标签排列时,处理成为一个问题。因此,我的问题是 NN 是否是所有其他名词变体的基本形式,以及我是否可以只搜索 NN。这同样适用于副词、代词和动词。 POS标签有基本形式吗?

【问题讨论】:

    标签: nltk


    【解决方案1】:

    POS 标签没有基本形式。更糟糕的是,对于英语的 POS 标签没有普遍的共识。然而,一些标准确实有一定的模式,而且它们通常是相当小的集合。

    根据您提供的列表 (NN,NNS,NNPS,NNS),您可能正在使用 Penn Treebank (PTB) 集。它也是最常用的一种。 PTB 中的所有名词标签都以“NN”开头。

    您可以在此处找到 PTB 中的 POS 标签列表:https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html

    为了比较,这里是 Brown POS 标签集:http://en.wikipedia.org/wiki/Brown_Corpus#Part-of-speech_tags_used。在这种情况下,它们并不都以 NN 开头。

    【讨论】:

      【解决方案2】:

      NLTK 的pos_tag 使用的 PennTree Bank (PTB) 标记集对于名词和动词有些分层。您可以使用标签的第一个字符来查看它是名词还是动词。

      试试这个:

      >>> from nltk import word_tokenize, pos_tag
      >>> sent = 'this is a foo bar sentence with many nouns talking to blah blah black sheep.'
      >>> pos_tag(word_tokenize(sent))
      [('this', 'DT'), ('is', 'VBZ'), ('a', 'DT'), ('foo', 'NN'), ('bar', 'NN'), ('sentence', 'NN'), ('with', 'IN'), ('many', 'JJ'), ('nouns', 'NNS'), ('talking', 'VBG'), ('to', 'TO'), ('blah', 'VB'), ('blah', 'NN'), ('black', 'NN'), ('sheep', 'NN'), ('.', '.')]
      >>> token_pos = []
      >>> for token, pos in pos_tag(word_tokenize(sent)):
      ...     if pos[0] in ['N', 'V']:
      ...             pos = 'noun' if pos[0] == 'N' else 'verb'
      ...     token_pos.append((token, pos))
      ... 
      >>> token_pos
      [('this', 'DT'), ('is', 'verb'), ('a', 'DT'), ('foo', 'noun'), ('bar', 'noun'), ('sentence', 'noun'), ('with', 'IN'), ('many', 'JJ'), ('nouns', 'noun'), ('talking', 'verb'), ('to', 'TO'), ('blah', 'verb'), ('blah', 'noun'), ('black', 'noun'), ('sheep', 'noun'), ('.', '.')]
      >>> [i for i in token_pos if i[1] == 'noun']
      [('foo', 'noun'), ('bar', 'noun'), ('sentence', 'noun'), ('nouns', 'noun'), ('blah', 'noun'), ('black', 'noun'), ('sheep', 'noun')]
      >>> [i for i in token_pos if i[1] == 'verb']
      [('is', 'verb'), ('talking', 'verb'), ('blah', 'verb')]
      

      【讨论】:

        【解决方案3】:

        您还可以使用以下代码简化斯坦福词性标签:

        text = nltk.word_tokenize("And now for something completely different")
        posTagged = pos_tag(text)
        
        print posTagged
        
        simplifiedTags = [(word, map_tag('en-ptb', 'universal', tag)) for word, tag in posTagged]
        print(simplifiedTags)
        

        产量:

        [('And', u'CONJ'), ('now', u'ADV'), ('for', u'ADP'), ('something', u'NOUN'), ('completely', u'ADV'), ('different', u'ADJ')]
        

        通过 SO 上的this question

        【讨论】:

          猜你喜欢
          • 2012-11-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-02-26
          • 1970-01-01
          • 2016-07-25
          相关资源
          最近更新 更多