Friday 15 May 2015

opennlp - R: annotate() gives error in R -



opennlp - R: annotate() gives error in R -

i new r. have utilize postagger in code. using opennlp r. while trying next sample code (in sample.r file):

library("nlp") library("opennlp") s <- paste(c("pierre vinken, 61 years old, bring together board ", "nonexecutive director nov. 29.\n", "mr. vinken 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]

and running code r console (using source("sample.r")) getting next error:

error in as.data.frame.default(x[[i]], optional = true) : cannot coerce class "c("simple_pos_tag_annotator", "annotator")" data.frame

following output of traceback() command :

14: stop(gettextf("cannot coerce class \"%s\" 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, = 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 underlying sentence tokenizer.") if (length(i <- which(a$type == "paragraph"))) { <- 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) @ sample.r#11 4: eval(expr, envir, enclos) 3: eval(ei, envir) 2: withvisible(eval(ei, envir)) 1: source("sample.r")

what can perchance wrong? using rx64 3.1.1 on windows 7. help much appreciated. in advance.

i don't have exact reply suffered same error using nlp, opennlp, tm, qdap. worked backward restarting r , loading (library) 1 package, running code, loading bundle , running code, until ran across "cannot coerce dataframe" error. found, in case qdap interferes opennlp annotate() function phone call -- using nlp wrapper.

opennlp version 0.2-3 imports nlp (≥ 0.1-2), opennlpdata (≥ 1.5.3-1), , rjava (≥ 0.6-3). because loaded nlp explicitly, may case of 2 instances of nlp running in memory interfering each other. seek loading opennlp , running code

r opennlp

No comments:

Post a Comment