我正在尝试将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__ ...
请问是否有人遇到过这种情况,或者有人知道如何解决此问题?我认为这与数据有关。因为此代码对第三方提供的另一个审阅文本数据集工作正常。
答案 0 :(得分:0)
我收到了相同的错误消息,在我的情况下,我的字符串向量中有一个空元素。
一旦我从向量中删除了所有空元素,它就可以正常工作。