python - 获取西班牙语(和其他非英语语言)中单个单词的所有可能引理
问题描述
给定一个单词,我想获得该单词的所有可能引理。我正在使用 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"
在所有情况下,即使有更多可能性,也只会返回一个可能的引理。
我尝试过的解决方案:
- lemminflect - 可能只适用于英语
- 这个答案,您在其中设置了一个词性标签(因此可以遍历所有可能的标签),但这似乎是针对旧版本的 spacy
我发现的最佳替代解决方案是使用牛津词典 API——它只支持几种语言——例如,它不提供法语的引理。
解决方案
推荐阅读
- javascript - sweetalert 删除 确认 laravel
- ios - 如何实现嵌套集合视图?
- swift - 如何在 ARKit 中使用环境贴图?
- mips - MIPS:将字符串输入存储到内存中
- php - 从 Woocommerce 3.4+ 的结帐字段中删除“(可选)”文本
- python - 如何在玩家之间随机洗牌?
- docker - 当我们拥有 WebDeploy 时,为什么要为 .NET Web 应用程序使用 Docker?
- scala - scala - 通过键的功能加入 Spark RDD
- json - 从 json 数组文件格式创建配置单元表
- vba - 改进 Word 中的 VBA 宏以自动创建与文档名称和位置相关的文件