r - tm 合并语料库列表

标签 r list tm

我有一个 URL 列表,我已为其获取 web 内容,并将其包含到 tm 语料库中:

library(tm)
library(XML)

link <- c(
"http://www.r-statistics.com/tag/hadley-wickham/",                                                      
"http://had.co.nz/",                                                                                    
"http://vita.had.co.nz/articles.html",                                                                  
"http://blog.revolutionanalytics.com/2010/09/the-r-files-hadley-wickham.html",                          
"http://www.analyticstory.com/hadley-wickham/"  
)               

create.corpus <- function(url.name){
doc=htmlParse(url.name)
parag=xpathSApply(doc,'//p',xmlValue)
if (length(parag)==0){
  parag="empty"
}
cc=Corpus(VectorSource(parag))
meta(cc,"link")=url.name
return(cc)
}

link=catch$url
cc <- lapply(link, create.corpus)

这给了我一个语料库的“大列表”,每个 URL 一个。
将它们一一组合起来工作:
x=cc[[1]]
y=cc[[2]]
z=c(x,y,recursive=T) # preserved metadata
x;y;z
# A corpus with 8 text documents
# A corpus with 2 text documents
# A corpus with 10 text documents

但是对于包含几千个语料库的列表来说,这变得不可行。
那么如何在维护元数据的同时将一个语料库列表合并为一个语料库呢?

最佳答案

您可以使用 do.call调用 c :

do.call(function(...) c(..., recursive = TRUE), cc)
# A corpus with 155 text documents

关于r - tm 合并语料库列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20971094/

相关文章:

r - 在 r 中使用 tm 包查找关键短语

R:TM 包从单列中查找词频

r - 与方差分析一起替代r

r - 在 for 循环中运行 sapply 的更快方法

r - RStudio(或R)中是否有像SPSS一样的变量列表?

python - 继承QAbstrctitemModel、PyQt时使用Lists作为QModelIndex中的internalPointer

python - 从不可变类型继承

r - 如何仅在R中调整y轴标签的大小?

android - 如何应用随机数字列表从数组中选择图像?

R tm包在strptime(d,fmt): input string too long中读取PDF错误