我正在尝试标记一个句子,并且我相信代码是正确的,但是没有输出。可能是什么问题呢?这是代码。
import nltk
from nltk.tokenize import word_tokenize
text = word_tokenize("And now for something completely different")
nltk.pos_tag(text)
text = word_tokenize("They refuse to permit us to obtain the refuse permit")
nltk.pos_tag(text)
答案 0 :(得分:1)
似乎缺少以下软件包。
注意:您需要首次下载它们。
尝试一下。
import nltk
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')
from nltk.tokenize import word_tokenize
text = word_tokenize("And now for something completely different")
print(nltk.pos_tag(text))
text = word_tokenize("They refuse to permit us to obtain the refuse permit")
print(nltk.pos_tag(text))
print("----End of execution----")