如何使用spacy lemmatizer将单词变成基本形式 [英] how to use spacy lemmatizer to get a word into basic form

查看:669
本文介绍了如何使用spacy lemmatizer将单词变成基本形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对spacy并不陌生,我想使用它的lemmatizer函数,但是我不知道如何使用它,就像我将它变成单词的字符串一样,它将以基本形式返回单词.

I am new to spacy and I want to use its lemmatizer function, but I don't know how to use it, like I into strings of word, which will return the string with the basic form the words.

示例:

  • 'words'=>'word'
  • 'did'=>'do'

谢谢.

推荐答案

先前的答案很复杂,无法编辑,因此这是一个更常规的答案.

Previous answer is convoluted and can't be edited, so here's a more conventional one.

# make sure your downloaded the english model with "python -m spacy download en"

import spacy
nlp = spacy.load('en')

doc = nlp(u"Apples and oranges are similar. Boots and hippos aren't.")

for token in doc:
    print(token, token.lemma, token.lemma_)

输出:

Apples 6617 apples
and 512 and
oranges 7024 orange
are 536 be
similar 1447 similar
. 453 .
Boots 4622 boot
and 512 and
hippos 98365 hippo
are 536 be
n't 538 not
. 453 .

来自官方照明之旅

这篇关于如何使用spacy lemmatizer将单词变成基本形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆