0
sample_text <- ' Ramesh is my frien. He is a very good man' 

Now I need to extract all the Pronouns (PRP or PRP$) from my text

acqTag <- tagPOS(sample_text)

I get the following

$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"  

Now How do I get ony pronouns from here ? PRP or PRP$

Shiva Prakash
  • 1,849
  • 4
  • 21
  • 25
  • 1
    something like `stringr::str_extract_all(acqTag$POStagged,"[[:alpha:]]/PRP")`. What package is `tagPOS` from ... ? – Ben Bolker Jul 18 '16 at 12:57
  • @BenBolker I was thinking the same thing. I think this is it http://stackoverflow.com/questions/28764056/could-not-find-function-tagpos – Pierre L Jul 18 '16 at 13:12
  • @BenBolker Sorry the above syntax you had mentioned does not give me the desired output. Seems it needs to be checked again! Thanks! – Shiva Prakash Jul 18 '16 at 13:42
  • note I said "something like". I posted as a comment because I thought it might be useful, but didn't have time to test ... – Ben Bolker Jul 18 '16 at 14:19
  • Sure! I was just mentioning that it is not working. In any case thanks! – Shiva Prakash Jul 18 '16 at 14:21

1 Answers1

1

What, exactly, do you want as the output? This seems to give what I think you want:

library("stringr")

prp <- str_extract_all(acqTag$POStagged,"\\w+/PRP\\$?")
str_replace(unlist(prp), "/PRP\\$?", "")
#[1] "my" "He"
Anders Ellern Bilgrau
  • 9,928
  • 1
  • 30
  • 37