trinker / termco

Regular Expression Counts of Terms and Substrings
Other
25 stars 5 forks source link

Get text from tags function #28

Closed trinker closed 7 years ago

trinker commented 7 years ago

something that does this or splits by tags etc.

_data[['textvar']]_[which(classify(_model_) == "Tag_O_Interest")]
trinker commented 7 years ago

Add this function to termco. Then have get_text.default in clustext refer to termco

p_load(termco)

discoure_markers <- list(
    response_cries = c("\\boh\\b", "\\bah\\b", "\\baha", "\\bouch", "yuk"),
    back_channels = c("uh[- ]huh", "uhuh", "yeah"),
    summons = "\\bhey",
    justification = "because"
)

model <- presidential_debates_2012 %>%
    with(term_count(dialogue, grouping.var = TRUE, discoure_markers))

attributes(model)

get_text <- function(x, ...){
    UseMethod("get_text")
}

get_text.term_count <- function(x, ...){
    attributes(model)[['text.var']][['text.var']][which(classify(model)%in% unlist(...))]
}

get_text(model, 'summons')
get_text(model, 'response_cries')
get_text(model, c('summons', 'response_cries'))