【问题标题】:How to take word class in ntlk?如何在 nltk 中学习单词类?
【发布时间】:2015-03-07 22:27:58
【问题描述】:

我想获得类似的词类:客观、形容词、动词 - 我该怎么做?

from nltk import corpus

a = ['What', 'is', 'your', 'first', 'and', 'last', 'name', '.']

问题很简单但我不知道nltk?

【问题讨论】:

    标签: python python-2.7 nlp nltk


    【解决方案1】:

    NLTK 为您提供 post_tag 函数:

    import nltk
    text = nltk.word_tokenize("What is your first and last name.")
    pos_tags = nltk.pos_tag(text)
    

    您可以在此处查看 pos_tag 结果的含义: https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html

    【讨论】:

      【解决方案2】:

      您可以使用nltk.tag 模块中的pos_tag 函数:

      >>> from nltk.tag import pos_tag
      >>> a = ['What', 'is', 'your', 'first', 'and', 'last', 'name', '.']
      >>> pos_tUse NLTK’s currently recommended part of speech tagger to tag the given list of tokens.ag(a) 
      [('What', 'WP'), ('is', 'VBZ'), ('your', 'PRP$'), ('first', 'JJ'), ('and', 'CC'), ('last', 'JJ'), ('name', 'NN'), ('.', '.')]
      

      pos_tag 使用 NLTK 目前推荐的词性标记器来标记给定的标记列表。

      您也可以使用pos_tag_sents 标记给定的句子列表。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-08-05
        • 1970-01-01
        • 1970-01-01
        • 2014-02-03
        • 2015-03-17
        • 1970-01-01
        • 2018-02-04
        相关资源
        最近更新 更多