我是R新手。我必須在我的代碼中使用POSTagger。我使用openNLP與R.在嘗試下面的示例代碼(在Sample.R文件):R:annotate()在R中給出錯誤
library("NLP")
library("openNLP")
s <- paste(c("Pierre Vinken, 61 years old, will join the board as a ",
"nonexecutive director Nov. 29.\n",
"Mr. Vinken is chairman of Elsevier N.V., ",
"the Dutch publishing group."),
collapse = "")
s <- as.String(s)
sent_token_annotator <- Maxent_Sent_Token_Annotator()
a1 <- annotate(s, sent_token_annotator)
s[a1]
,從R點控制檯(使用源(「Sample.R」)) 我正在下面這段代碼運行錯誤:
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class "c("Simple_POS_Tag_Annotator", "Annotator")" to a data.frame
以下是回溯()命令的輸出:
14: stop(gettextf("cannot coerce class \"%s\" to a data.frame", deparse(class(x))),
domain = NA)
13: as.data.frame.default(x[[i]], optional = TRUE)
12: as.data.frame(x[[i]], optional = TRUE)
11: data.frame(x = function (s, a = Annotation())
{
s <- as.String(s)
y <- f(s)
n <- length(y)
id <- .seq_id(next_id(a$id), n)
type <- rep.int("sentence", n)
if (is.Annotation(y)) {
y$id <- id
y$type <- type
}
else if (is.Span(y)) {
y <- as.Annotation(y, id = id, type = type)
}
else stop("Invalid result from underlying sentence tokenizer.")
if (length(i <- which(a$type == "paragraph"))) {
a <- a[i]
a$features <- lapply(annotations_in_spans(y, a), function(e) list(constituents = e$id))
y <- c(y, a)
}
y
}, check.names = FALSE, stringsAsFactors = FALSE)
10: eval(expr, envir, enclos)
9: eval(as.call(c(expression(data.frame), x, check.names = !optional,
stringsAsFactors = stringsAsFactors)))
8: as.data.frame.list(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors)
7: as.data.frame(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors)
6: data.frame(position)
5: annotate(s, sent_token_annotator) at sample.R#11
4: eval(expr, envir, enclos)
3: eval(ei, envir)
2: withVisible(eval(ei, envir))
1: source("sample.R")
什麼可以可能是錯誤的?我在Windows 7上使用Rx64 3.1.1。任何幫助將不勝感激。提前致謝。
這是因爲'qdap'在默認情況下加載了'ggplot2',它也有一個名爲'annotate'的函數。首先加載'qdap',一切都會好的。這在qdap的開發版本中已經改變了:https://github.com/trinker/qdap/issues/199你可能想要[安裝這個版本。](https://github.com/trinker/qdap#安裝) – 2015-02-05 17:12:04
這確實是功能覆蓋問題。我使用NLP :: annotate()解決了錯誤,而不是單獨使用註釋。它工作了,謝謝! – Shruti 2015-05-17 17:25:37