trinker / qdap

Quantitative Discourse Analysis Package: Bridging the gap between qualitative data and quantitative analysis
http://cran.us.r-project.org/web/packages/qdap/index.html
175 stars 44 forks source link

Add combine trailing sentences #218

Open trinker opened 9 years ago

trinker commented 9 years ago

http://stackoverflow.com/a/33719705/1000343

foo <- data.frame(
    num = 1:6,
    txt = c("Do you have any idea what", "they were arguing about?",
            "Do--Do you speak", "English?", "yeah...", "No, I'm sorry."
    ), 
    stringsAsFactors = FALSE)

##   num                       txt
## 1   1 Do you have any idea what
## 2   2  they were arguing about?
## 3   3          Do--Do you speak
## 4   4                  English?
## 5   5                   yeah...
## 6   6            No, I'm sorry.

x <- paste0(foo$txt, collapse = " ")
trimws(unlist(strsplit(x, "(?<=[?.!|])(?=\\s)", perl=TRUE)))

## [1] "Do you have any idea what they were arguing about?"
## [2] "Do--Do you speak English?"                         
## [3] "yeah..."                                           
## [4] "No, I'm sorry."