R-openNLP没有字令牌发现注释

问题描述 投票:0回答:1

我试图标记POS用于从Yelp的数据集的挑战下载的评论文章的文本(第11轮)。下面列出的是我写的功能:

r <- unlist(lapply(rec_texts, function(x) { str_split(x, "\n") }))

R_tagPOS <-  function(x, ...) {
r <- as.String(x)
word_token_annotator <- Maxent_Word_Token_Annotator()
a2 <- Annotation(1L, "sentence", 1L, nchar(r))
a2 <- annotate(r, word_token_annotator, a2)
a3 <- annotate(r, Maxent_POS_Tag_Annotator(), a2)
a3w <- a3[a3$type == "word"]
POStags <- unlist(lapply(a3w$features, `[[`, "POS"))
POStagged <- paste(sprintf("%s/%s", s[a3w], POStags), collapse = " ")
list(POStagged = POStagged, POStags = POStags)
}

POS_R <- lapply(r, R_tagPOS)

但它返回这样的结果:

Error in e(s, a) : no word token annotations found 
8.stop("no word token annotations found") 
7. e(s, a) 
6.paste(y$id, y$type, y$start, y$end, sep = "\r") 
5.merge.Annotation(a, e(s, a)) 
4.merge(a, e(s, a)) 
3.annotate(r, Maxent_POS_Tag_Annotator(), a2) 
2.FUN(X[[i]], ...) 
1.lapply(r, R_tagPOS) 

该rec_texts来自Yelp的数据集挑战的评论文章。

Classes 'tbl_df', 'tbl' and 'data.frame':   2000 obs. of  1 variable:
$ text: chr  "Mix is such a beautiful restaurant and you have a gorgeous 
view of the strip while you're enjoying your dinner!"| 
__truncated__"WooooooHooooo 100th review!!!  I eat here all the time, 
but I've gotta take the chance to be the 100th review.\"| __truncated__ 
"My bf and I came for a small snack and some brews. We got the pretzel 
and cheese appetizer. The pretzel was ver"| __truncated__ "The food was 
amazing! This is a must for me now when I come visit Las Vegas! Everyone 
was very friendly. The ow"| __truncated__ ... 

请问有没有人遇到这种情况或任何人知道如何解决这个问题呢?林认为它有事情做与数据。由于此代码的工作蛮好的由第三方提供的另一种评论文本数据集。

r opennlp
1个回答
0
投票

我收到了同样的错误消息,在我的情况我在我的琴弦的向量有一个空元素。

一旦我删除从我的矢量的所有空元素的它工作得很好。

© www.soinside.com 2019 - 2024. All rights reserved.