我正在尝试使用dfm_lookup()在语料库中查找特定单词。
我真的在努力学习dfm_loopup()所需的词典。
我创建了一个名为“words”的字符向量,其中包含应该进入字典的所有单词。
字典需要一个列表,所以我在使用dictionary()之前从字符向量创建一个列表。
dict <- dictionary(list(words))
但后来我明白了
Error in validate_dictionary(object) :
Dictionary elements must be named: digital digital-tv digitalis ...
我需要在list命令中更改什么才能获得dictionary()的正确输出?
是否有更简单的版本来查找dfm中的特定单词?因为使用tm()包非常简单。
我相信你需要在列表中命名项目,以便使用quanteda
字典。这是一个例子:
library(quanteda)
words = c("cat","dog","bird")
word.list = as.list(words)
names(word.list) = words
dictionary(word.list)
Dictionary object with 3 key entries.
- [cat]:
- cat
- [dog]:
- dog
- [bird]:
- bird