附加文档期限矩阵

问题描述

我想从一大堆PDF文件中创建一个DTM(最终目的=主题建模)。用

创建必要的语料库
pdf_raw <- VCorpus(DirSource(directory = "./",pattern = ".pdf"),readerControl = list(reader = readPDF(engine = c("pdftools")),language = "de",encoding = 'UTF-8'))

但是,会导致错误消息“空间不足”。我发现此错误与Windows有关,因为该命令可以在我的2012 MacBook上顺利运行...由于我必须依靠Windows设备,因此我正在寻找解决方法,并提出了为个人创建DTM的想法。 PDF(在清理它们以节省存储空间之后),然后将DTM彼此附加。我试图跑步:

combinedfiles <- list.files(path = "./",pattern= ".pdf")
for(i in 1:length(combinedfiles)){
print(i)

#individual corpus
pdf_raw <- VCorpus(DirSource(directory = "./",pattern = combinedfiles[i]),encoding = 'UTF-8'))

#preprocessing individual corpus to decrease size
pdf_raw <- tm_map(pdf_raw,removePunctuation,preserve_intra_word_dashes=FALSE)
pdf_raw <- tm_map(pdf_raw,removeNumbers)
pdf_raw <- tm_map(pdf_raw,content_transformer(tolower))
germanStopwords <- readLines("./stopwords_de.txt",enc= "UTF-8")
pdf_raw <- tm_map(pdf_raw,function(x) removeWords(x,germanStopwords)) 
pdf_raw <- tm_map(pdf_raw,stripWhitespace)
pdf_raw <- tm_map(pdf_raw,function(x) stemDocument(x,language="german"))

#Transfer to DTM
dtm <- DocumentTermMatrix(pdf_raw)
remove(pdf_raw)  }

很显然,这仅将i的最后一次出现存储在dtm中。我试图弄清楚如何用c附加dtm,但是找不到循环的解决方案。我还尝试过首先创建一个dtm作为列表,然后将DTM存储在dtm [[i]]中,但这会将格式从DTM更改为列表...任何建议,我们将不胜感激!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)