6

我想知道 R 的文本挖掘包是否有可能具有以下功能:

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

理想情况下,我想将其他文档合并到现有的语料库中。

任何帮助表示赞赏

4

2 回答 2

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 包文档中找到更多信息tm_combine

于 2011-07-07T20:50:50.463 回答
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"])))
于 2017-05-27T12:31:12.800 回答