- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个要处理的文档列表,对于每个记录,我想将一些元数据附加到 R 包 tm 生成的“语料库”数据结构内的文档“成员”(通过读取文本文件)。
这个 for 循环有效,但速度很慢 ,
性能似乎随着函数 f ~ 1/n_docs 而下降。
for (i in seq(from= 1, to=length(corpus), by=1)){
if(opts$options$verbose == TRUE || i %% 50 == 0){
print(paste(i, " ", substr(corpus[[i]], 1, 140), sep = " "))
}
DublinCore(corpus[[i]], "title") = csv[[i,10]]
DublinCore(corpus[[i]], "Publisher" ) = csv[[i,16]] #institutions
}
i = 0
corpus = tm_map(corpus, function(x){
i <<- i + 1
if(opts$options$verbose == TRUE){
print(paste(i, " ", substr(x, 1, 140), sep = " "))
}
meta(x, tag = "Heading") = csv[[i,10]]
meta(x, tag = "publisher" ) = csv[[i,16]]
})
Examples:
data("crude")
meta(crude[[1]])
DublinCore(crude[[1]])
meta(crude[[1]], tag = "Topics")
meta(crude[[1]], tag = "Comment") <- "A short comment."
meta(crude[[1]], tag = "Topics") <- NULL
DublinCore(crude[[1]], tag = "creator") <- "Ano Nymous"
DublinCore(crude[[1]], tag = "Format") <- "XML"
DublinCore(crude[[1]])
meta(crude[[1]])
meta(crude)
meta(crude, type = "corpus")
meta(crude, "labels") <- 21:40
meta(crude)
最佳答案
这是一些基准测试......
与 for
循环:
expr.for <- function() {
for (i in seq(from= 1, to=length(corpus), by=1)){
DublinCore(corpus[[i]], "title") = LETTERS[round(runif(26))]
DublinCore(corpus[[i]], "Publisher" ) = LETTERS[round(runif(26))]
}
}
microbenchmark(expr.for())
# Unit: milliseconds
# expr min lq median uq max
# 1 expr.for() 21.50504 22.40111 23.56246 23.90446 70.12398
tm_map
:
corpus <- crude
expr.map <- function() {
tm_map(corpus, function(x) {
meta(x, "title") = LETTERS[round(runif(26))]
meta(x, "Publisher" ) = LETTERS[round(runif(26))]
x
})
}
microbenchmark(expr.map())
# Unit: milliseconds
# expr min lq median uq max
# 1 expr.map() 5.575842 5.700616 5.796284 5.886589 8.753482
tm_map
正如您所注意到的,版本似乎快了大约 4 倍。
tm_map
中的更改版本不持久,那是因为你不回
x
在匿名函数的末尾。最后应该是:
meta(x, tag = "Heading") = csv[[i,10]]
meta(x, tag = "publisher" ) = csv[[i,16]]
x
关于performance - R: tm Textmining 包:Doc-Level 元数据生成很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14960863/
我编写了一个 c# 程序,并在未安装 MS-Office 的 PC 中将其与文件扩展名(如 DOC)相关联。然后,我双击名称中包含空白字符的任何文件,我的程序将启动以打开该文件。我使用了以下语句: s
我试过创建、批量更新、从 https://developers.google.com/docs/api/how-tos/overview 获取. 即使在 batchUpdate 中,我也看不到编辑 t
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在尝试使用新 API 更新 Google 文档中的表格。表格链接自 Google 表格。 我尝试了谷歌云中的 API 资源管理器。我能够以 json 格式提取文档,然后过滤出表格。但是在表 jso
将 Google Docs Java API 与 Google Apps 帐户一起使用,是否可以模拟用户并下载文件? 当我运行下面的程序时,它显然是登录到域并冒充用户,因为它检索其中一个文件的详细信息
我试图通过 apidoc 生成 API 文档 如果我的回应是一个数组 [ {"id" : 1, "name" : "John"}, {"id" : 2, "name" : "Mary"}
是否可以在没有身份验证的情况下在 Google Docs 中查询公开共享的用户文档? 我正在寻找的特定最终目标是能够提供用户 ID,然后列出所有公开共享的文档,并在集合中带有特定标记。 谢谢。 最佳答
我对Elasticsearch映射感到困惑 首先,我创建了一个带有映射请求的文档 PUT /person { "mappings":{ "properties":{ "firs
我有一个可在一个电子表格中运行的 Google 文档查询。但是,当我复制电子表格时,查询不起作用,并且收到解析错误:无法解析函数 QUERY 参数 2 的查询字符串:NO_COLUMNCol2。 我的
我有一个如下所示的 XML 文档: _1 _2 TASK _3 TASK 我必须使用第一个文档中的节点属性创建另一
我没有看到什么? RTD features页面说: PDF Generation When you build your project on RTD, we automatically build
我有一个网页,我在 iFrame 中嵌入了一个 Google 文档查看器 (其中 URL-encoded-URL 是实际编码的 URL)。 对于我的许多/大多数用户,Google PDF 文档查看器
我如何在我的项目中使用 GOOGLE DOCS,我正在使用 asp.net 和 C# 作为后面的代码。 基本上我需要在浏览器中以只读形式显示一些 pdf、doc、dox、excel 文档。 提前致谢
从看起来像的 Google Doc 开始: * Item 我希望进行一系列 API 调用以将文档转换为: * Item - Subitem 但是,我不知道如何使用 API 做到这一点。 Crea
我需要控制我网站中嵌入的 Google 文档查看器。更具体地说,我需要能够启用/禁用 Google 幻灯片 View 的控件,并能够使用 JavaScript 启动/停止演示文稿。 我无法为此找到任何
我想使用 Google Docs API 将页眉和页脚添加到现有的 Google 文档文件中. 看着documents.batchUpdate ( link ) 我们可以插入文本、替换文本、添加图像和
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 已关闭 4 年前。 Improve
我已按照 GitHub 的文档进行操作,并使用 docs 成功发布了我的项目页面。我的项目存储库下的文件夹。但我想知道如何解决这个小问题: 我正在开发一个 JavaScript 库 wesa.js ,
我的程序正在创建文档,每个文档都有需要放入其中的文本。任何调用 InsertTextRequest 的尝试调用错误。 List requests = new ArrayList<>(); reques
基于此: Set field to automatically insert time-stamp on UPDATE? 我正在尝试创建适合我需要的触发器,但我发现使用 OLD 和 NEW 关键字不方
我是一名优秀的程序员,十分优秀!