首页 > 解决方案 > 使用 quanteda 进行词形还原

问题描述

怎么可能用 quantedamakes来使单词词形还原。make

在 Python 中,可以使用NLTK WordNet Lemmatizer

标签: rquanteda

解决方案


可以使用tokens_wordstem或进行词干提取dfm_wordstem。但是需要用tokens_replace. 请注意 2 之间的差异,在将“am”进行词元化时,将“be”更改为“be”,因为这是引理。

在 lexicon 包中有一个名为 hash_lemmas 的表,您可以将其用作字典。quanteda 中没有默认的引理函数。

txt <- c("I am going to lemmatize makes into make, but not maker")

library(quanteda)

# stemming
tokens_wordstem(tokens(txt))
Tokens consisting of 1 document.
text1 :
 [1] "I"      "am"     "go"     "to"     "lemmat" "make"   "into"   "make"   ","      "but"    "not"    "maker" 

# lemmatizing using lemma table
tokens_replace(tokens(txt), pattern = lexicon::hash_lemmas$token, replacement = lexicon::hash_lemmas$lemma)
Tokens consisting of 1 document.
text1 :
 [1] "I"         "be"        "go"        "to"        "lemmatize" "make"      "into"      "make"      ","         "but"       "not"      
[12] "maker"    

其他引理选项将 spacyr 与 quanteda 结合使用。请参阅 spacyr 教程。

或者您可以先使用 udpipe 获取引理,然后使用 quantedatokens_replacedfm_replace函数。


推荐阅读