def crawl_lemmas(self, vocab):
"""Add Wordnet lemmas as definitions."""
lemmatizer = nltk.WordNetLemmatizer()
for word in vocab.words:
definitions = []
try:
for part_of_speech in ['a', 's', 'r', 'n', 'v']:
lemma = lemmatizer.lemmatize(word, part_of_speech)
if lemma != word and not [lemma] in definitions:
definitions.append([lemma])
except:
logger.error("lemmatizer crashed on {}".format(word))
if definitions:
self._data[word] = definitions
self.save()
评论列表
文章目录