【问题标题】:Extracting verbs except for the POStag from text with POS tag in R从R中带有POS标签的文本中提取除POStag之外的动词
【发布时间】:2021-06-13 18:46:56
【问题描述】:

我是 R 新手。我尝试使用“openNLP”收集动词(“/VB”、“/VBD”、“/VBG”、“/VBN”、“/VBP”、“/VBZ”)包(请注意,“udpipe”在我的环境中不起作用)。我有一个句子和下面的标签混合在一起。

“做/VBG 工作/NN as/IN always/RB ./.playing/VBG football/NN is/VBZ good/JJ ./.I/PRP do/VBP that/IN”

如何实现没有词性标签的动词?我试图在这个例子中得到的答案是

“做”、“玩”、“是”、“做”

【问题讨论】:

标签: r


【解决方案1】:

您要求的示例:

    x <- "Doing/VBG work/NN as/IN always/RB ./. playing/VBG soccer/NN is/VBZ good/JJ ./. I/PRP do/VBP that/IN"
    x <- strsplit(x, split = " ")
    x <- unlist(x)
    x <- lapply(x, FUN = function(data){ 
        x <- strsplit(data, split = "\\/")
        x <- unlist(x)
        data.frame(token = x[1], xpos = x[2], stringsAsFactors = FALSE)
    })
    x <- do.call(rbind, x)
    subset(x, xpos %in% c("VB","VBD","VBG","VBN","VBP","VBZ"))

使用 udpipe

library(udpipe)
txt <- c(doc1 = "Doing work as always. playing soccer is good. I do that")
x <- udpipe(txt, object = "english", udpipe_model_repo = "bnosac/udpipe.models.ud", trace = 100)
subset(x, xpos %in% c("VB","VBD","VBG","VBN","VBP","VBZ"))

> subset(x, xpos %in% c("VB","VBD","VBG","VBN","VBP","VBZ"))
   doc_id paragraph_id sentence_id                sentence start end term_id token_id   token lemma upos xpos
1    doc1            1           1   Doing work as always.     1   5       1        1   Doing    do VERB  VBG
6    doc1            1           2 playing soccer is good.    23  29       6        1 playing  play VERB  VBG
8    doc1            1           2 playing soccer is good.    38  39       8        3      is    be  AUX  VBZ
12   doc1            1           3               I do that    49  50      12        2      do    do VERB  VBP
                                                   feats head_token_id dep_rel deps misc
1                                           VerbForm=Ger             0    root <NA> <NA>
6                                           VerbForm=Ger             4   csubj <NA> <NA>
8  Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin             4     cop <NA> <NA>
12                      Mood=Ind|Tense=Pres|VerbForm=Fin             0    root <NA> <NA>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-31
    • 2015-10-22
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多