2011-07-07 32 views
6

我在想,如果有一个具有以下特点的r文本挖掘包的任何机会:[R文本挖掘包:允许把新的文件到现有的语料库

myCorpus <- Corpus(DirSource(<directory-contatining-textfiles>),control=...) 
# add docs 
myCorpus.addDocs(DirSource(<new-dir>),control=...) 

我非常希望把附加的文件进入现有的语料库。

任何帮助表示赞赏

回答

11

您应该能够只使用c(,)作为

> library(tm) 
> data("acq") 
> data("crude") 
> together <- c(acq,crude) 
> acq 
A corpus with 50 text documents 
> crude 
A corpus with 20 text documents 
> together 
A corpus with 70 text documents 

你可以找到更多的tm package documentationtm_combine下。

+0

感谢您的回复。我不知道更新的tm手册。它不在以前的tm手册(2010或以前的版本)中。 –

0

我在大数据文本挖掘集的背景下也解决了这个问题。无法一次加载整个数据集。

在这里,这种大数据集的另一种选择是可能的。该方法是在循环内收集一个文档语料库的向量。在处理完所有文件之后,可以将这个矢量转换成一个巨大的语料库,例如在它上面创建一个DTM。

# Vector to collect the corpora: 
webCorpusCollection <- c() 

# Loop over raw data: 
for(i in ...) { 

    try({  

    # Convert one document into a corpus: 
    webDocument <- Corpus(VectorSource(iconv(webDocuments[i,1], "latin1", "UTF-8"))) 

    # 
    # Do other things e.g. preprocessing... 
    # 

    # Store this document into the corpus vector: 
    webCorpusCollection <- rbind(webCorpusCollection, webDocument) 

    }) 
} 

# Collecting done. Create one huge corpus: 
webCorpus <- Corpus(VectorSource(unlist(webCorpusCollection[,"content"])))