首页 > 解决方案 > 获取西班牙语(和其他非英语语言)中单个单词的所有可能引理

问题描述

给定一个单词,我想获得该单词的所有可能引理。我正在使用 Spacy 3。以下代码将为给定单词输出最多一个引理。它没有找到替代品。

import spacy

# Load Spanish model
nlp = spacy.load("es_core_news_sm", disable=['parser', 'ner'])

text = "habla"
doc = nlp(text)

for token in doc:
    print("{:<12}{:<12}{:<12}{:<12}".format(token.text, token.pos_, token.tag_, token.lemma_))

# Outputs:
# text = "habla" (you/he/she speaks; speech)
# habla       VERB        VERB        hablar
# "hablar" = to speak (verb). However "habla" also means "speech" (noun)

# text = "como" (I eat; as)
# como        SCONJ       SCONJ       como
# not returning possible verb lemma - "comer" - to eat

# text = "come" (you/he/she eats)
# come        VERB        VERB        come
# lemma should be "comer" not "come"

# text = "sabe" (you/she/he knows)
# sabe        VERB        VERB        saber
# Correct lemmatization of "sabe" 

在所有情况下,即使有更多可能性,也只会返回一个可能的引理。

我尝试过的解决方案:

我发现的最佳替代解决方案是使用牛津词典 API——它只支持几种语言——例如,它不提供法语的引理。

标签: pythonnlpspacylemmatization

解决方案


推荐阅读