NLTK在分块之前对令牌进行柠檬化

2024-05-19 21:55:57 发布

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

我现在陷入了这个问题。在

NLTK的分块功能如下:

tokens = nltk.word_tokenize(word)
tagged = nltk.pos_tag(tokens)
chunking = nltk.chunk.ne_chunk(tagged)

在被分块之前,有没有办法用它的标记对令牌进行柠檬化?像

lmtzr.lemmatize('tokens, pos=tagged)

我尝试过将块进行柠檬化,但它不起作用(error说分块是一个列表)。我是python新手,所以我对它的了解不是那么好。任何帮助都将是伟大的!在


Tags: pos功能tag分块wordne柠檬tokenize
1条回答
网友
1楼 · 发布于 2024-05-19 21:55:57

您可以直接lemmatize而不使用pos_tag-

import nltk
from nltk.corpus import wordnet

lmtzr = nltk.WordNetLemmatizer()
word = "Here are words and cars"
tokens = nltk.word_tokenize(word)
token_lemma = [ lmtzr.lemmatize(token) for token in tokens ]
tagged = nltk.pos_tag(token_lemma)
chunking = nltk.chunk.ne_chunk(tagged)

输出

^{pr2}$

相关问题 更多 >