r - 使用 quanteda 进行词形还原
问题描述
怎么可能用 quantedamakes
来使单词词形还原。make
在 Python 中,可以使用NLTK WordNet Lemmatizer
解决方案
可以使用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_replace
或dfm_replace
函数。
推荐阅读
- java - 尝试将数据插入 Atlast 服务器上的集合时,命令失败并出现错误 8000 (AtlasError)
- python - 何时调用/引用函数以及何时执行?
- python - 无法导入 RocksDB 模块
- c - 在单个 scanf 中获取字符串和整数会在获取字符串后跳过其余整数,为什么?如何仅在单个 scanf 中执行此操作?
- javascript - 如何在时间流逝时增加抖动效果的强度
- c++ - 用于将 bmp 图像拼接在一起的应用程序。需要帮助
- python - python - 如何在python中的pandas数据框中执行词干提取和删除列?
- javascript - 移动李,这样我就可以做一个新的清单
- aws-sdk - listCollection 在使用 javascript sdk 时返回空,而它是通过 python 使用 boto3 创建的
- python - 如何合并列表的多个元素?