Updated dfm_gen to only create derivative codes if majorTopic actually exists, and set docvars to NULL when no majorTopic codes

master
Erik de Vries 6 years ago
parent dc4daf9de4
commit 311838b34b

@ -35,7 +35,7 @@ dfm_gen <- function(out,words = '999', text = c("lemmas","full")) {
str_replace_all("<.*?>", " ") %>%
str_replace_all("\\s+"," ")
}
# out$codes <- out$`_source.codes.majorTopic` %>%
if ('_source.codes.majorTopic' %in% colnames(out)) {
out <- out %>%
mutate(codes = case_when(
.$`_source.codes.timeSpent` == -1 ~ NA_character_,
@ -56,7 +56,11 @@ dfm_gen <- function(out,words = '999', text = c("lemmas","full")) {
.[,2] %>%
as.numeric()
)
dfm <- corpus(out$merged, docnames = out$`_id`, docvars = out[,-seq(1,(length(names(out))-3),1)]) %>%
vardoc <- out[,-seq(1,(length(names(out))-3),1)]
} else {
vardoc <- NULL
}
dfm <- corpus(out$merged, docnames = out$`_id`, docvars = vardoc) %>%
dfm(tolower = T, stem = F, remove_punct = T, valuetype = "regex", ngrams = 1)
return(dfm)
}

Loading…
Cancel
Save