r - 如何在 R 中使用自定义元保存 TM VCorpus
问题描述
我正在 R 中保存一个 TM 语料库。
writeCorpus(as.character(thecrp), dirdst, filenames = NULL)
一切都很好,直到我得到一个错误:
Error in UseMethod("meta", x) : no method applicable for meta applicable to an object of class "character"
注意。我在语料库的每个文档中添加了三个自定义元字段。
这是一个可重现的示例:
# Create corpus from a folder of documents on disk
thetxts <- readtext(pthtxt, cache = FALSE)
thecrp <- corpus(thetxts)
# Add docvars (= columns)
# Reference
# NOTE: Add Meta to the corpus
meta(thecrp, tag = "doctyp", type = "corpus") <- "Reports, 2018"
# NOTE: Add Meta to each of the documents
for (i in 1:length(thecrp)){
# ID derived from the name of the file (withdraw .txt)
meta(thecrp[[i]], tag = "id", type = "indexed") <- gsub("\\.txt", "", meta(thecrp[[i]], tag = "id", type = "indexed"))
# constants
meta(thecrp[[i]], tag = "author", type = "indexed") <- "author"
meta(thecrp[[i]], tag = "type", type = "indexed") <- "individual"
meta(thecrp[[i]], tag = "prov", type = "indexed") <- "ocr"
}
# Then I perform usual and **mildly** transformative actions on the corpus
...
# Then I save it to disk: the **error occurs here**
dirdst <- "~/test"
writeCorpus(as.character(thecrp), dirdst, filenames = NULL)
解决方案
推荐阅读
- java - 为什么 invokevirtual 的目标类型从 javac 目标 1.1 更改为 1.2?
- c# - System.Web.Mvc.WebViewPage
.Model.get 返回 null - javascript - 谷歌地图仅在我按 cmd+shift+R 时显示
- android - 为什么 `android:layout_height="0dp" ` 会产生与 XML 中的 `android:layout_height="wrap_content" ` 相同的结果
- arduino - 带有 NULL 字符的 Arduino HttpClient getString 问题。ESP32
- java - 一定时间重复后启用按钮
- angular - 使用 express 导入意外令牌导入的电子错误 [使用 babel]
- javascript - Ajax 太慢 - 递归
- laravel - 在 PostTooLargeException laravel 5.6 之后尝试重定向到上一个视图(有错误)
- handlebars.js - 是否可以输出带有把手的 html 页面名称列表?