从 R 中的文本中提取代词
Extract Pronouns from text in R
sample_text <- ' Ramesh is my frien. He is a very good man'
现在我需要从我的文本中提取所有代词(PRP
或 PRP$
)
acqTag <- tagPOS(sample_text)
我得到以下
$POStagged
[1] "Ramesh/NNP is/VBZ my/PRP$ frien/NN ./. He/PRP is/VBZ a/DT very/RB good/JJ man/NN"
$POStags
[1] "NNP" "VBZ" "PRP$" "NN" "." "PRP" "VBZ" "DT" "RB" "JJ" "NN"
现在如何从这里获得代词? PRP or PRP$
您究竟想要什么作为输出?这似乎给出了我认为你想要的:
library("stringr")
prp <- str_extract_all(acqTag$POStagged,"\w+/PRP\$?")
str_replace(unlist(prp), "/PRP\$?", "")
#[1] "my" "He"
sample_text <- ' Ramesh is my frien. He is a very good man'
现在我需要从我的文本中提取所有代词(PRP
或 PRP$
)
acqTag <- tagPOS(sample_text)
我得到以下
$POStagged
[1] "Ramesh/NNP is/VBZ my/PRP$ frien/NN ./. He/PRP is/VBZ a/DT very/RB good/JJ man/NN"
$POStags
[1] "NNP" "VBZ" "PRP$" "NN" "." "PRP" "VBZ" "DT" "RB" "JJ" "NN"
现在如何从这里获得代词? PRP or PRP$
您究竟想要什么作为输出?这似乎给出了我认为你想要的:
library("stringr")
prp <- str_extract_all(acqTag$POStagged,"\w+/PRP\$?")
str_replace(unlist(prp), "/PRP\$?", "")
#[1] "my" "He"