小编use*_*599的帖子

如何使用OpenNLP在R中获取POS标签?

这是R代码:

library(NLP) 
library(openNLP)
tagPOS <-  function(x, ...) {
s <- as.String(x)
word_token_annotator <- Maxent_Word_Token_Annotator()
a2 <- Annotation(1L, "sentence", 1L, nchar(s))
a2 <- annotate(s, word_token_annotator, a2)
a3 <- annotate(s, 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)}
str <- "this is a the first sentence."
tagged_str <-  tagPOS(str)
Run Code Online (Sandbox Code Playgroud)

输出是:

tagged_str $ POStagged [1]"this/DT is/VBZ a/DT the/DT first/JJ sentence/NN ./."

现在我想从上面的句子中只提取NN单词即句子,并希望将其存储到变量中.任何人都可以帮我解决这个问题.

nlp r text-mining pos-tagger opennlp

5
推荐指数
2
解决办法
1万
查看次数

标签 统计

nlp ×1

opennlp ×1

pos-tagger ×1

r ×1

text-mining ×1