我如何使用 R 对英语单词(例如:'run' 和 'ran')进行词形还原,使它们都具有相同的时态?

How can I lemmatize english words (example: 'run' and 'ran') using R to bring them all to the same tense?

我想对英语单词进行词形还原,以便所有单词都转换为相同的时态。例如:

c("ran","run","running") 

应该变成c("run","run","run").

我已经探索过 tm、wordnet、RTextTools 和 Snowball C 等 R 包;但所有这些都会导致输出 c("ran","run","run")。如您所见,它们不会将 "ran" 转换为 "run"。

看看我维护的textstem package

if (!require("pacman")) install.packages("pacman")
pacman::p_load(textstem)

lemmatize_words(c("ran","run","running"))
###[1] "run" "run" "run"

请注意,如果您实际上有字符串而不是词向量,您可能需要 lemmatize_strings 函数。