【发布时间】:2017-02-13 09:04:51
【问题描述】:
我正在尝试使用 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
【问题讨论】: