python - 使用 nltk 和 wordnet 对复数名词进行词形还原

标签 python nltk wordnet lemmatization

我想使用 lemmatize

from nltk import word_tokenize, sent_tokenize, pos_tag
from nltk.stem.wordnet import WordNetLemmatizer
from nltk.corpus import wordnet
lmtzr = WordNetLemmatizer()
POS = pos_tag(text)

def get_wordnet_pos(treebank_tag):
        #maps pos tag so lemmatizer understands
        from nltk.corpus import wordnet
        if treebank_tag.startswith('J'):
            return wordnet.ADJ
        elif treebank_tag.startswith('V'):
            return wordnet.VERB
        elif treebank_tag.startswith('N'):
            return wordnet.NOUN
        elif treebank_tag.startswith('R'):
            return wordnet.ADV
        else:
            return wordnet.NOUN
 lmtzr.lemmatize(text[i], get_wordnet_pos(POS[i][1]))

问题是词性标注器得到“procaspases”是“NNS”,但我如何将 NNS 转换为 wordnet,因为“procaspases”即使在词形还原器之后仍然是“procaspaseS”。

最佳答案

NLTK 处理大多数复数形式,而不仅仅是删除结尾的“s”。

import nltk
from nltk.stem.wordnet import WordNetLemmatizer

Lem = WordNetLemmatizer()

phrase = 'cobblers ants women boys needs finds binaries hobbies busses wolves'

words = phrase.split()
for word in words :
  lemword = Lem.lemmatize(word)
  print(lemword)

输出: cobbler ant woman boy need find binary hobby bus wolf

关于python - 使用 nltk 和 wordnet 对复数名词进行词形还原,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31016540/

相关文章:

python - 从解析结果中提取语法规则

php - 使用 WordNet 创建一个简单的字典

python - 使用 Sphinx for Python 项目文档的正确工作流程是什么?

python - 当我们只向 kmeans 提供单个单词的 tfidf 向量时,kmeans 如何知道如何对文档进行聚类?

python - 尝试下载 nltk 数据时出现 405 错误

带有 nltk.wordnet.synsets 的 Python IF 语句

python - 使用senti_classifier和NLTK进行情感分析

python - Pandas 忽略非数字值

python - 填写部分文本后如何点击自动完成?

python - 有效地调整图像的ndarray