使用nltk和wordnet将复数名词词典化

时间:2015-06-24 02:22:42

标签: python nltk wordnet lemmatization

我想使用

进行引理
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”,即使在词形变换器之后也是如此。

2 个答案:

答案 0 :(得分:5)

NLTK负责处理大多数复数,而不仅仅是删除结尾。'

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)

输出: 补鞋匠蚂蚁女人男孩需要找到二元爱好公共汽车狼

答案 1 :(得分:4)

我可以使用wordnet.morphy轻松地使事物变形:

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

请注意,procaspase不在WordNet中(但是caspase并且morphy会将caspase作为引理),并且您的lemmatizer可能只是不能识别它。如果您没有将其他词语解释为问题,那么它可能只是执行中的陌生问题。