【发布时间】:2018-05-14 08:04:03
【问题描述】:
在我的数据集中,我试图为每个观察分别创建包含名词、动词和形容词数量的变量。使用 openNLP 包,我已经做到了这一点:
s <- paste(c("Pierre Vinken, 61 years old, will join the board as a ",
"nonexecutive director Nov. 29.\n",
"Mr. Vinken is chairman of Elsevier N.V., ",
"the Dutch publishing group."),
collapse = "")
s <- as.String(s)
s
sent_token_annotator <- Maxent_Sent_Token_Annotator()
word_token_annotator <- Maxent_Word_Token_Annotator()
a2 <- annotate(s, list(sent_token_annotator, word_token_annotator))
pos_tag_annotator <- Maxent_POS_Tag_Annotator()
pos_tag_annotator
a3 <- annotate(s, pos_tag_annotator, a2)
a3
a3w <- subset(a3, type == "word")
a3w
这给了我输出:
id type start end features
1 sentence 1 84 constituents=<<integer,18>>
2 sentence 86 153 constituents=<<integer,13>>
3 word 1 6 POS=NNP
4 word 8 13 POS=NNP
5 word 14 14 POS=,
等等。
我的问题是,我如何提取例如每次观察的名词数量,以便我可以将其用于进一步分析。
谢谢!
【问题讨论】:
标签: r text-mining pos-tagger