0

我正在尝试使用 R 对从 Twitter 中提取的数据进行情感分析研究。我在编写时使用的是 udpipe 库

udpipe_dowload_model("model")
model< <- udpipe_load_model("directory)
out <- as.data.frame(udpipe_annotate(object, x, doc_id,...)

我跑了,引发了一个异常:

Error in udp_tokenise_tag_parse(object$model, x, doc_id, tokenizer, tagger,  : 
  external pointer is not valid 

相对回溯是:

4.
stop(structure(list(message = "external pointer is not valid", 
    call = udp_tokenise_tag_parse(object$model, x, doc_id, tokenizer, 
        tagger, parser, log_every, log_now), cppstack = structure(list(
        file = "", line = -1L, stack = c("1   udpipe.so                           0x0000000117ba907e _ZN4Rcpp9exceptionC2EPKcb + 222",  ... 
3.
udp_tokenise_tag_parse(object$model, x, doc_id, tokenizer, tagger, 
    parser, log_every, log_now) 
2.
udpipe_annotate(model, x = x, doc_id = doc_id, trace = F) at textAnalysisFunct.R#221
1.
lemmaUDP(x = twt$text_clean, model = modelI, doc_id = twt$doc_id, 
    stopw = tm::stopwords("italian"), userstopw = mystop) 

然后我开始调试,控制台上出现了:

Error during wrapup: external pointer is not valid

lemmaUDP 函数是我的老师创建的,如果有用我也将它的定义粘贴在这里,但与手动完成相同

lemmaUDP <- function(x = NULL, 
                     model = NULL, 
                     doc_id = NULL, 
                     stopw = tm::stopwords("italian"), 
                     userstopw=NULL){

  require(udpipe)
  if(is.null(x)){message("manca vettore testi");return()}
  if(is.null(model)){message("manca modello");return()}
  if(class(x) != "character"){message("il vettore x non è di tipo testo");return()}
  if(class(model) != "udpipe_model"){message("modello non valido");return()}
  if(is.null(doc_id)){doc_id <- 1:length(x)}
  if(!is.null(userstopw)){
    stopw <- c(stopw,userstopw)
  }
  xx <- udpipe_annotate(model, x = x, doc_id = doc_id,trace = F)
  xx <- as.data.frame(xx)
  xx$STOP <- ifelse(xx$lemma %in% stopw | xx$token %in% stopw,TRUE,FALSE)
  return(xx)
}
4

0 回答 0