【问题标题】:lemmatize plural nouns using nltk and wordnet使用 nltk 和 wordnet 对复数名词进行词形还原
【发布时间】:2015-09-10 01:32:42
【问题描述】:

我想使用 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]))

问题是 POS 标记器知道“procaspases”是“NNS”,但是我如何将 NNS 转换为 wordnet,因为即使在词形分析器之后,“procaspases”仍然是“procaspaseS”。

【问题讨论】:

标签: python nltk wordnet lemmatization


【解决方案1】:

我可以使用 wordnet.morphy 轻松地对事物进行词形还原:

>>> from nltk.corpus import wordnet
>>> wordnet.morphy('cats')
u'cat'

请注意 procaspases 不在 WordNet 中(但是 caspase 是,而 morphy 会将 caspase 作为引理),很可能您的词法分析器根本无法识别它。如果您没有对其他词进行词形还原的问题,那么它可能只是实现之外的问题。

【讨论】:

【解决方案2】:

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)

输出: 鞋匠蚂蚁女人男孩需要找到二进制爱好巴士狼

【讨论】:

    猜你喜欢
    • 2014-05-24
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-15
    • 2018-11-03
    相关资源
    最近更新 更多