我正在尝试通过使用stri_replace_all_fixed函数来阻止 R 中的约 4000 个文档。但是,它非常慢,因为我的词干词典包含大约。30 万字。我这样做是因为文档是丹麦语的,因此 Porter Stemmer Algortihm 没有用(它太激进了)。
我已经发布了下面的代码。有谁知道这样做的替代方法?
逻辑:查看每个文档中的每个单词 -> 如果 word = voc-table 中的单词,则替换为 tran-word。
##Read in the dictionary
voc <- read.table("danish.csv", header = TRUE, sep=";")
#Using the library 'stringi' to make the stemming
library(stringi)
#Split the voc corpus and put the word and stem column into different corpus
word <- Corpus(VectorSource(voc))[1]
tran <- Corpus(VectorSource(voc))[2]
#Using stri_replace_all_fixed to stem words
## !! NOTE THAT THE FOLLOWING STEP MIGHT TAKE A FEW MINUTES DEPENDING ON THE SIZE !! ##
docs <- tm_map(docs, function(x) stri_replace_all_fixed(x, word, tran, vectorize_all = FALSE))
“voc”数据框的结构:
Word Stem
1 abandonnere abandonner
2 abandonnerede abandonner
3 abandonnerende abandonner
...
313273 åsyns åsyn