如何在ntlk上单词课?

2024-10-02 12:32:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我想得到像这样的词类:宾语,形容词,动词-我该怎么做?在

from nltk import corpus

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

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


Tags: andnamefromimportyouris动词corpus
2条回答

NLTK为您提供函数post_标记:

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

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

您可以使用^{}模块中的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 Use NLTK’s currently recommended part of speech tagger to tag the given list of tokens.

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

相关问题 更多 >

    热门问题