【发布时间】: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
我想获得类似的词类:客观、形容词、动词 - 我该怎么做?
from nltk import corpus
a = ['What', 'is', 'your', 'first', 'and', 'last', 'name', '.']
问题很简单但我不知道nltk?
【问题讨论】:
标签: python python-2.7 nlp nltk
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
【讨论】:
您可以使用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 标记给定的句子列表。
【讨论】: