您要求的示例:
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>