从字符向量创建自定义字典

Create custom dictionary from character vector

我正在尝试使用 dfm_lookup() 在语料库中查找特定单词。

我真的很难找到 dfm_loopup() 所需的词典。

我创建了一个名为 "words" 的字符向量,其中包含所有应该进入字典的单词。

dictionary 需要一个列表,所以我在使用 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