user_az
user_az

Reputation: 363

R: How to unTag the Sentence, after tagged by tagPOS

I have tagged part of Speech to an string using tagPOS Now I want to unTag the string and get back as it was previous.

library(openNLP)
str <- "this is the a demo string. Which is used to show tagPOS capability.
And I want to untagged the tagged sentence.
Kindly help to do this."
tagged_str <-  tagPOS(str)
print(tagged_str)

Output:

"this/DT is/VBZ the/DT a/DT demo/NN string./NN Which/WDT is/VBZ used/VBN to/TO show/VB tagPOS/NNS capability./. And/CC I/PRP want/VBP to/TO untagged/VB the/DT tagged/JJ sentence./NN Kindly/RB help/VB to/TO do/VB this./."

Desired Output:

this is the a demo string. Which is used to show tagPOS capability. And I want to untagged the tagged sentence. Kindly help to do this."

Upvotes: 1

Views: 305

Answers (1)

Tyler Rinker
Tyler Rinker

Reputation: 109954

Here is one possible solution:

paste(sapply(strsplit(tagged_str, "/|\\s"), "[", c(TRUE, FALSE)), collapse = " ")

Edit:

Per your new request. A bit different approach:

paste(unlist(strsplit(tagged_str, "/[[:upper:]]*\\s|/\\.")), collapse = " ")

Upvotes: 1

Related Questions